Programming for Engineers (2020/2021)
C Programming Assignment
Instructions
1) Design and write one C program for all the problems, submit only one C source code file.
2) Write a report which includes your commented C code, screenshots of test results for each problem (run your code and show results), and flowcharts for problems 1 and 3 respectively. You must prepare your report in a Word document, and submit the report as one pdf file.
3) Commented C source code file and the report should be submitted online. Check the deadline on Canvas.
Problems
The objective for the Main Project is to program a menu driven system that will give user a choice of the 6 options as follows.
1) Ask user to enter your student candidate number, calculate the sum of the digits. If the sum is less than 20, display the sum to the power of 2, otherwise display the square root of the sum. If the sum equals to 25, display this sum as well. (15 Marks)
2) Calculate the roots of a quadratic equation ????2 + ???? + ?? = 0, when ??2 ? 4???? ? 0. Ask user to enter the values a, b and c, the program then calculates and displays the roots by calling a function. (Must use a user defined function). (15 Marks)
3) Prompt user for entering two integers a and x and an exponent integer n, use a loop structure to calculate ??+????. If the result is greater than 2147483647, display a message that the result is out of the value range of integer. (15 Marks)
4) Ask user to enter the following array data, then prompt the user to enter 18 to replace the last element in the array. Finally, calculate and display the product of all the data in the updated array.
12 22
38 40
11 33
(15 Marks)
5) Prompt user for entering any five numbers, find the minimum and maximum numbers among the five numbers using pointer variables. (15 Marks)
2
6) Load the data file (data.txt) which is given below into an array. Display an error message if the file cannot be opened. Design C codes to find the maximum value, count the number of positive values and the number of odd values. (25 Marks)
data.txt (Note: you need to create and save the data file, a, b, c, d, e and f are from your candidate numbers, for example, if your candidate number is 184579 then a=1, b=8, c=4, d=5, e=7 and d=9).
a
b
c
5
14
6
-7
-19
21
-3
0
37
10
-31
34
-37
-9
d
e
f
Recent Comments