EEET2097 Electronic Circuits

EEET2097 Electronic Circuits

Workshop 2 (Weeks 5-6)

CURRENT SOURCES AND CURRENT MIRRORS

General Information

Special Note: there are two options in this lab manual:

• In the Option 1, measurement video and results are provided.

• In the Option 2, instructions for physical circuit measurement are provided.

Please select one out of the two options. Please note the Option 2 is the recommended option, as you will have the opportunity to gain more hands-on skills.

If you select the Option 1:

• Please complete lab tasks either during the lab session or during your preferred time at home (i.e., attending the lab session is not mandatory). Lab tasks are individual.

• You may also attend any lab session (listed in the Canvas Workshop 2 page) each week for questions and help.

• Please read through the General Information part and then follow the instructions on Page 3 to Page 8 of this lab manual

If you select the Option 2:

• Please complete the lab tasks during your timetabled on-campus lab session. You will conduct physical experiments and measurements in groups (i.e., group tasks)

• Please attend your timetabled session to make sure you have access to the hardware.

• You may also attend other lab sessions (listed in the Canvas Workshop 2 page) for questions and help.

• Please read through the General Information part and then follow the instructions on Page 9 to Page 13 of this lab manual.

Individual lab report is required for both options. Please provide your answers to the questions

(start with “Q”) based on your selection (using provided measurements or your own measurements).

1. AIMS

(i)     Investigate the operation of BJT current sources

(ii)    Understand the output resistance of BJT current sources

(iii)   Investigate the use of BJT current mirrors as the active load

2. INTRODUCTION

Current sources and current mirrors are very important parts of analogue IC designs. The  active current sources and mirrors provide biasing currents for amplifier stages and save valuable real estate on the chip compared with discrete element designs. The current mirror can also be used as the active load in electronic circuits.

A BJT based current mirror circuit is shown in Figure 1.

The output current Io  is related to the reference current IREF  by:

where β is the current amplification factor of the BJT. Assume VA2  is the Early voltage of transistor Q2, the output resistance (taken from Q2) can be described as:

Figure 1 BJT current mirror.

3. ASSESSMENT

By lab report (individual report).

Due at 11:59pm, 13 September 2024 (i.e., the Friday of Week 7).

Provide your answers to the questions asked in this lab manual (starting with “Q”).

Include key calculation steps, equivalent circuit schematics, simulation circuit schematics, simulation results, plots, measurement results (if applicable), comparisons and discussions in the report.

•    If you select Option  1:  please include screenshots of your simulation circuit schematics and key simulation results.

•    If you select Option 2:  please  include  photos of the circuit you built and key measurement results.

Please refer to the Marking Rubric for detailed report format and requirements.

4. SESSION TASK ALLOCATION SUGGESTION

If you select Option 1, you may consider allocating the lab tasks to 2 sessions as follows:

•    Watch the general guidance video and complete 5.1 in the first session.

•    Complete 5.2 and 5.3 in the second session.

If you select Option 2, you may consider allocating the lab tasks to 2 sessions as follows:

•    Watch the general guidance video and complete 6.1 in the first session.

•    Complete 6.2 and 6.3 in the second session.

Option 1

Please note this is the first option, where you will be provided with measurement videos and data. All tasks in Option 1 are individual tasks.

5.  WORKSHOP PROCEDURE (OPTION 1)

In this workshop, we will use the pre-designed differential amplifier card. Current mirror and current source are part of the card. The circuit schematic is shown in Figure 2. The solid lines in the figure represent existing circuit connections, and the dashed lines represent possible circuit connections that are not connected yet.

Figure 2 Laboratory differential amplifier circuit schematic.

The  differential  amplifier  card  needs  to  be  installed  in  a  card  frame. to  use  (please  refer  to  the measurement video). The numbers with a circle around them in Figure 2 correspond to the numbered sockets at the base of the card frame. We will refer to these numbers as “socket X” .

5.1 DC Biasing

In this part, we will focus on the DC biasing of the current source. Note the inclusion of:

•    The link A1;

• The 1  resistor E2.

As shown in the measurement video (video Part 1-1), we connect socket 10 in Fig. 2 to ground (thereby setting VB1 = 0V) and connect a DC current meter between sockets 6 and 7. We also connect DC supply voltages V+ (+10 Volts) and V- (–10 Volts) as marked (i.e., sockets 16 and 1, respectively). Note that we use the dual DC supply on the workbench to generate ±10V supply voltages.

We then adjust the 500 KΩ potentiometer in the circuit to set the emitter current IE of the transistor Q1 to I= 1 mA.

5.1.1 Q: What is the resulting equivalent circuit with the connections mentioned above (please

draw the circuit diagram)? What are the functions of the two BJTs currently utilized (Q1 and Q5)?

5.1.2 Q: Theoretically,  how does the 500 KΩ potentiometer in the circuit control the emitter

current of transistor Q1 and why?

After adjusting the emitter current Iof Q1, as shown in the measurement video (video Part 1-2) We measure the DC emitter and collector voltages of transistor Q1. The results are shown in Table 1. We also measure the DC voltages of transistor Q5. The results are also shown in Table 1.

Table 1

BJT Transistor

Base Voltage

Collector Voltage

Emitter Voltage

Q1

0 V

5.34 V

-0.747 V

Q5

-9.23 V

-0.747 V

-10 V

5.1.3 Q: Is the BJT Q1 in the active operation mode? Also explain why the Q1 emitter voltage is

approximately -0.7V.

5.1.4 Q: Is the BJT Q5 in the active operation mode? Brief explain its working principle. NI Multisim Simulation:

Build the equivalent circuit obtained in 5.1.1 in NI Multisim. For the BJTs in the 3086 array (e.g., Q1 and Q5), they are general purpose NPN transistors, and you can use BJT model 2N3904 instead in the simulation (you will notice that there are multiple manufacturers and packages of 2N3904 available, and you can use any of them). Similar with the measurement, adjust the 500 kΩ potentiometer to set the emitter current Iof Q1 to I= 1 mA in the simulation. If yourIcurrent is below 1 mA, replace the 1 MΩ resistor (E2 in Figure 2) with any resistor between 560 kΩ and 1.5 MΩ to set it to 1 mA.

5.1.5 Q: What is your simulation circuit schematic? Also show that yourIcurrent is 1 mA. Simulate the emitter, base and collector voltages of transistors Q1 and Q5.

5.1.6 Q: What are the simulated voltages? Show the screenshots of simulation results.

5.1.7 Q: Compare the simulation results with the measurement results shown in Table 1. Are

they similar and why?

Note: Since we are analysing the bias of the circuit, the DC Operating Point analysis mode can be used  in this  part  of  circuit  simulation.  For  the  potentiometer,  in  simulation  you  can  use  the component “POTENTIOMETER_RATED”, and for the Zener diode, you can use “ZENER” .

5.2 Current Source Output Resistance

As shown in the measurement video (video Part 2), we connect a number of 1kΩ resistors between socket 6 and the input to the current meter (the current mirror is connected between sockets 6 and 7, as described in 5.1). We change the resistor connections for 5 different settings (i.e., 5 different resistances), and measure the corresponding collector-emitter voltage of the transistor Q5 (i.e., the voltage difference between socket 7 and socket 1) and the collector current (i.e., output current of Q5). The results are shown in Table 2.

Table 2

Resistance

200 Ω

250 Ω

333 Ω

500 Ω

1 kΩ

VCE

9.118 V

9.064 V

8.968 V

8.791 V

8.352 V

IC

0.996 mA

0.995 mA

0.993 mA

0.990 mA

0.984 mA

5.2.1 Q: Theoretically, how does the resistor connected between socket 6 and the input to the

current meter allow us to change the output voltage from the current source transistor Q5?

5.2.2 Q: Plot the transistor Q5 output current versus the collector-emitter voltage curve based

on the measurement results shown in Table 2 (you may consider use Excel or Matlab) . Include the plot in your lab report. What is the output resistance of the current source transistor?

Hint: The slope of the I-V curve is the output conductance of the current source.

5.2.3 Q: If we analyse the circuit theoretically, what is the value of the output resistance of the

current source? (the Early Voltage of transistor Q5 according to the datasheet is 60 V).

5.2.4 Q: Compare and discuss your calculation result with your measurement result: are they

similar and why?

NI Multisim Simulation:

Similar with the measurement above, adjust the simulation circuit used in 5.1 by connecting a resistor between the emitter of Q1 and the collector of Q5. Change the Early voltage of the transistor 2N3904 used  in the simulation to 60 V.  Keep other  parts of the simulation  circuit  unchanged. Adjust the resistance of to the values shown in Table 2.

