Cse1pes programming for engineers and scientists - create a


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

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: Cse1pes programming for engineers and scientists - create a
Reference No:- TGS02268540

Expected delivery within 24 Hours