Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Introduction This assignment will give you some experience working with C input (using scanf()) and output (using printf()), as well as arithmetic operations with

1. Introduction

This assignment will give you some experience working with C input (using scanf()) and output (using printf()), as well as arithmetic operations with variables. You will do some very basic circuit analysis, reading the values of a voltage source and three resistors, and calculating the voltage across and current through each of the resistors using three different circuit configurations.

Remember, in addition to submitting your code, you MUST complete the Blackboard assignment "Program 2 style assessment" to get all of the points for this program. You can complete this "assignment" by typing a short message indicating you submitted your code through the textbook IDE.

2. Specification

Note that this specification refers to several figures, which can be found at the following link: Program 2 figures

In this program, you will deal with the three resistive circuits in Figure 1: a series circuit, a parallel circuit, and a circuit using resistors both in series and in parallel.

Those of you who are familiar with basic DC circuit analysis should be able to easily derive the voltage across and current through each resistor. For more details and equations, please see the Circuit Analysis Supplement in the Program 2 figures document.

Input Specification

Your program should prompt the user to enter the values of Vsource (in volts) and R1, R2, and R3 (in ohms). The source voltage should be entered on one line, while all three resistance values should be entered on a second line. (Note: remember, scanf() ignores whitespace when scanning numbersyou do not have to explicitly worry about varying numbers of spaces.)

The program could produce the first two lines below (the numbers are user inputs, not program outputs):

Enter voltage source value (V): 10 Enter three resistance values (ohms): 5 10 10 

All input values should be treated as double-precision floating point values.

Output Specification

Once the voltage and resistance values have been read, you should print the following information for each circuit, as shown below:

A blank line (to separate each circuit description)

A brief circuit description (e.g., SERIES CIRCUIT)

The voltage across each resistor. Note that, in the parallel circuit, the voltage across each resistor is the same and should only be printed once.

The current through each resistor. Note that, in the series circuit, the current through each resistor is the same and should only be printed once.

See the Circuit Analysis Supplement in the Program 2 figures document for more details on determining the appropriate voltage and current through each resistor if you are unfamiliar with the analysis used. The output lines that would follow the example shown above would be:

SERIES CIRCUIT Current through circuit: 0.400000 A Voltage across R1: 2.000000 V Voltage across R2: 4.000000 V Voltage across R3: 4.000000 V PARALLEL CIRCUIT Voltage across each resistor: 10.000000 V Current through R1: 2.000000 A Current through R2: 1.000000 A Current through R3: 1.000000 A R2 & R3 IN PARALLEL Voltage across R1: 5.000000 V Current through R1: 1.000000 A Voltage across R2: 5.000000 V Current through R2: 0.500000 A Voltage across R3: 5.000000 V Current through R3: 0.500000 A 

See the built-in program test cases for more sample program runs.

3. Hints

Order of operations

C operators follow the same order of operations you likely learned for basic arithmetic operationsmultiplication and division take precedence over addition and subtraction. Parentheses have higher precedence than any of these operators. So, for example, if x = 5, y = 2, and z = 3:

x + y * z = 5 + 2 * 3 = 5 + 6 = 11

(x + y) * z = (5 + 2) * 3 = 7 * 3 = 21

x + y / 2 = 5 + 2 / 2 = 5 + 1 = 6

Variables and expressions

Variables should be used to store values that are used more than once to avoid repeating calculations. For example, you could improve the following code by creating a variable to hold the value a + 2:

x = (a + 2) * 3; y = 5 / (a + 2); z = (a + 2)  (a + 2); 

Values used only for output do not need variables, since printf() can print the value of any expression. Each of the following lines is therefore a valid use of this function. Assume you have variables int n and double x:

printf("n squared: %d, n cubed: %d ", n * n, n * n * n);

printf("17/x + 35n = %lf ", (17 / x) + (35 * n));

printf("Rectangle with length %d, width %lf has area %lf ", n, x, n * x);

4. Grading Rubric

For this assignment, points are assigned as follows:

40 points: Your code uses appropriate coding style such as including appropriate comments, indenting the main() function body, and appropriate variable declarations. You must complete the Blackboard assignment "Program 2 style assessment" to earn any of these points.

60 points: Your code compiles and output matches the desired test outputs shown below. Each test case has a different number of points assigned to it, as shown in submit mode. This section will be auto-graded, while I will assign the other 40 points after inspecting your program.

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

More Books

Students also viewed these Databases questions