Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please code this is C++ Part 1: A DC circuit simulator Please read this over carefully before beginning to work on this laboratory. It is

image text in transcribedimage text in transcribedimage text in transcribed

Please code this is C++

Part 1: A DC circuit simulator Please read this over carefully before beginning to work on this laboratory. It is strongly suggested that you create a script (possibly pseudo code or even a flowchart) for solving this problem. This project is best solved by breaking it into small easily solved-problems using functions. Specification: Given a DC circuit with voltage supply Vdd (e.g., 5V) and resistors R1, R2, ... Rn connected in series, the current flow i can be calculated by i = Vdd/SUM (R1, R2, ...., Rn) and the power consumption can be calculated by P = i * Vdd. Unfortunately, we cannot calculate the voltage drop or power dissipation introduced by each resistor since we have not covered the chapters for vectors, arrays, or structures. For each circuit, the resistors are read from an input file. Each circuit has its resistance values separated by a negative number, since resistance values cannot be negative. For example, if the input file contains the following values: 10.0 20.5 100.0 70.5-46 30.8 1000.5 480.50 -50 we know that there are two DC circuits. The first circuit contains 4 resistors connected in series, while the second DC circuit contains 3 resistors. Step 1: From an input file (e.g., resistors.txt), use a while loop to read a resistance value, called myResistance. If the resistance value is a negative value, ignore it and go to Step 4 else go to Step 2. If it is end of the file, stop the program. Step 2: Write a function called Rmin max() to find the maximal resistance and minimal resistance for the circuit based on the resistances already read so far. The function takes myResistance, minResiatnce (the minimum resistance read so far), maxResistance (the maximal resistance read so far) as parameters. You have to consider which parameters use call by value, which parameters use call by reference. Step 3: Write a function called RtotalNum() to find the total resistance values and total number of resistors based on the resistances already read so far. The function takes myResistance, totalResiatnce (the sum of resistance read so far), totalResistors (the total number of resistors read so far) as parameters. You have to consider which parameters use call by value, which parameters use call by reference. Go to Step 1. Step 4: At this stage, you already read all resistors for the circuit, and we need to calculate the current flow (currentFlow) and power consumption (circuitPower). You should input the voltage supply called voltage, and write a function called currentPower() to computer the current flow and power dissipation using the equations presented above. The currentPower() function takes voltage, totalResistance, currentFlow, and circuit Power as parameters. Step 5: Write the circuit data such as minResistance, maxResistance, totalResistance, totalResistots, currentFlow, and circuitPower into an output file (e.g., called circuitStatistics.txt) by following the format of sample output file shown below. This can be done in the main() program. Go to Step 1. Of course, you must write the main() program to integrate all functions and the major control flow together. Our suggestion to you is to fully test each function() by calling the function from the main() program before you implement and test the next function. Divide and conquer is always the best way to complete a project. Use lots of cout's to display your program flow to debug your program. Note that all functions and main() will all be in a single program (e.g., called DCSimulator.cpp). Your output file must be formatted, at least, like the sample output file. Both sample input file and sample output file will be posted with the lab description. Sample input file: 10 30 20 50-60 50 30 80 10.8 -80 14 59 36 33.2 636 99 442.5-90 535.5 828 52 49.9 616 649.5 826.7 824.9 616.4-30 635.60-53 324 513.5 845.90 438.4 842.3 748.5-90 Sample output file: cktNo: 1 voltage: 110.00 Num resistors: 4 current: 1.00 power: 110.00 Ohm sum: 110.00 Rmin: 10.00 Rmax: 50.00 Ohm.sum: 170.80 Rmin; 10.80 Rmax: 80.00 cktNo: 2 voltage: 170.80 Num.resistors: 4 current: 1.00 power: 170.80 Ohm sum: 1319.70 Rmin; 14.00 Rmax: 636.00 cktNo: 3 voltage: 2000.00 Num resistors: 7 current: 1.52 power: 3030.99 Ohm sum: 4998.90 Rmin; 49.90 Rmax: 828.00 cktNo: 4 voltage: 3000.00 Num resistors: 9 current: 0.60 power: 1800.40 cktNo: 5 voltage: 700.00 Num resistors: 1 current: 1.10 power: 770.93 Ohm.sum: 635.60 Rmin; 635.60 Rmax: 635.60 Ohm.sum: 3712.60 Rmin; 324.00 Rmax: 845.90 cktNo: 6 voltage: 1000.00 Num resistors: 6 current: 0.27 power: 269.35 Part 1: A DC circuit simulator Please read this over carefully before beginning to work on this laboratory. It is strongly suggested that you create a script (possibly pseudo code or even a flowchart) for solving this problem. This project is best solved by breaking it into small easily solved-problems using functions. Specification: Given a DC circuit with voltage supply Vdd (e.g., 5V) and resistors R1, R2, ... Rn connected in series, the current flow i can be calculated by i = Vdd/SUM (R1, R2, ...., Rn) and the power consumption can be calculated by P = i * Vdd. Unfortunately, we cannot calculate the voltage drop or power dissipation introduced by each resistor since we have not covered the chapters for vectors, arrays, or structures. For each circuit, the resistors are read from an input file. Each circuit has its resistance values separated by a negative number, since resistance values cannot be negative. For example, if the input file contains the following values: 10.0 20.5 100.0 70.5-46 30.8 1000.5 480.50 -50 we know that there are two DC circuits. The first circuit contains 4 resistors connected in series, while the second DC circuit contains 3 resistors. Step 1: From an input file (e.g., resistors.txt), use a while loop to read a resistance value, called myResistance. If the resistance value is a negative value, ignore it and go to Step 4 else go to Step 2. If it is end of the file, stop the program. Step 2: Write a function called Rmin max() to find the maximal resistance and minimal resistance for the circuit based on the resistances already read so far. The function takes myResistance, minResiatnce (the minimum resistance read so far), maxResistance (the maximal resistance read so far) as parameters. You have to consider which parameters use call by value, which parameters use call by reference. Step 3: Write a function called RtotalNum() to find the total resistance values and total number of resistors based on the resistances already read so far. The function takes myResistance, totalResiatnce (the sum of resistance read so far), totalResistors (the total number of resistors read so far) as parameters. You have to consider which parameters use call by value, which parameters use call by reference. Go to Step 1. Step 4: At this stage, you already read all resistors for the circuit, and we need to calculate the current flow (currentFlow) and power consumption (circuitPower). You should input the voltage supply called voltage, and write a function called currentPower() to computer the current flow and power dissipation using the equations presented above. The currentPower() function takes voltage, totalResistance, currentFlow, and circuit Power as parameters. Step 5: Write the circuit data such as minResistance, maxResistance, totalResistance, totalResistots, currentFlow, and circuitPower into an output file (e.g., called circuitStatistics.txt) by following the format of sample output file shown below. This can be done in the main() program. Go to Step 1. Of course, you must write the main() program to integrate all functions and the major control flow together. Our suggestion to you is to fully test each function() by calling the function from the main() program before you implement and test the next function. Divide and conquer is always the best way to complete a project. Use lots of cout's to display your program flow to debug your program. Note that all functions and main() will all be in a single program (e.g., called DCSimulator.cpp). Your output file must be formatted, at least, like the sample output file. Both sample input file and sample output file will be posted with the lab description. Sample input file: 10 30 20 50-60 50 30 80 10.8 -80 14 59 36 33.2 636 99 442.5-90 535.5 828 52 49.9 616 649.5 826.7 824.9 616.4-30 635.60-53 324 513.5 845.90 438.4 842.3 748.5-90 Sample output file: cktNo: 1 voltage: 110.00 Num resistors: 4 current: 1.00 power: 110.00 Ohm sum: 110.00 Rmin: 10.00 Rmax: 50.00 Ohm.sum: 170.80 Rmin; 10.80 Rmax: 80.00 cktNo: 2 voltage: 170.80 Num.resistors: 4 current: 1.00 power: 170.80 Ohm sum: 1319.70 Rmin; 14.00 Rmax: 636.00 cktNo: 3 voltage: 2000.00 Num resistors: 7 current: 1.52 power: 3030.99 Ohm sum: 4998.90 Rmin; 49.90 Rmax: 828.00 cktNo: 4 voltage: 3000.00 Num resistors: 9 current: 0.60 power: 1800.40 cktNo: 5 voltage: 700.00 Num resistors: 1 current: 1.10 power: 770.93 Ohm.sum: 635.60 Rmin; 635.60 Rmax: 635.60 Ohm.sum: 3712.60 Rmin; 324.00 Rmax: 845.90 cktNo: 6 voltage: 1000.00 Num resistors: 6 current: 0.27 power: 269.35

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions

Question

How did you feel about taking piano lessons as a child? (general)

Answered: 1 week ago