Question

In: Computer Science

1. Introduction This assignment will give you some experience working with C input (using scanf()) and...

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.

Test cases for the program can be found at this link.

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 numbers—you 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 posted 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 operations—multiplication 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 * n);
  • printf("17/x + 35n = %lf\n", (17 / x) + (35 * n));
  • printf("Rectangle with length %d, width %lf has area %lf\n", 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.

Solutions

Expert Solution

thanks for the question, here is the fully implemented code in C. I ran for the given example in the question and the output is coming exaclty as given.

Let me know for any question, do appreciate with an up vote please :)

------------------------------------------------------------------------------------------------------------------------------------------------------------

#include<stdio.h>

int main(){

               

                double volts;

                double r1,r2,r3;

               

                printf("Enter voltage source value (V): "); scanf("%lf",&volts);

                printf("Enter three resistance values (ohms): "); scanf("%lf %lf %lf",&r1,&r2,&r3);

               

               

                double total_resistance = r1+r2+r3;

                printf("SERIES CIRCUIT\n");

                double current = volts/total_resistance;

                printf("Current through circuit: %lf A\n",current);

                printf("Voltage across R1: %lf V\n",current*r1);

                printf("Voltage across R2: %lf V\n",current*r2);

                printf("Voltage across R3: %lf V\n",current*r3);

               

                printf("\n");

               

               

                printf("PARALLEL CIRCUIT\n");

                printf("Voltage across each resistor: %lf V\n",volts);

                printf("Current through R1: %lf A\n",volts/r1);

                printf("Current through R2: %lf A\n",volts/r2);

                printf("Current through R3: %lf A\n",volts/r3);

               

                printf("\n");

                printf("R2 & R3 IN PARALLEL\n");

               

                double eq_resistance = r1+ (r2*r3)/(r2+r3);

                double eq_current = volts/eq_resistance;

               

                printf("Voltage across R1: %lf V\n",eq_current*r1);

                printf("Current through R1: %lf A\n",eq_current);

               

                double r2_current = eq_current*r2/(r2+r3);

                double r3_current = eq_current*r3/(r2+r3);

                printf("Voltage across R2: %lf V\n",r2_current*r2);

                printf("Current through R2: %lf A\n",r2_current);

                printf("Voltage across R3: %lf V\n",r3_current*r3);

                printf("Current through R3: %lf A\n",r3_current);

               

               

}

==========================================================

thanks so much : )


Related Solutions

Assignment Overview IN C++ This assignment will give you practice with numerical calculations, simple input/output, and...
Assignment Overview IN C++ This assignment will give you practice with numerical calculations, simple input/output, and if-else statements. Candy Calculator [50 points] The Harris-Benedict equation estimates the number of calories your body needs to maintain your weight if you do no exercise. This is called your basal metabolic rate or BMR. The calories needed for a woman to maintain her weight is: BMR = 655 + (4.3 * weight in pounds) + (4.7 * height in inches) - (4.7 *...
The objective of this homework is to give you experience using inheritance with C++. You will...
The objective of this homework is to give you experience using inheritance with C++. You will use the provided employee base class and implement two derived classes, salaried employee and hourly employee. For this assignment, you will use the base class Employee, which is implemented with the files Employee.h and Employee.cpp. A test file, test.cpp, is also provided for your use, as you choose to use it. Each employee object has a user id; a first and last name; a...
The C++ question: This part of the assignment will give you a chance to perform some...
The C++ question: This part of the assignment will give you a chance to perform some simple tasks with pointers. The instructions below are a sequence of tasks that are only loosely related to each other. Start the assignment by creating a file named pointerTasks.cpp with an empty main function, then add statements in main() to accomplish each of the tasks listed below. Some of the tasks will only require a single C++ statement, others will require more than one....
This assignment will give you more experience on the use of: 1. integers (int) 2. floats...
This assignment will give you more experience on the use of: 1. integers (int) 2. floats (float) 3. conditionals 4. iteration The goal of this project is to make a fictitious comparison of the federal income. You will ask the user to input their taxable income. Use the income brackets given below to calculate the new and old income tax. For the sake of simplicity of the project we will only consider individuals and not married users. We will also...
This assignment will give you more experience on the use of: 1. integers (int) 2. floats...
This assignment will give you more experience on the use of: 1. integers (int) 2. floats (float) 3. conditionals(if statements) 4. iteration(loops) Functions, lists, dictionary, classes CANNOT BE USED!!! The goal of this project is to make a fictitious comparison of the federal income. You will ask the user to input their taxable income. Use the income brackets given below to calculate the new and old income tax. For the sake of simplicity of the project we will only consider...
Purpose This assignment should give you experience in using file descriptors, open(), close(), write(), stat() and...
Purpose This assignment should give you experience in using file descriptors, open(), close(), write(), stat() and chmod(), perror(), and command line arguments. Program Write a C++ program that will allow you to add messages to a file that has NO permissions for any user. A Unix system has many files that have sensitive information in them. Permissions help keep these files secure. Some files can be publicly read, but can not be altered by a regular user (ex.: /etc/passwd). Other...
introduction: C PROGRAMMING For this assignment you will write an encoder and a decoder for a...
introduction: C PROGRAMMING For this assignment you will write an encoder and a decoder for a modified "book cipher." A book cipher uses a document or book as the cipher key, and the cipher itself uses numbers that reference the words within the text. For example, one of the Beale ciphers used an edition of The Declaration of Independence as the cipher key. The cipher you will write will use a pair of numbers corresponding to each letter in the...
This is an assignment for a C++ introduction class. This module included if statements. If you...
This is an assignment for a C++ introduction class. This module included if statements. If you have any questions please feel free to let me know! { In this module you learned about making decisions in C++ and how to combine decision making with the material from the first few modules to solve problems. For this assignment, write a program that calculates a discount for buying certain quantities of coffee. Consider the following scenario: A coffee company sells a pound...
This assignment is to give you practice using struts, arrays, and sorting. (Objective C++ and please...
This assignment is to give you practice using struts, arrays, and sorting. (Objective C++ and please have a screenshot of output) In competitive diving, each diver makes dives of varying degrees of difficulty. Nine judges score each dive from 0 through 10 in steps of 0.5. The difficulty is a floating-point value between 1.0 and 3.0 that represents how complex the dive is to perform. The total score is obtained by discarding the lowest and highest of the judges’ scores,...
0. Introduction. In this assignment you will implement a stack as a Java class, using a...
0. Introduction. In this assignment you will implement a stack as a Java class, using a linked list of nodes. Unlike the stack discussed in the lectures, however, your stack will be designed to efficiently handle repeated pushes of the same element. This shows that there are often many different ways to design the same data structure, and that a data structure should be designed for an anticipated pattern of use. 1. Theory. The most obvious way to represent a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT