What's the estimation for this
1 CSE1PES: PROGRAMMING FOR ENGINEERS AND SCIENTISTS ASSIGNMENT 2 (10%) Assignment developed by Matthew Felicetti 2016, updated 2017(MF), updated 2018(MF), updated 2019(MF) TOOLS • Unix server through Putty for compiling and testing • Notepad ++ for writing solutions • LMS for submission SUBMISSION o Three files .c file in the normal assignment submission portal. (Do not submit the executable.) ac_calculator_part1.c ac_calculator_part2.c ac_calculator_part3.c o There is NO late submissions for this assignment. o Requests for extensions, need to be sent by email: Doctors certificates need to cover a period greater than 3 days, and not submitted less than 3 days before the assignment is due. Special consideration will be rejected due to the assignment being worth less than 15%. ACADEMIC INTEGRITY Plagiarism is the submission of somebody else’s work in a manner that gives the impression that the work is your own. For individual assignments, plagiarism includes the case where two or more students work collaboratively on the assignment. The School of Engineering and Mathematics treats plagiarism very seriously. When it is detected, penalties are strictly imposed. http://www.latrobe.edu.au/students/academic-integrity http://www.latrobe.edu.au/students/academic-integrity 2 NOTE This assignment is broken up into 3 parts. Each subsequent part uses the previous part adding new functionality, however each must be submitted. This ensures that if an earlier part works, you will get the marks based on the working code. Please be careful not to overwrite your previous parts, if you do you need to go back and remove the subsequent section Each should have a unique comment description at the top of the code explaining what it does relating to the domain. Only code that compiles will be marked, comment out or remove sections that do not compile if you want to still be marked on the other sections. 3 IMPEDANCE, VOLTAGE AND CURRENT CALCULATOR FOR SIMPLE AC CIRCUIT BACKGROUND An Alternating Current (AC) circuit is one in which the output of the voltage source changes with time. When we add components to the circuit, the voltage and current will be different at different points in the circuit. The components we will be looking at are resistors, capacitors and inductors. Further information can be found here: https://en.wikipedia.org/wiki/Alternating_current, https://en.wikipedia.org/wiki/Inductor, https://en.wikipedia.org/wiki/Resistor, https://en.wikipedia.org/wiki/Capacitor. Impedance is the measure of the resistance and reactance of a component or circuit. Resistance is a measure of friction against the motion of electrons, whereas reactance is the inertia against the motion of electrons. Impedance introduces a phase shift between the voltage and current through a component, and hence is expressed as a complex number. Do not worry too much if this doesn't make sense, you can just think of this as complex resistance. For further information, please read https://en.wikipedia.org/wiki/Electrical_impedance. To calculate the impedance, voltage and current for each component in the circuit, we can use ohms law. The equation for ohms law is as follows: (Note we are dealing with complex numbers, however we will develop all the necessary functions you will need in lab 5) ?? = ?? ∗ ?? , ?? = ?? ?? ,?? = ?? ?? Where V, I and Z represent voltage, current and impedance respectively, and are measured in volts, amps and ohms respectively. For series circuits the current is the same through all components. For parallel circuits the voltage is the same through all components. The impedance calculation depends on the component. Details are as follows: Resistors: The impedance for a resistor can be found as: ?? = ?? where R is the resistance measured in ohms. Capacitors: The impedance for a capacitor can be found as: ???? = 1 2∗??∗??∗?? where C is the capacitance measured in Farads and f is the frequency measured in hertz ?? = 0 − ?? ∗ ???? where ???? is the reactance and j is the imaginary unit. Inductors: The impedance for an inductor can be found as: ???? = 2 ∗ ?? ∗ ?? ∗ ?? where L is the inductance measured in Henrys ?? = 0 + ?? ∗ ???? where ???? is the reactance and j is the imaginary unit. 4 Components will either be arranged in parallel or series. Depending on this, the total impedance calculation will vary. Total impedance in Series The total impedance between two components in series is: ???? = ??1 + ??2 If we have three components in series, then the total impedance is: ????2 = ???? + ??3 Hence, generalizing this we get: ???? = �???? ?? ??=1 Total impedance in Parallel The total impedance between two components in parallel is: ???? = � 1 ??1 + 1 ??2 � −1 Which we can then extend to calculate for three components by: ????2 = � 1 ???? + 1 ??3 � −1 Hence, generalizing this we get: ???? = �� 1 ???? ?? ??=1 � −1 5 PROBLEM – 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: A worked example of the math can be found here: https://lms.latrobe.edu.au/mod/page/view.php?id=3378968 Example outputs can be found here: https://lms.latrobe.edu.au/mod/page/view.php?id=3249426 MAKE SURE YOU UNDERSTAND THE WORKED EXAMPLE BEFORE STARTING ANYTHING YOU DO NOT UNDERSTAND IN THE MATH PUT ON THE FORUM The file should be named: ac_calculator_part1.c FUNCTION PROTOTYPES AND INCLUDES – PART 1 6 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: 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 – 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: https://lms.latrobe.edu.au/mod/page/view.php?id=3378971 (This must be included to be awarded marks in the assignment) 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. https://lms.latrobe.edu.au/mod/page/view.php?id=3378971 7 4. The program creates the following 2 pointers to doubles variables (These combined form the result table) a. 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) 0 1 … number of components -1 number of components result_table_impedance_real 0 Impedance component 1 – Real part Impedance component 2 – Real part … Impedance component n – Real part Total Impedance - Real part result_table_impedance_imag 1 Impedance component 1 – Imaginary part Impedance component 2 – Imaginary part … Impedance component n – Imaginary part Total Impedance - Imaginary part 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). 8 FUNCTION - CALCULATE_IMPEDANCE – PART 1 (Hint. Refer to background information – Impedance. Resistors, Capacitors and Inductors have different equations) 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 b. Else if component i is a capacitor Then impedance real i is 0 and impedance imaginary i is −???? (Hint. Refer to background information on page 2) Store the calculated impedance of the component in the results_table_impedance_real and results_table_impedance_imag in the i’th position c. Else if component i is an inductor: Then impedance real i is 0 and impedance imaginary i is ???? (Hint. Refer to background information on page 2) Store the calculated impedance of the component in the results_table_impedance_real and results_table_impedance_imag in the i’th position