Department of Electrical Engineering and ElectronicsIntroduction toProgramming in C(ELEC129)Assignment 2Introduction to Programming in C (ELEC129) Assignment 2Dept. Electrical Eng. & Electronics Page 2 / 5 University of LiverpoolObjectivesTo design, implement and document simple modular programs that use functions and loops.AssessmentThis assignment is an assessed component and the mark for this work will contribute towardsthe overall module mark. The weight of Assignment 2 is 22%. The marking criteria can befound in the Exam Resources section of ELEC129 in VITAL.This assignment is composed of a number of exercises. The relative weight of each exercise onthe overall assignment mark is indicated between brackets.InstructionsStudents are required to do all exercises and submit a single Word file in the Assessmentsection of ELEC129 in VITAL (https://vital.liv.ac.uk) by Tuesday 10/12/2018 at 17:00 (5pm) UKlocal time (week 12 of semester 1). Delay penalties apply. Please double check your report andmake sure your work is in its final form before submission as the online application will notallow resubmissions. Email submissions and/or resubmissions will not be accepted.Submissions must be a single Word file containing the work done by the student (studentname and student ID should be clearly stated in the first page). The file must contain twoparts for each exercise proposed in this assignment as detailed below.Part I: The first part must contain the source code. Please use font Courier New with a size of 8points, use indentation to make the code readable, and observe the following requirements: The source code must be the result of your own original and individual work. The source code must be entirely written in the C programming language. Source codewritten in any other programming languages (e.g., C++) will receive a mark of zero. The use of global variables is (in general) not needed in ELEC129 assignments and itsuse is not allowed unless otherwise stated. All variables should be local to a function(i.e., declared within the body of a function). The use of global variables will bepenalised. If you are in doubt, ask a lab demonstrator to check your source code. All exercises can be solved based on concepts explained in previous lectures. Studentsare allowed to use concepts from other (future) chapters but this is not expected. Feelfree to discuss your approach to solving the exercises with a lab demonstrator.Part II: The second part must contain a detailed explanation of the software developmentprocess followed by the student (i.e., the first five steps of the software development method):1. Problem specification: Formulation of the problem and its objectives.2. Analysis: Identification of: i) inputs, ii) outputs, and iii) other relevant aspects,requirements or constraints (e.g., relevant formulas, etc.).3. Design: Formulation of the algorithm (list of steps) needed to solve the problem. Atthis stage, the problem should be divided into a number of sub-problems that can besolved using functions.Introduction to Programming in C (ELEC129) Assignment 2Dept. Electrical Eng. & Electronics Page 3 / 5 University of Liverpool4. Implementation: List of functions used in the program (function names), indicating foreach function which step(s) of the algorithm is/are implemented by the function.5. Testing and verification: Explanation of how the program was tested and verified.Snapshots of the programs output window can be obtained by using [Alt] + [PrtScr(orPrintScreen)] and pasting into the report.Please indicate clearly if in your opinion the program works correctly. If you do not think theprogram works correctly or does not compile, indicate what the problems are. You will then beable to get points for that programming task. If in the testing section of your design documentyou have indicated that the program works correctly but it turns out that your code does noteven compile (because of syntax errors, for example) you will not receive adequate points.Academic integrityStudents should familiarise themselves with Section 6 of the University’s Code of Practice onAssessment, which provides important information regarding the submission of assessedcoursework (link: http://www.liv.ac.uk/tqsd/code-of-practice-on-assessment).Students should also familiarise themselves with Section 9 (Academic Integrity) and Appendix L(Academic Integrity Policy) of the University’s Code of Practice on Assessment which providethe definitions of academic malpractice and the policies and procedures that apply to theinvestigation of alleged incidents (including collusion, plagiarism, fabrication of data, etc.).Students found to have committed academic malpractice are liable to receive a mark of zerofor the assessment or the module concerned. Unfair and dishonest academic practice willattract more severe penalties, including possible suspension or termination of studies.By electronically submitting this coursework you confirm that: You have read and understood the University’s Academic Integrity Policy. You have acted honestly, ethically and professionally in conduct leading to assessmentfor the programme of study. You have not copied material from another source nor committed plagiarism norfabricated data when completing the attached piece of work. You have not previously presented the work or part thereof for assessment foranother University of Liverpool module. You have not coELEC129作业代写、代做C/C++程序语言作业、代写Electrical Engineering作业、C/C++课程pied material from another source, nor colluded with any otherstudent in the preparation and production of this work. You have not incorporated into this assignment material that has been submitted byyou or any other person in support of a successful application for a degree of this orany other University or degree awarding body.Students are encouraged to contact the module instructor if any clarifications are needed.Introduction to Programming in C (ELEC129) Assignment 2Dept. Electrical Eng. & Electronics Page 4 / 5 University of LiverpoolExercise 1 (20% of assignment mark)Write a program that calculates the equivalent resistance of a circuit. n electrical resistors withresistance values R1, R2, …, Rn are said to be connected in parallel if the same voltage is appliedacross each. Their equivalent resistance Req is related to the values R1, R2, …, Rn by:Req R R Rn1...1 1 11 2Write a program that prompts the user to enter the resistance of n resistors. The user shouldbe prompted continuously by using a while loop until a zero or negative value is entered (theprogram should count the number of resistors n entered by the user and store the values in anarray). Use another separate loop to print the resistance values entered by the user and theequivalent resistance Req. Test your program with R1 = 1 kΩ, R2 = 2 kΩ, R3 = 4 kΩ and R4 = 8 kΩ.Exercise 2 (40% of assignment mark)Write a program that calculates and prints bills for the city power company.The program should prompt the user to enter an account number (type unsigned int) anda use code (type char). Code R means residential use, code C means commercial use andcode I means industrial use. For valid codes, both lowercase and uppercase letters should beaccepted by the program (i.e., r or R for residential, c or C for commercial, and i or I forindustrial). The user should be prompted until a valid code is entered.Depending on the selected account type (use code), the user should then be prompted toprovide the consumption figures in whole numbers of kilowatts-hour (type unsigned int).The rates vary depending on whether the use is residential, commercial or industrial, and arecomputed in terms of used kilowatts-hour (kwh) as follows:Residential (code R): £4.00 plus £0.03 per kwh used.Commercial (code C): £40.00 for the first 1500 kwh and £0.02 for each additional kwh used.Industrial (code I): Rate varies depending on time of usage:- Peak hours: £53.00 for the first 1600 kwh£0.07 for each additional kwh- Off-peak hours: £32.00 for the first 1600 kwh£0.04 for each additional kwhThe program should then display the account number and the amount due by the user.The calculation of the amount due should be performed by three functions:1. residential(): Function that takes an input argument kwh of type unsigned intand returns the amount due as a value of type double. This function should be used tocompute the bill for residential customers.Introduction to Programming in C (ELEC129) Assignment 2Dept. Electrical Eng. & Electronics Page 5 / 5 University of Liverpool2. commercial(): Function that takes an input argument kwh of type unsigned int andreturns the amount due as a value of type double. This function should be used to computethe bill for commercial customers.3. industrial(): Function that takes two input arguments kwh_peak andkwh_off_peak of type unsigned int both and returns the amount due as a value oftype double. This function should be used to compute the bill for industrial customers.In the test part of your report, specify the results provided by your program for: i) residentialuse of 500 kwh, ii) commercial use of 1000 kwh; iii) commercial use of 2000 kwh; iv) industrialuse of 1000 kwh (peak hours) and 2000 kwh (off-peak hours).Exercise 3 (40% of assignment mark)Write a program that computes the solutions for a quadratic equation:02ax bx cRecall that the solutions can be real or complex numbers. The following cases may occur: a = b = 0: The equation is extremely degenerate and we leave it at that. a = 0: The equation is degenerate and has one solution x = –c/b. a ≠ 0: The equation has two solutions, which can be either real or complex numbers,depending on whether the expression b2–4ac is positive or negative.o b2–4ac > 0: The solutions are real numbers.o b2–4ac o b2–4ac = 0: The equation has two identical (multiple) real solutions.The solutions/roots can be calculated with the following equations:ab b acxab b acWrite a program that reads the values for a, b and c and finds the solutions for the equation.For each set of values (a, b, c), your program should print the equation type (extremelydegenerate, degenerate, two real solutions, two complex solutions or multiple real solutions)along with the solution(s)/root(s) for the quadratic equation. For full marks you should usefunctions where possible. Marks will also be awarded for program structure.In the test part of your report, specify the results provided by your program for: i) a = 0, b = 0,c = 5; ii) a = 0, b = 4, c = 3; iii) a = 1, b = 4, c = 3; iv) a = 2, b = 4, c = 3; v) a = 2, b = 4, c = 2.NOTE: You need to include the math.h header file in your program in order to use thesqrt() function, which calculates the square root of a positive real number. The functionprototype is declared in math.h as follows:double sqrt(double);转自:http://ass.3daixie.com/2018121327928139.html