5.2.5 Q: Under  different  settings  of R, what  are  the  simulated  collector-emitter  voltage  of

transistor Q5 (VCE) and and the collector current (i.e., output current IC of Q5)?

5.2.6 Q: Plot the transistor Q5 output current versus the collector-emitter voltage curve based

on the simulation results. Include the plot in your lab report. What is the simulated output resistance of the current source transistor?

5.2.7 Q: Compare   and  discuss  your  simulation   result  with  your  calculation  (5.2.3)  and

measurement (5.2.2) results.

Note: Since we are still dealing with DC analysis, the DC Operating Point analysis mode can be used in this part of circuit simulation.

5.3 Current Mirror Operation

The differential amplifier card contains a current mirror comprising two PNP transistors (type 2N3638) that can be connected as a load to replace the 4.7kΩ collector resistors. In this part, we will connect two common-emitter amplifiers in parallel as a differential pair (Q1 and Q2 in Figure 3) and use the current mirror as the collector load for each amplifier.

To configure the circuit, we remove link A1, and insert link F and link G, as highlighted in Figure 3. E2 remains the same with 1 MΩ resistor connected. These links connect the PNP current mirror (i.e., Q3 and Q4) to the collectors of the two NPN transistors Q1 and Q2 which form. the differential pair. We then connect socket 10 and socket 13 to ground to set the two base voltages to 0, and connect the DC current  meter  between sockets 6 and 7. Afterwards, we adjust the 500  kΩ  potentiometer  in the current source transistor Q5 to get a current flow of 1 mA.

If we now use the current meter to measure the collector currents of the current mirror, as shown in the measurement results (Fig. 4), we can obtain about 0.5 mA current for each of the transistors (i.e., Q3 and Q4) in the current mirror.

Figure 3 Current mirror configuration.

5.3.1 Q: What   is  the   resulting  equivalent  circuit?  Why  the  current  through  each  of  the

transistors in the current mirror is about 0.5 mA?

Figure 4 (a) collector current of transistor Q3; and (b) collector current of transistor Q4.

Now we connect an AC small signal to the input of transistor Q1 of the differential pair (i.e., socket 10). We set the signal frequency to 1 kHz, the amplitude (peak-to-peak) to 10 mV, and the signal waveform. to sinusoidal, as shown in Fig. 5(a). The measured signal waveform. at socket 4 (i.e., the output port of the circuit even when the input signal is connected to the left half circuit, which will be discussed in detail in Topic 5) is shown in Figure 5(b). The measured AC current through the link F is 0.0933 mA (AC peak current).

Figure 5 (a) input signal to the differential amplifier (socket 10); and (b) output signal of the differential amplifier (socket 4).

5.3.2 Q: The measured voltage at socket 4 is equal to the AC collector-emitter in the current

mirror. Explain why this is so.

5.3.3 Q: Based on the results, calculate the small signal output resistance of the left half circuit

(including the current mirror transistor Q3 and the amplifier transistor Q1).

HintThe small signal output resistance can be calculated as Rout   = vac,4 /iac.    5.3.4 Q: Calculate the expected output resistance of the left half circuit theoretically.

For the transistor Q1 (or Q2) in the amplifier part, the Early Voltage, which is typically referred as the “Collector-Emitter Breakdown Voltage” in a datasheet, is 60 V. For the transistor Q3 (or Q4) in the current mirror, the Early Voltage is 25 V.

Hint: The output resistance of the left half circuit here includes two parts connected in parallel: the ro  of Q1 and the ro  of Q3.

5.3.5 Q: Compare  and  discuss  your calculation  result  (5.3.3) with the  measurement  result

(5.3.4).

We now connect the AC small signal to the input of transistor Q2 in the differential pair (i.e., socket 13). The measured signal waveform. at socket 4 is shown in Figure 6. The measured AC current (rms current) through the link G is 0.0938 mA (AC peak current).

Figure 6 Output signal of the differential amplifier (socket 4).

5.3.6 Q: Based on the results, calculate the small signal output resistance of the right half circuit

(including the current mirror transistor Q4 and the amplifier transistor Q2).

5.3.7 Q: Calculate the expected output resistance of the right half circuit theoretically.

Hint: Transistor Q2 is identical to Q1, and transistor Q4 is identical to Q3.

5.3.8 Q: Compare  and  discuss  your  calculation  result  (5.3.6)  with  the  measurement  result

(5.3.7).

5.3.9 Q: Compare the output resistances of the right circuit (i.e., Q2 + Q4) and the left circuit

(i.e., Q1 + Q3). Explain the difference on the output resistance.

Option 2

Please note this is the second option (no simulation required), you will be provided with measurement guides. The measurement tasks in Option 2 can be completed in groups (however, individual  lab reports are still required). Option 2 is the recommended option to gain more hands-on skills.

6.  WORKSHOP PROCEDURE (OPTION 2)

Obtain a differential amplifier card from the cupboard and install it in a card frame. Current mirror and current source are part of the card. Connect the circuit as shown in Figure 7. Note the inclusion of:

• The link A1.

• The 1  resistor E2.

The differential amplifier needs to be installed to a card frame. to use. The  numbers with a circle around them in Figure 7 correspond to the numbered sockets at the base of the card frame. We will refer to these numbers as “socket X” . Please note that Figure 7 is identical to Figure 2 in Option 1.

Figure 7 Laboratory differential amplifier circuit schematic.

6.1 DC Biasing

Step 1: Connect socket 10 in Fig. 7 to ground (thereby setting VB1 = 0V) and connect a DC current meter between sockets 6 and 7 (make sure the multimeter is set to current mode and that socket 6   is connected to the current input terminal on the meter). Connect DC supply voltages V+ (+10 Volts)  and V- (–10 Volts) as marked (i.e., sockets 16 and 1, respectively). You can use the dual DC supply on your workbench in tracking mode to generate ±10V supply voltages (please refer to Appendix I).

NOTE: If you are not sure if the circuit connection or the dual power supply connection is correct, please ask your lab tutor to have a quick check before powering the circuit.

6.1.1 Q: What is the resulting equivalent circuit (please draw the circuit diagram)? What are the

functions of the two BJTs currently utilized (Q1 and Q5)? Step 2: Measure the emitter current Iof the CE amplifier (i.e., Q1).

Step 3: Adjust the 500 kΩ potentiometer on the card to set I= 1 mA. If your maximum current is below 1 mA, replace the 1MΩ resistor with any resistor between 560kΩ to 1.5MΩ .

6.1.2 Q: Theoretically,  how does the 500  kΩ potentiometer in the circuit control the emitter

current of transistor Q1 and why?

Step 4: Measure the base, emitter and collector voltages of the transistor in the CE amplifier. Step 5: Measure the terminal voltages of the current source transistor (i.e., Q5).

6.1.3 Q: What are the base, emitter and collector voltages and currents of the transistor in the

CE amplifier?

6.1.4 Q: What are the base, emitter and collector voltages and currents of the current source

transistor?

6.1.5 Q: Is the BJT Q1 in the active operation mode? Also explain why the Q1 emitter voltage is

approximately -0.7V.

6.1.6 Q: Is the BJT Q5 in the active operation mode? Brief explain its working principle.

6.2 Current Source Output Resistance

Step 1: Let’s continue with the circuit that you build in 6.1. Add a 1 kΩ resistor between socket 6 and the input to the current meter (i.e., the connection is: socket 6 to the input of the current meter, to   the output of the current meter, and further to socket 7).

Step 2: Measure the collector-emitter voltage of the current source transistor (i.e., the voltage difference between socket 7 and socket 1) and the current delivered by the current source.

Hint: You can use the digital multimeter (DMM) block of the ELVIS II board to measure the collector-emitter voltage (please refer to Appendix II).

Step 3: Change the resistance of the resistor added inStep 1 above to another four different values

(between 0.1 kΩ to 1 kΩ), and repeat Step 2 above (i.e., measure the corresponding collector-

emitter voltage of the current source transistor and the current delivered by the current source).

6.2.1 Q: Theoretically, how does the resistor connected between socket 6 and the input to the

current meter allow us to change the output voltage from the current source transistor Q5?

6.2.2 Q: Use a table to show the measurement results (you may use a table similar to the Table

2 in Option 1).

6.2.3 Q: Based  on  your  measurement  results,  plot  the  output  current versus the collector-

emitter voltage curve (you may use Excel or Matlab) and find the output resistance of the current source. Include the plot in your lab report. What is the output resistance of the current source transistor?

Hint: The slope of the I-V curve is the output conductance of the current source.

6.2.4 Q: If we analyse the circuit theoretically, what is the value of the output resistance of the

current source? (the Early Voltage of transistor Q5 according to the datasheet is 60 V) .

6.2.5 Q: Compare and discuss your calculation result with your measurement result: are they

similar and why?

请查看以下的C++代码的编写要求,请根据代码要求开始编写代码 PURPOSE: This file is a proforma for the EEET2246 Laboratory Code Submission/Test 1. This file defines the assessment task which is worth 10% of course in total - there is no other documentation. At the BASIC FUNCTIONAL REQUIREMENTS level, your goal is to write a program that takes two numbers from the command line and perform and arithmetic operations with them. Additionally your program must be able to take three command line arguments where if the last argument is 'a' an addition is performed, and if 's' then subtraction is performed with the first two arguments. At the FUNCTIONAL REQUIREMENTS level you will be required to extend on the functionality so that the third argument can also be 'm' for multiplication,'d' for division and 'p' for exponential operations, using the first two arguments as the operands. Additionally, at this level basic error detection and handling will be required. The functionality of this lab is relatively simple: + - / * and "raised to the power of" The emphasis in this lab is to achieve the BASIC FUNCTIONALITY REQUIREMENTS first. Once you a basic program functioning then you should attempt the FUNCTIONALITY REQUIREMENTS and develop your code so that it can handle a full range of error detection and handling. ___________________________________________________________________________________________ ___ GENERAL SPECIFICATIONS (mostly common to all three EEET2246 Laboratory Code Submissions): G1. You must rename your file to lab1_1234567.cpp, where 1234567 is your student number. Your filename MUST NEVER EVER contain any spaces. _under_score_is_Fine. You do not need to include the 's' in front of your student number. Canvas will rename your submission by adding a -1, -2 etc. if you resubmit your solution file - This is acceptable. G2. Edit the name/email address string in the main() function to your student number, student email and student name. The format of the student ID line is CSV (Comma Separated Variables) with NO SPACES- student_id,student_email,student_name When the program is run without any operands i.e. simply the name of the executable such as: lab1_1234567.exe the program MUST print student ID string in Comma Separated Values (CSV) format with no spaces. For example the following text should be outputted to the console updated with your student details: "1234567,s1234567@student.rmit.edu.au,FirstName_LastName" G3. All outputs are a single error character or a numerical number, as specified by the FUNCTIONAL REQURMENTS, followed by a linefeed ( endl or \n). G4. DO NOT add more than what is specified to the expected console output. Do NOT add additional information, text or comments to the output console that are not defined within the SPECIFICATIONS/FUNCTIONAL REQURMENTS. G5. DO NOT use 'cin', system("pause"), getchar(), gets(), etc. type functions. Do NOT ask for user input from the keyboard. All input MUST be specified on the command line separated by blank spaces (i.e. use the argv and argc input parameters). G6. DO NOT use the characters: * / \ : ^ ? in your command line arguments as your user input. These are special character and may not be processed as expected, potentially resulting in undefined behaviour of your program. G7. All input MUST be specified on the command line separated by blank spaces (i.e. use the argc and argv[] input parameters). All input and output is case sensitive unless specified. G8. You should use the Integrated Debugging Environment (IDE) to change input arguments during the development process. G9. When your code exits the 'main()' function using the 'return' command, you MUST use zero as the return value. This requirement is for exiting the 'main()' function ONLY. A return value other than zero will indicate that something went wrong to the Autotester and no marks will be awarded. G10. User-defined functions and/or class declarations must be written before the 'main()' function. This is a requirement of the Autotester and failure to do so will result in your code scoring 0% as it will not be compiled correctly by the Autotester. Do NOT put any functions/class definitions after the 'main()' function or modify the comments and blank lines at the end of this file. G11. You MUST run this file as part of a Project - No other *.cpp or *.h files should be added to your solution. G12. You are not permitted to add any other #includes statements to your solution. The only libraries permitted to be used are the ones predefined in this file. G13. Under no circumstances is your code solution to contain any go_to labels - Please note that the '_' has been added to this description so that this file does not flag the Autotester. Code that contains go_to label like syntax will score 0% and will be treated as code that does not compile. G14. Under no circumstances is your code solution to contain any exit_(0) type functions. Please note that the '_' has been added to this description so that this file does not flag the Autotester. Your solution must always exit with a return 0; in main(). Code that contains exit_(0); label like syntax will score 0% and will be treated as code that does not compile. G15. Under no circumstances is your code solution to contain an infinite loop constructs within it. For example usage of while(1), for(int i; ; i++) or anything similar is not permitted. Code that contains an infinite loop will result in a score of 0% for your assessment submission and will be treated as code that does not compile. G16. Under no circumstances is your code solution to contain any S_l_e_e_p() or D_e_l_a_y() like statements - Please note that the '_' has been added to this description so that this file does not flag the Autotester. You can use such statements during your development, however you must remove delays or sleeps from your code prior to submission. This is important, as the Autotester will only give your solution a limited number of seconds to complete (i.e. return 0 in main()). Failure for your code to complete the required operation/s within the allotted execution window will result in the Autotester scoring your code 0 marks for that test. To test if your code will execute in the allotted execution window, check that it completes within a similar time frame as the provided sample binary. G17. Under no circumstances is your code solution to contain any characters from the extended ASCII character set or International typeset characters. Although such characters may compile under a normal system, they will result in your code potentially not compiling under the Autotester environment. Therefore, please ensure that you only use characters: a ... z, A ... Z, 0 ... 9 as your variable and function names or within any literal strings defined within your code. Literal strings can contain '.', '_', '-', and other basic symbols. G18. All output to console should be directed to the standard console (stdout) via cout. Do not use cerr or clog to print to the console. G19. The file you submit must compile without issues as a self contained *.cpp file. Code that does not compile will be graded as a non-negotiable zero mark. G20. All binary numbers within this document have the prefix 0b. This notation is not C++ compliant (depending on the C++ version), however is used to avoid confusion between decimal, hexadecimal and binary number formats within the description and specification provided in this document. For example the number 10 in decimal could be written as 0xA in hexadecimal or 0b1010 in binary. It can equally be written with leading zeroes such as: 0x0A or 0b00001010. For output to the console screen you should only ever display the numerical characters only and omit the 0x or 0b prefixes (unless it is specifically requested). ___________________________________________________________________________________________ ___ BASIC FUNCTIONAL REQUIREMENTS (doing these alone will only get you to approximately 40%): M1. For situation where NO command line arguments are passed to your program: M1.1 Your program must display your correct student details in the format: "3939723,s3939723@student.rmit.edu.au,Yang_Yang" M2. For situation where TWO command line arguments are passed to your program: M2.1 Your program must perform an addition operation, taking the first two arguments as the operands and display only the result to the console with a new line character. Example1: lab1_1234567.exe 10 2 which should calculate 10 + 2 = 12, i.e. the last (and only) line on the console will be: 12 M3. For situations where THREE command line arguments are passed to your program: M3.1 If the third argument is 'a', your program must perform an addition operation, taking the first two arguments as the operands and display only the result to the console with a new line character. M3.2 If the third argument is 's', your program must perform a subtraction operation, taking the first two arguments as the operands and display only the result to the console with a new line character. The second input argument should be subtracted from the first input argument. M4. For situations where less than TWO or more than THREE command line arguments are passed to your program, your program must display the character 'P' to the console with a new line character. M5. For specifications M1 to M4 inclusive: M5.1 Program must return 0 under all situations at exit. M5.2 Program must be able to handle integer arguments. M5.3 Program must be able to handle floating point arguments. M5.4 Program must be able to handle one integer and one floating point argument in any order. Example2: lab1_1234567.exe 10 2 s which should calculate 10 - 2 = 8, i.e. the last (and only) line on the console will be: 8 Example3: lab1_1234567.exe 10 2 which should calculate 10 + 2 = 12, i.e. the last (and only) line on the console will be: 12 Example4: lab1_1234567.exe 10 4 a which should calculate 10 + 4 = 14, i.e. the last (and only) line on the console will be: 14 ___________________________________________________________________________________________ ___ FUNCTIONAL REQUIREMENTS (to get over approximately 50%): E1. For situations where THREE command line arguments (other than 'a' or 's') are passed to your program: E1.1 If the third argument is 'm', your program must perform a multiplication operation, taking the first two arguments as the operands and display only the result to the console with a new line character. E1.2 If the third argument is 'd', your program must perform a division operation, taking the first two arguments as the operands and display only the result to the console with a new line character. E1.3 If the third argument is 'p', your program must perform an exponential operation, taking the first argument as the base operand and the second as the exponent operand. The result must be display to the console with a new line character. Hint: Consider using the pow() function, which has the definition: double pow(double base, double exponent); Example5: lab1_1234567.exe 10 2 d which should calculate 10 / 2 = 5, i.e. the last (and only) line on the console will be: 5 Example6: lab1_1234567.exe 10 2 p which should calculate 10 to power of 2 = 100, i.e. the last (and only) line on the console will be: 100 NOTE1: DO NOT use the character ^ in your command line arguments as your user input. Question: Why don't we use characters such as + - * / ^ ? to determine the operation? Answer: Arguments passed via the command line are processed by the operating system before being passed to your program. During this process, special characters such as + - * / ^ ? are stripped from the input argument stream. Therefore, the input characters: + - * / ^ ? will not be tested for by the autotester. See sections G6 and E7. NOTE2: the pow() and powl() function/s only work correctly for given arguments. Hence, your code should output and error if there is a domain error or undefined subset of values. For example, if the result does not produce a real number you code should handle this as an error. This means that if the base is negative you can't accept and exponent between (but not including) -1 and 1. If you get this then, output a MURPHY's LAW error: "Y" and return 0; NOTE3: zero to the power of zero is also undefined, and should also be treated MURPHY's LAW error. So return "Y" and return 0; In Visual Studio, the 0 to the power of 0 will return 1, so you will need to catch this situation manually, else your code will likely calculate the value as 1. ___ REQUIRED ERROR HANDLING (to get over approximately 70%): The following text lists errors you must detect and a priority of testing. NB: order of testing is important as each test is slight more difficult than the previous test. All outputs should either be numerical or upper-case single characters (followed by a new line). Note that case is important: In C, 'V' is not the same as 'v'. (No quotes are required on the output). E2. Valid operator input: If the third input argument is not a valid operation selection, the output shall be 'V'. Valid operators are ONLY (case sensitive): a addition s subtraction m multiplication d division p exponentiation i.e. to the power of: 2 to the power of 3 = 8 (base exponent p) E3. Basic invalid number detection (Required): Valid numbers are all numbers that the "average Engineering graduate" in Australia would consider valid. Therefore if the first two arguments are not valid decimal numbers, the output shall be 'X'. For example: -130 is valid +100 is valid 1.3 is valid 3 is valid 0.3 is valid .3 is valid ABC123 is not valid 1.3.4 is not valid 123abc is not valid ___ ERROR HANDLING (not marked by the autotester): E4. Intermediate invalid number detection (NOT TESTED BY AUTOTESTER - for your consideration only): If the first two arguments are not valid decimal numbers, the output shall be 'X'. Using comma punctuated numbers and scientific formatted numbers are considered valid. For example: 0000.111 is valid 3,000 is valid - NB: atof() will read this as '3' not as 3000 1,000.9 is valid - NB: atof() will read this as '1' not as 1000.9 1.23e2 is valid 2E2 is valid -3e-0.5 is not valid (an integer must follow after the e or E for floating point number to be valid) 2E2.1 is not valid e-1 is not valid .e3 is not valid E5. Advanced invalid number detection (NOT TESTED BY AUTOTESTER - for your consideration only): If the first two arguments are not valid decimal numbers, the output shall be 'X'. 1.3e-1 is valid 1,00.0 is valid - NB: if the comma is not removed atof() will read this as '1' not as 100 +212+21-2 is not valid - NB: mathematical operation on a number of numbers, not ONE number 5/2 is not valid - NB: mathematical operation on a number of numbers, not ONE number HINT: consider the function atof(), which has the definition: double atof (const char* str); Checking the user input for multiple operators (i.e. + or -) is quite a difficult task. One method may involve writing a 'for' loop which steps through the input argv[] counting the number of operators. This process could also be used to count for decimal points and the like. The multiple operator check should be considered an advanced task and developed once the rest of the code is operational. E6. Input number range checking: All input numbers must be between (and including) +2^16 (65536) or -2^16 (-65536). If the operand is out of range i.e. too small or too big, the output shall be 'R'. LARGE NUMBERS: is 1.2e+999 acceptable input ? what happens if you enter such a number ? try and see. Hint: #INF error - where and when does it come up ? SMALL NUMBERS: is 1.2e-999 acceptable input ? what happens if you enter such a number ? try and see. Test it by writing your own test program. E7. ERROR checks which will NOT be performed are: E7.1 Input characters such as: *.* or / or \ or : or any of these characters: * / ^ ? will not be tested for. E7.2 Range check: some computer systems accept numbers of size 9999e999999 while others flag and infinity error. An infinity error becomes an invalid input Therefore: input for valid numbers will only be tested to the maximum 9.9e99 (Note: 9.9e99 is out of range and your program should output 'R') E8. Division by zero should produce output 'M' E9. Error precedence: If multiple errors occur during a program execution event, your program should only display one error code followed by a newline character and then exit (using a return 0; statement). In general, the precedence of the error reported to the console should be displayed in the order that they appear within this proforma. However to clarify the exact order or precedence for the error characters, the precedence of the displayed error code should occur in this order: 'P' - Incorrect number of input command line arguments (see M4) 'X' - Invalid numerical command line argument 'V' - Invalid third input argument 'R' - operand (command line argument) value out of range 'M' - Division by zero 'Y' - MURPHY'S LAW (undefined error) Therefore if an invalid numerical command line argument and an invalid operation argument are passed to the program, the first error code should be displayed to the console, which in this case would be 'X'. Displaying 'V' or 'Y' would be result in a loss of marks. E10. ANYTHING ELSE THAT CAN GO WRONG (MURPHY'S LAW TEST): If there are any other kinds of errors not covered here, the output shall be 'Y'. Rhetorical question: What for example are the error codes that the Power function returns ? If this happens then the output shall be 'Y'. See section E1.3, NOTE2. ___________________________________________________________________________________________ ___ HINTS: - Use debug mode and a breakpoint at the return statement prior to program finish in main. - What string conversion routines, do you know how to convert strings to number? Look carefully as they will be needed to convert a command line parameter to a number and also check for errors. - ERROR CHECKING: The basic programming rules are simple (as covered in lectures): 1) check that the input is valid. 2) check that the output is valid. 3) if any library function returns an error code USE IT !!! CHECK FOR IT !!! - Most conversion routines do have inbuilt error checking - USE IT !!! That means: test for the error condition and take some action if the error is true. If that means more than 50% of your code is error checking, then that's the way it has to be. ____________________________________________________________________________________________ */ // These are the libraries you are allowed to use to write your solution. Do not add any // additional libraries as the auto-tester will be locked down to the following: #include <iostream> #include <cstdlib> #include <time.h> #include <math.h> #include <errno.h> // leave this one in please, it is required by the Autotester! // Do NOT Add or remove any #include statements to this project!! // All library functions required should be covered by the above // include list. Do not add a *.h file for this project as all your // code should be included in this file. using namespace std; const double MAXRANGE = pow(2.0, 16.0); // 65536 const double MINRANGE = -pow(2.0, 16.0); // All functions to be defined below and above main() - NO exceptions !!! Do NOT // define function below main() as your code will fail to compile in the auto-tester. // WRITE ANY USER DEFINED FUNCTIONS HERE (optional) // all function definitions and prototypes to be defined above this line - NO exceptions !!! int main(int argc, char *argv[]) { // ALL CODE (excluding variable declarations) MUST come after the following 'if' statement if (argc == 1) { // When run with just the program name (no parameters) your code MUST print // student ID string in CSV format. i.e. // "studentNumber,student_email,student_name" // eg: "3939723,s3939723@student.rmit.edu.au,Yang_Yang" // No parameters on command line just the program name // Edit string below: eg: "studentNumber,student_email,student_name" cout << "3939723,s3939723@student.rmit.edu.au,Yang_Yang" << endl; // Failure of your program to do this cout statement correctly will result in a // flat 10% marks penalty! Check this outputs correctly when no arguments are // passed to your program before you submit your file! Do it as your last test! // The convention is to return Zero to signal NO ERRORS (please do not change it). return 0; } //--- START YOUR CODE HERE. // The convention is to return Zero to signal NO ERRORS (please do not change it). // If you change it the AutoTester will assume you have made some major error. return 0; } // No code to be placed below this line - all functions to be defined above main() function. // End of file.
08-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值