# CSE1PES | Programming for Engineers and Scientists | Engineering

Home Recent Questions CSE1PES | Programming for Engineers and Scientists | Engineering

PROBL EM – PART 1

You are to create a program that allows a user to view the impedance for each component and the total in a series circuit. The program will ask the user for the the frequency, the number of components, and the values of each component. A generic example circuit is shown below:

FUNCTION PROTOTYPES AND INCLUDES – PART 1

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

FUNCTION – MAIN – PART 1

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. (This must be included to be awarded marks in the assignment)
2.Include the line of code found here after printing the above:
3.The program asks the user the frequency in hertz and the number of components. And stores the results appropriately. All of these values are positive integers.
a.  You can assume the user enters ANY valid values for frequency and number of components.4.The program creates the following 2 pointers to doubles variables (These combined form the result table)
b.Then dynamically allocate memory (malloc) for each of the pointers as an array of size sizeof(double) *(number of components + 1) (The +1 is for the total)

5.The program dynamically allocates memory for an array of ints of length number of components, and an appropriate pointer is created named components which points to the start of the array. This will store the component types.

6.The program dynamically allocates memory for an array of doubles of length number of component, and an appropriate pointer named values is created which points to the start of the array. This will store the size of each of the components.

7.For each component (hint. for loop), the program asks the user to enter the type of component and the value of that component and stores the types and values. When asking for the size, the correct units must be shown (Ohms, Farads and Henrys).
a.  You can assume the user enters ANY valid values components (1,2 or 3) and their values (positive values)

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

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

10.End the program appropriately (hint. free).

FUNCTION - CALCULATE_IMPEDANCE – PART 1

1.Calculate the impedance for both real and imaginary part for each component using a for loop where i is the index of the component in the array: a. If component i is a resistor:

Then impedance real i is the size of the component and impedance imaginary i is 0
Store the calculated impedance of the component in the results_table_impedance_real and results_table_impedance_imag in the i’th position

2.Calculate the total impedance for both real and Imaginary parts. And store the results in the results_table_impedance_real and results_table_impedance_imag (Refer to additional material if new to summation)

a.Create 2 temporary variables to store the current sum (for both complex and real parts) and initialize to 0.

i.Iteratively add all the real parts to current sum real to give the total real part
ii.Iteratively add all the imaginary parts to current sum imaginary to give the total imaginary part

b.Store the total impedance values in the appropriate place (at the end) in the 2 result tables.

FUNCTION - PRINT_RESULTS – PART 1

1.Print the result table as shown below:

a.The first column describes the rows with the text “COMPONENTS”,”Z ( Ohms)”
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

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.

PROBLEM – PART 2

You are to create a program that allows a user to view the 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 frequency, the number of components, and the values of each component. The two generic example circuits are shown below:

FUNCTION PROTOTYPES – PART 2

1.Modify the calculate_impedance prototype and in turn the function to include the choice parameter as shown below

FUNCTION – MAIN – PART 2

1.Modify step 2 of main from part 1, such that:

a.The program also asks the user firstly which circuit they want to evaluate (this is ‘choice’)

b.Further, now when asking for the number of components, the type of circuit should be specified as shown below.

2.Modify step 7 of main from part 1, such that the function is called appropriately with the changes.

FUNCTION – CALCULATE _IMPEDANCE – PART 2

1.Modify step 2 such that:

a.Calculate the total impedance for both real and Imaginary parts. And store the results in the results_table_impedance_real and results_table_impedance_imag

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 imaginary and real parts).
iii.Then if the circuit is series:

1.Iteratively add all the real parts to give the total real part (This is the same as before)

2.Iteratively add all the imaginary parts to give the total real part (This is the same as before)

iv.else if the circuit is parallel:

1.Create 2 temporary variables for the result of the division (real and imaginary)

2.Iterate through the component values starting from the first component:

a.Divide 1+0j by the components impedance value and store the result appropriately

b.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 – PART 2

PROBLEM – PART 3

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:

FUNCTION PROTOTYPES – PART 3

1.Modify the print_results prototype and in turn the function as shown below

FUNCTION – MAIN – PART 3

1.The program now also should ask the user for the source voltage as shown below

2.Modify step 3 of part 1 such that:

a.The program creates the following 6 pointers to doubles variables (These combined forms the result table) (The first two where created in part 1)
b.Then dynamically allocate memory (malloc) for each of the pointers as an array of size sizeof(double) *(number of components + 1) (The +1 is for the total)
c.Then the program stores the source voltage in the array as shown below

3.After step 7 of part 1 add:

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

(You have the total impedance for both real and imaginary, and the total voltage both real and imaginary. Hint. use the complex_division function)

b.Calculate the voltages and currents of all components, and store appropriately.

4.Modify your call to print_results based on the changes

5.End the program appropriately based on the changes

FUNCTION – CALCULATE _IMPEDANCE – PART 3

No modifications required to print_impedance for part 2

FUNCTION - PRINT_RESULTS – PART 3

1.Modify print_results from part 1 such that:

a.   Print the result table as shown below:

i.The first column describes the rows with the text “COMPONENTS”,”Z ( Ohms)”,”I ( Amps)”,”V (Volts)”.

ii.The first row prints the components as ‘R’ for resistor, ‘C’ for capacitor and ‘I’ for inductor.

iii.The second row prints the impedance, the third the current and the fourth the voltage

iv.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.

#### Latest Reviews

• ##### Kannon
13 Jul, 2019

I asked for essay help from Assignment Help 4 Me and I am happy that the essay writers completed my task on time. The prices they asked for are worth in comparison to the services rendered.

• ##### Liam
13 Jul, 2019

Assignment Help 4 Me is the best help provider. I took assistance to get my essay completed and I am glad that the writers delivered the quality content as they promised within the time committed.

• ##### Silas
12 Jul, 2019

Accounting is a very interesting subject but when it comes to assignment writing, I feel hard to get through the same. But, since the assignments have to be completed somehow, I preferred to avail online help from Assignment Help 4 Me. All thanks to them that they helped me complete my work on time at reasonable prices.