解析ELEC129 Programming in C
Posted 念花人伊人泪
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解析ELEC129 Programming in C相关的知识,希望对你有一定的参考价值。
目标
设计、实现和记录使用函数和循环的简单模块化程序。
评估
这项作业是一个评估部分,这项工作的分数将有助于
整体模块标记。作业 2 的权重为 22%。评分标准可以是
可在 VITAL 的 ELEC129 的考试资源部分找到。
这个作业由许多练习组成。每项运动的相对权重
总体分配标记显示在括号内。
指示
学生必须完成所有练习并在评估中提交一个 Word 文件
ELEC129 在 VITAL (https://vital.liv.ac.uk) 的部分,截至 2018 年 12 月 10 日星期二 17:00 (5pm) UK
当地时间(第 1 学期第 12 周)。延误罚款适用。请仔细检查您的报告并
请确保您的作品在提交前处于最终形式,因为在线申请不会
允许重新提交。不接受电子邮件提交和/或重新提交。
提交的文件必须是包含学生(学生
姓名和学生证应在第一页清楚注明)。该文件必须包含两个
本作业中提议的每个练习的部分,详述如下。
第一部分:第一部分必须包含源代码。请使用大小为 8 的 Courier New 字体
点,使用缩进使代码可读,并遵守以下要求:
源代码必须是您自己原创和个人工作的结果。
源代码必须完全用 C 编程语言编写。源代码
用任何其他编程语言(例如 C++)编写的将获得零分。
在 ELEC129 赋值及其中(通常)不需要使用全局变量
除非另有说明,否则不允许使用。所有变量都应该是函数的局部变量
(即,在函数体内声明)。全局变量的使用将是
受到处罚。如果您有疑问,请让实验室演示人员检查您的源代码。
所有练习都可以根据之前讲座中解释的概念来解决。学生们
允许使用其他(未来)章节中的概念,但这不是预期的。感觉
与实验室演示者自由讨论您解决练习的方法。
第二部分:第二部分必须包含软件开发的详细解释
学生遵循的过程(即软件开发方法的前五个步骤):
- 问题说明:问题及其目标的表述。
- 分析:识别:i) 输入,ii) 输出,以及 iii) 其他相关方面,
要求或约束(例如,相关公式等)。 - 设计:制定解决问题所需的算法(步骤列表)。在
这个阶段,问题应该分解成若干子问题
用函数解决。
Department of Electrical Engineering and Electronics
Introduction to
Programming in C
(ELEC129)
Assignment 2
Introduction to Programming in C (ELEC129) Assignment 2
Dept. Electrical Eng. & Electronics Page 2 / 5 University of Liverpool
Objectives
To design, implement and document simple modular programs that use functions and loops.
Assessment
This assignment is an assessed component and the mark for this work will contribute towards
the overall module mark. The weight of Assignment 2 is 22%. The marking criteria can be
found in the Exam Resources section of ELEC129 in VITAL.
This assignment is composed of a number of exercises. The relative weight of each exercise on
the overall assignment mark is indicated between brackets.
Instructions
Students are required to do all exercises and submit a single Word file in the Assessment
section of ELEC129 in VITAL (https://vital.liv.ac.uk) by Tuesday 10/12/2018 at 17:00 (5pm) UK
local time (week 12 of semester 1). Delay penalties apply. Please double check your report and
make sure your work is in its final form before submission as the online application will not
allow resubmissions. Email submissions and/or resubmissions will not be accepted.
Submissions must be a single Word file containing the work done by the student (student
name and student ID should be clearly stated in the first page). The file must contain two
parts 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 8
points, 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 code
written 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 its
use 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 be
penalised. 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. Students
are allowed to use concepts from other (future) chapters but this is not expected. Feel
free 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 development
process followed by the student (i.e., the first five steps of the software development method):
- Problem specification: Formulation of the problem and its objectives.
- Analysis: Identification of: i) inputs, ii) outputs, and iii) other relevant aspects,
requirements or constraints (e.g., relevant formulas, etc.). - Design: Formulation of the algorithm (list of steps) needed to solve the problem. At
this stage, the problem should be divided into a number of sub-problems that can be
solved using functions.
Introduction to Programming in C (ELEC129) Assignment 2
Dept. Electrical Eng. & Electronics Page 3 / 5 University of Liverpool - Implementation: List of functions used in the program (function names), indicating for
each function which step(s) of the algorithm is/are implemented by the function. - Testing and verification: Explanation of how the program was tested and verified.
Snapshots of the program\'s output window can be obtained by using [Alt] + [PrtScr(or
PrintScreen)] and pasting into the report.
Please indicate clearly if in your opinion the program works correctly. If you do not think the
program works correctly or does not compile, indicate what the problems are. You will then be
able to get points for that programming task. If in the testing section of your design document
you have indicated that the program works correctly but it turns out that your code does not
even compile (because of syntax errors, for example) you will not receive adequate points.
Academic integrity
Students should familiarise themselves with Section 6 of the University’s Code of Practice on
Assessment, which provides important information regarding the submission of assessed
coursework (link: http://www.liv.ac.uk/tqsd/cod...
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 provide
the definitions of academic malpractice and the policies and procedures that apply to the
investigation of alleged incidents (including collusion, plagiarism, fabrication of data, etc.).
Students found to have committed academic malpractice are liable to receive a mark of zero
for the assessment or the module concerned. Unfair and dishonest academic practice will
attract 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 assessment
for the programme of study.
You have not copied material from another source nor committed plagiarism nor
fabricated data when completing the attached piece of work.
You have not previously presented the work or part thereof for assessment for
another University of Liverpool module.
You have not copied material from another source, nor colluded with any other
student in the preparation and production of this work.
You have not incorporated into this assignment material that has been submitted by
you or any other person in support of a successful application for a degree of this or
any 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 2
Dept. Electrical Eng. & Electronics Page 4 / 5 University of Liverpool
Exercise 1 (20% of assignment mark)
Write a program that calculates the equivalent resistance of a circuit. n electrical resistors with
resistance values R1, R2, …, Rn are said to be connected in parallel if the same voltage is applied
across each. Their equivalent resistance Req is related to the values R1, R2, …, Rn by:
Req R R Rn
1
... - 1 1
- 2
Write a program that prompts the user to enter the resistance of n resistors. The user should
be prompted continuously by using a while loop until a zero or negative value is entered (the
program should count the number of resistors n entered by the user and store the values in an
array). Use another separate loop to print the resistance values entered by the user and the
equivalent 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) and
a use code (type char). Code R means residential use, code C means commercial use and
code I means industrial use. For valid codes, both lowercase and uppercase letters should be
accepted by the program (i.e., r or R for residential, c or C for commercial, and i or I for
industrial). 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 to
provide 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 are
computed 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 kwh
The 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: - residential(): Function that takes an input argument kwh of type unsigned int
and returns the amount due as a value of type double. This function should be used to
compute the bill for residential customers.
Introduction to Programming in C (ELEC129) Assignment 2
Dept. Electrical Eng. & Electronics Page 5 / 5 University of Liverpool - commercial(): Function that takes an input argument kwh of type unsigned int and
returns the amount due as a value of type double. This function should be used to compute
the bill for commercial customers. - industrial(): Function that takes two input arguments kwh_peak and
kwh_off_peak of type unsigned int both and returns the amount due as a value of
type 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) residential
use of 500 kwh, ii) commercial use of 1000 kwh; iii) commercial use of 2000 kwh; iv) industrial
use 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:
0
2
ax bx c
Recall 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 b
2
–4ac is positive or negative.
o b
2
–4ac > 0: The solutions are real numbers.
o b
2
–4ac < 0: The solutions are complex numbers.
o b
2
–4ac = 0: The equation has two identical (multiple) real solutions.
The solutions/roots can be calculated with the following equations:
a
b b ac
x
a
b b ac
Write 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 (extremely
degenerate, 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 use
functions 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 the
sqrt() function, which calculates the square root of a positive real number. The function
prototype is declared in math.h as follows:
double sqrt(double);
WX:codehelp
以上是关于解析ELEC129 Programming in C的主要内容,如果未能解决你的问题,请参考以下文章
Programming In hardware Programming in software
geeksforgeeks@ Maximum Index (Dynamic Programming)