Create a program that allows a user to view the voltage

Assignment Help C/C++ Programming
Reference no: EM131472974

PROBLEM

You are to create a program that allows a user to view the voltage, current and impedance for each component and the total in either the parallel circuit (a) or series circuit (b). The program will ask the user for the circuit type, the source voltage, the frequency, the number of components, and the values of each component. The two circuits are shown below:

1969_Figure.jpg

FUNCTION PROTOTYPES AND INCLUDES

1. You must include the stdio.h and stdlib libraries
2. The following function prototypes are to be used:

2314_Figure1.jpg

a. The first two are described below
b. The last four will be developed in lab5, you need to alter the types from floats to doubles
c. You can change the naming
d. You cannot change the types

FUNCTION - MAIN

1. The program prints to the screen the student number, student name and the assignment number. This is enclosed by
double asterisks. Ensure you follow the below format.

**3777777    John Smith Assignment 2**

2. The program asks the user which circuit they want to evaluate, the frequency in hertz, the source voltage and the number of components. And stores the results appropriately. All of these values are positive integers. When asking for the number of components, the type of circuit should be specified as shown below.

a. You can assume the user enters valid values for frequency, voltage and number of components.
b. You must handle the case where the user enters an incorrect value for the type of circuit and give a message to the user. (No example given, a single line for ‘invalid message' to user ending with a newline. The message is up to you, but must be appropriate)

Do you want to create a 1.parallel or 2. series circuit evaluation? 1

Enter the frequency in Hertz of the source:60

Enter the source voltage :12

How many components are in parallel:3

3. The program creates an array of pointers to doubles (hint: use [ ]), the array is of length 6

a. Then using a for loop dynamically allocate memory (malloc) for each of the pointers an array of size sizeof(double) *(number of components + 1)
b. This is the result table
c. The program stores the source voltage in the array as shown below

result_table[4] [number_of_components] = source_voltage;

result_table[5] [number_of_components] = 0L;

Impedance component 1 -

Real part

Impedance component 2 -

Real part

...

Impedance component n -

Real part

Total Impedance  - Real part

Impedance component 1 -

Imaginary part

Impedance component 2 -

Imaginary part

...

Impedance component n -

Imaginary part

Total Impedance  - Imaginary part

Current component 1 -

Real part

Current component 2 -

Real part

...

Current component n -

Real part

Total Current - Real part

Current component 1 -

Imaginary part

Current component 2 -

Imaginary part

...

Current component n -

Imaginary part

Total Current - Imaginary part

Voltage component 1 -

Real part

Voltage component 2 -

Real part

...

Voltage component n -

Real part

Total Votage/Source Voltage - Real part

Voltage component 1 - Imaginary part

Voltage component 2 -

Imaginary part

...

Voltage component n -

Imaginary part

Total Votage/Source Voltage - I

maginary

part

4. The program creates a pointer to ints and dynamically allocates memory for an array of length number of components. This will store the component types.

5. The program creates a pointer to doubles and dynamically allocates memory for an array of length number of components. This will store the size of the components.

6. For each component, the program asks the user to enter the type of component and the value of that component. When asking for the size, the correct units must be shown (Ohms, Farads and Henrys).

a. The storing of the component types and values must be done using pointer arithmetic in this section. (Refer to lab 6 and additional material)

b. You can assume the user enters valid values components (1,2 or 3) and their values (positive values)

2311_figure2.jpg

7. Calculate the impedance values by calling the calculate_impedance function. (Described in section below)

8. Calculate the total current values for both the real and imaginary parts and store appropriately (Ohms law I=V/Z)

9. Calculate the voltages and currents of all components, and store appropriately. (Hint. Refer to background information - Ohms Law. Parallel and series will have different equations)

10. Call the print_results function to print out the results table (Described in section below)

11. End the program appropriately.

FUNCTION - CALCULATE_ IMPEDANCE

1. Calculate the impedance for both real and imaginary part for each component using a for loop with an if, else-if, else statement in the loop. And store the results in the results_table (Hint. Refer to background information - Impedance. Resistors, Capacitors and Inductors have different equations)
2. Calculate the total impedance for both real and Imaginary parts. And store the results in the results_table (Refer to additional material if new to summation)
a. Hint: (One possible implementation)
i. Create temporary variables to store the current sum (for both complex and real parts) and initialize to 0.
ii. Create variables to store the total impedance (both for complex and real parts).
iii. Then if the circuit is series:
1. Iteratively add to these for each impedance values.
2. The sum is the total impedance
iv. else if the circuit is parallel:
1. Create a set of temporary variables for the result of the division
2. Iterate through the component values starting from the first component:
i. Divide 1+0j by the components impedance value and store the result appropriately, then add this result to the current sum.

3. Divide 1+0j by the total sum to give the total impedance.
v. Store the total impedance values in the appropriate place in the result table.

FUNCTION - PRINT_ RESULTS

1. Print the result table as shown below:
a. The first column describes the rows with the text
"COMPONENTS","Z ( Ohms)","I ( Amps)","V (Volts)".

b. The first row prints the components as ‘R' for resistor, ‘C' for capacitor and ‘I' for inductor.
c. The second row prints the impedance, the third the current and the fourth the voltage
i. The real part is printed in brackets in exponential format with sign and 3 decimal places. Then the ‘+' character. Then the imaginary part is printed in brackets in exponential format with sign and 3 decimal places. Then the ‘j' character.

CONSTRAINTS

- Pi needs to be to 11 decimal places in your program.
- Formatting needs to be exactly as specified. (Your program will be tested against automated test cases)
- Text to user needs to be easily understandable. You can change the text but the same inputs must be used.
- The program must print your student number, name and the assignment number as specified.
- Types should be used appropriately.
- You must use comments to explain significant lines of code.
- You must use comments to explain how to use the functions and solution

Attachment:- Assignment-2.pdf

Reference no: EM131472974

Questions Cloud

What should wilson focus on in the profile : Chris Wilson is conducting a situational profile of James Cho, her client. What should Wilson focus on in the profile?
Develop a plan for assessing it security : Identify the critical requirements of the audit for your chosen organization and explain why you consider them to be critical requirements.
Define the traditional financial models : Explain three constraints that may be more relevant to individual investors than to institutional investors.
Present value of the interest tax shields : What is the present value of the interest tax shields from this? debt?
Create a program that allows a user to view the voltage : CSE1PES: PROGRAMMING FOR ENGINEERS AND SCIENTISTS - create a program that allows a user to view the voltage, current and impedance
Prove given syllogisms valid first using natural deduction : Prove the following syllogisms valid first using natural deduction and then using the method of tableaux. These may also be proven using the method of tableaux.
What is the foundations time horizon : The Fisher Foundation was established by the estate of a wealthy industrial tycoon. Its sole purpose is to provide grants to improve literacy in low-income.
Find a franchisee breakeven sales in dollars : BUSAC 187-5651 RESEARCH PROJECT 2. Owner Li Soo is considering franchising her Happy Noodles restaurant concept. Find a franchisee's breakeven sales in dollars
Pay raises everyday-how do you feel when you get raise : How do you feel when you get a raise? Happy? Rewarded? Do you think frequent, small raises versus annual, larger raises is more motivating? Why or why not?

Reviews

len1472974

4/25/2017 1:37:53 AM

Are variables named appropriately? 0 Variables are named poorly. 1 Variables are named suitably for the code. 2 Variables are named suitably for the code and the domain. Are appropriate variable types used where appropriate? 0 All variables are declared as the largest types 1 Some types are not suitable. 2 All variable types are suitable.

len1472974

4/25/2017 1:37:41 AM

Is malloc used appropriately 0 Malloc is not used 2 Malloc is used incorrectly 4 Malloc is used appropriately Is pointer arithmetic used appropriately 0 Pointer arithmetic is not used 2 Pointer arithmetic is used incorrectly 4 Pointer arithmetic is used appropriately Are pointers used appropriately 0 Pointers are not used 2 Pointers are used incorrectly 4 Pointers are used appropriately Are functions used appropriately 0 Functions are not used 2 Functions are used incorrectly 4 Functions are used appropriately Is the code correctly indented? 0 The code is not indented. 1 Some errors in indenting. 2 Code is indented appropriately.

len1472974

4/25/2017 1:37:30 AM

Is the formatting of the table correct? 0 The tables do not use any formatting. 4 The tables are formatted but incorrectly. 6 Correct format specifiers, spacing and new lines are used Is the impedance calculated correctly 0 The impedance is not calculated correctly 4 The impedance for each component is calculated correctly, but not the total for both series and parallel. 9 Total impedance and impedance for each component is calculated correctly for both series and parrallel. Is the current calculated correctly 0 The current is not calculated correctly. 4 Total current or current of each component is calculated correctly for both series and parallel. 6 Total current and current of each component is calculated correctly for both series and parrallel. Is the voltage calculated correctly 0 The current is not calculated correctly. 4 Voltage of each component is calculated correctly for both series and parallel. 6 Total voltage and voltage of each component is calculated correctly for both series and parrallel.

len1472974

4/25/2017 1:37:19 AM

Is the student’s number, student name and assignment number printed? ACADEMIC INTEGRITY If the names are different 0 Incorrectly formatted 1 Correctly formatted Does the program compile? 0 Does not compile. 4 Compiles with warnings. 8 Compiles appropriately. Is the logic of the code appropriate? 0 The code logic does not match the problem. 2 Some small errors in interpreting the problem. 4 The logic is suitable for the problem. Are the inputs and outputs understandable? 0 Does not accept inputs correctly or does not output data appropriately. 2 Some errors in outputs. 4 Inputs and outputs are handled appropriately. Suitable comments are used to explain particular blocks or lines of code. 0 No comments 4 Reasonable comments used throughout. 8 Excellent descriptions and commenting.

len1472974

4/25/2017 1:37:06 AM

Since it is a C Programming assignment, there is no word limit. Although, the lecturer has stated that, there should be roughly between 150-200 lines of coding. Need to add comments to almost every line as well or wherever a new type of code is implemented. A new Express request is submitted

Write a Review

C/C++ Programming Questions & Answers

  Create a program that will input a group of floating point

Create a program that will input a group of floating point values, storing them as double values in an array. This array will then be sent to three functions.

  Write a short c++ function

Write a short C++ function, isMultiple, that takes two positive long values, n and m, and returns true if and only if n is a multiple of m, that is, n = mi for some integer i.

  Implement the value iteration algorithm for mdp

CSCI924/CSCI424 - Reasoning and Learning - Implement the value iteration algorithm for MDP which computes the solution to the situation. You may write your code in either C or C++. Your code must be implemented as a self-contained single source co..

  C write a function which adds the two numbers

1. In C write a function which adds the two numbers. Test this function by calling from the main. In main, the user should be asked to provide the two numbers.

  Write a program to display the given pattern on the screen

Write a program to accept number of lines (n) from the user and display the given pattern on the screen. 1 232 34543 4567654 567898765

  Write a program that requires the number of bits

Write a program that requires the number of bits for the exponent and significant of a floating point representation, then requires two decimal real numbers and an operation, sum, subtraction or multiplication.

  Program that will input any four float values

You need to prepare a program to print the given output - write a program that will input any four float values where the four variables are declared in the 'main' function and perform

  Write a set of nested loops that display 10 rows

Write a set of nested loops that display 10 rows of # characters. There should be 15 # characters in each row.

  Print name on the screen

Write a C++ program to prompt the user to input her/his name and print name on the screen.

  Process creation

Write a C (or C++) program that can create a collection of processes (each with its base thread) when a user runs the program. Using the standard cmd prompt features, you can "launch" a process just by typing its name. I will need some way to provide..

  Code to implement a staque

Write a C++ code to implement a Staque. Since the data structure is all about inserting and deleting numbers, it would be a good option to use a linked list to implement Staque.

  Find the amount in the savings act each month

Suppose you start with $1000 and each month you contribute $100. suppose that the interest rate is 6%per year compounding monthy,which is equal to 0.5% each month.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd