Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ 1.Create a text file with the word Divider on the first line, and save it to a file named divider_wheatstone_circuits.txt in the directory where

c++

1.Create a text file with the word Divider on the first line, and save it to a file named divider_wheatstone_circuits.txt in the directory where your program is stored. For the remainder of this assignment, all input will be read from this file. Declare an ifstream object, use it to open the input file, and read the first line with the >> operator. If the first line is anything other than Divider or Wheatstone, the program should exit with the error message (printed to standard output) ERROR! Invalid header. and a return value of -1.

2. If the first line of the file is Divider, the program should read three more lines from the file, which hold values for the voltage source Vs and the resistors R1 and R2. Store Vs in a double variable, and store R1 and R2 in int variables. Define an ofstream object, and use it to open a text file for output named divider_wheatstone_solutions.txt. Write messages to the output file to report the values that were read from the file. Type the following into the input file and use it to test your program. Divider 5 1000 1500

3.Modify your program so that, if the first line of the file is Divider, it will solve the voltage divider circuit by computing the loop current I and the resistor voltages V1 and V2, and write messages to the output file reporting the computed values. Test your program using the input file from step 3, and make sure the computed values are correct. The required format for the output file is shown below for this case. ECE 0301: Circuit Solver for Voltage Divider and Wheatstone bridge example circuits. ----- Circuit #1 (Voltage Divider) --- Source voltage: Vs = 5 Volts. Resistor: R1 = 1000 Ohms. Resistor: R2 = 1500 Ohms. Loop current: I = 0.002 Amperes. Resistor voltage: V1 = 2 Volts. Resistor voltage: V2 = 3 Volts. Modify the text file by changing the component values, and test again. The loop current and resistor voltage will be reported with more digits if the answers are not integers or terminating decimals. Can your program solve any voltage divider problem?

4. If the first line of the file is Wheatstone, the program should read seven more lines from the file, which hold values for the voltage source Vs, the current source Is, and the resistors R1 through R5. Store Vs and Is in double variables, and store the resistances in int variables. Write messages to the output file to report the values that were read from the file. Test your program with this file: Wheatstone 12.0 0.1 150 150 150 150 150

5. Modify your program so that, if the first line of the file is Wheatstone, it will solve the Wheatstone bridge circuit by computing the resistor voltages V1 through V5, and resistor currents I1 through I5, and write messages to the output file reporting the computed values. Test your program using the input file from step 5, and verify that the computed values are correct. The required output file format is shown below for this case. ECE 0301 Circuit Solver for Voltage Divider and Wheatstone bridge example circuits. ----- Circuit #1 (Wheatstone Bridge) --- Source voltage: Vs = 12 Volts. Source current: Is = 0.1 Amperes. Resistor: R1 = 150 Ohms. Resistor: R2 = 150 Ohms. Resistor: R3 = 150 Ohms. Resistor: R4 = 150 Ohms. Resistor: R5 = 150 Ohms. Resistor voltage: V1 = 6 Volts. Resistor current: I1 = 0.04 Amperes. Resistor voltage: V2 = -4.5 Volts. Resistor current: I2 = -0.03 Amperes. Resistor voltage: V3 = 10.5 Volts. Resistor current: I3 = 0.07 Amperes. Resistor voltage: V4 = 10.5 Volts. Resistor current: I4 = 0.07 Amperes. Resistor voltage: V5 = -4.5 Volts. Resistor current: I5 = -0.03 Amperes.

6. The method we derived for solving the Wheatstone bridge circuit will not work in all cases. Your program should produce a divide-by-zero error if any of the following conditions are true (go back and look at the equations to see why): 2 R = 0 4 0 V IR s s = 3 R = 0 5 0 V IR s s + = . Furthermore, if either of the quantities in the right column are very small but not zero, then round-off error in representing them could occur when they are used as the denominator of a division operation. Round-off error for double-precision floating-point calculations is on the order of 15 10 , and we will require that all denominators be at least 100 times larger (in magnitude) than this value. Modify your program so that, if it is directed to solve the Wheatstone bridge circuit, and any one of the following conditions are true 2 R = 0 13 13 4 10 10 V IR s s >+>

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_2

Step: 3

blur-text-image_3

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions