Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This code needs to be done in c++ Objective: This lab is designed to practice more on functions and looping, and begin to practice file

This code needs to be done in c++

image text in transcribed

image text in transcribed

image text in transcribed

Objective: This lab is designed to practice more on functions and looping, and begin to practice file I/O. It contains two parts: Part 1: A direct-current circuit simulator and Part 2: Rock paper scissors game. This lab does not have big logical thinking, but gives you another training in decomposing a task into smaller pieces to solve, and get file 1/0 into your skill set. 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 pri * 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 my Resistance, 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 (circuit Power). 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 circuit Power 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 50.00 current: 1.00 power: 110.00 Ohm_sum: 110.00 Rmin: 10.00 Rmax: Ohm_sum: 170.80 Rmin: 10.80 Rmax: cktNo: 2 voltage: 170.80 Num_resistors: 4 80.00 current: 1.00 power: 170.80 Ohm_sum: 1319.70 Rmin: 14.00 Rmax: cktNo: 3 voltage: 2000.00 Num_resistors: 7 636.00 current: 1.52 power: 3030.99 cktNo: 4 voltage: 3000.00 Num_resistors: 9 828.00 current: 0.60 power: 1800.40 Ohm_sum: 4998.90 Rmin: 49.90 Rmax: Ohm_sum: 635.60 Rmin: 635.60 Rmax: cktNo: 5 voltage: 700.00 Num_resistors: 1 635.60 current: 1.10 power: 770.93 Ohm_sum: 3712.60 Rmin: 324.00 Rmax: cktNo: 6 voltage: 1000.00 Num_resistors: 6 845.90 current: 0.27 power: 269.35 Objective: This lab is designed to practice more on functions and looping, and begin to practice file I/O. It contains two parts: Part 1: A direct-current circuit simulator and Part 2: Rock paper scissors game. This lab does not have big logical thinking, but gives you another training in decomposing a task into smaller pieces to solve, and get file 1/0 into your skill set. 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 pri * 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 my Resistance, 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 (circuit Power). 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 circuit Power 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 50.00 current: 1.00 power: 110.00 Ohm_sum: 110.00 Rmin: 10.00 Rmax: Ohm_sum: 170.80 Rmin: 10.80 Rmax: cktNo: 2 voltage: 170.80 Num_resistors: 4 80.00 current: 1.00 power: 170.80 Ohm_sum: 1319.70 Rmin: 14.00 Rmax: cktNo: 3 voltage: 2000.00 Num_resistors: 7 636.00 current: 1.52 power: 3030.99 cktNo: 4 voltage: 3000.00 Num_resistors: 9 828.00 current: 0.60 power: 1800.40 Ohm_sum: 4998.90 Rmin: 49.90 Rmax: Ohm_sum: 635.60 Rmin: 635.60 Rmax: cktNo: 5 voltage: 700.00 Num_resistors: 1 635.60 current: 1.10 power: 770.93 Ohm_sum: 3712.60 Rmin: 324.00 Rmax: cktNo: 6 voltage: 1000.00 Num_resistors: 6 845.90 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

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

Students also viewed these Databases questions