program讲解 、C/C++语言程序辅导
Page 1 of 3
Fundamentals of Programming
Individual Assignment
Instructions
1. Answer all questions.
2. Each question must be solved by a function, and called from the main() function.
3. Any relevant standard C functions provided by the C compiler can be used.
4. Submit only one source (.c) file to Blackboard before the deadline. Check the deadline on the
Blackboard module page.
5. The individual assignment will contribute to your overall assignment coursework marks.
Marks Allocation
Question Marks
Q1 3
Q2 3
Q3 4
Q4 4
Q5 6
Total 20
Marking Scheme
No. Item Q1 Q2 Q3 Q4 Q5
1 Source code compiles without errors. 1 1 1 1 1
2 Source code meets specifications. 1 1 1 1 1
3 Source code outputs expected results to screen
(with the necessary numerical precision).
1 1 1 1 1
4 Source code reads and correctly processes
argument(s) and/or external data.
- - - - 0.5 0.5 0.5
5 Source code uses appropriate library functions. - - - - 0.5 0.5 0.5
6 Source code processes data using efficient
method(s), such as pointers, loops, etc.
- - - - - - - - 1
7 Source code contains error checking and/or
input validation feature(s).
- - - - - - - - 1
TOTAL 3 3 4 4 6
Academic Misconduct Notice
PSB Academy takes cases of academic misconduct involving plagiarism and cheating very seriously.
Plagiarism is taking work made by someone else as your own. Academic cheating is subverting the
coursework or examination process for your own benefit.
Students are required to conduct themselves honourably in their academic work. Any
evidence of plagiarism will be penalised, which is not limited to the student receiving a failing grade.
Refer to the latest Student Handbook regarding the issue of Academic Misconduct.
Page 2 of 3
Question 1
Create a function called CalcAverage() that will process a local array of 12 integers, and prints the
average result to the terminal screen. The average has to be a float value and limited to 2 d.p.
For example, if the integer values 2, 3, 6, 13, 8, 4, 9, 5, 11, 7, 19, 26 were used, the average is 9.42.
Question 2
Create the function CalcCentroid() that determines the centroid of a trapezoid with three (3) float
values (a, b, h) provided by the user. The function must print the result to the terminal screen. Ensure
that the result is limited to 4 d.p.
Centroid = + 2
3( + )
ℎ
where h = height of trapezoid, and a, b = length of parallel sides.
For example,
Enter value a: 5
Enter value b: 8
Enter value h: 7
Centroid = 3.2308
Question 3
Create a function named CountChar() that accepts a string array as an argument, and determines total
number of letters, number of digits, and special characters. The function will then print the result to
the terminal screen.
For example,
Function usage Expected result
CountChar("Hell0 WorlD*@;5689");
Letters = 9
Digits = 5
Specials = 4
Question 4
Create the function ConvertStr() that will read a string array argument, and print only vowels (a, e, i,
o, u, A, E, I, O, U), numbers and special characters to the terminal screen. Consonants (non-vowel
letters) and whitespaces are not to be printed.
For example,
Function usage Expected result
ConvertStr("Good Evening_120%"); ooEei_120%
Page 3 of 3
Question 5
Create a function called ProcData() that accepts two arguments, an int value and an int array, in order
to process data in the x[] array containing 104 integer values as shown below. The x[] array must be
declared in the main() function, then passed into the ProcData() function. An integer pointer may be
used in the ProcData() function to operate on the int array argument. Output the result to the terminal
screen.
• If int value argument is 1, the function determines the total of odd values in the int array.
• If int value argument is 2, the function determines the total of even values in the int array.
• If int value argument is 3, the function determines the total of positive values in the int array.
• If int value argument is 4, the function determinesthe total of negative valuesin the int array.
Copy and paste the x[] array into the main() function as a local array:
int x[104] = {
79, -72, 66, 30, -0, 39, 45, -82, 32, -17, -34,
84, 44, 30, -97, -87, 61, 23, 19, -50, 3,
-9, 42, -52, 86, 68, -69, -90, 8, -48, -84,
8, -51, 55, 3, 20, 85, 45, 0, -13, 65, 66,
70, 12, -89, 97, 68, -53, -91, 83, 58, -81,
-62, 91, 98, -3, -56, 49, -68, -79, 92, 76,
17, -20, 0, 45, -71, -5, 39, 72, 67, 77, -34,
70, -11, 98, -70, 48, -39, 84, -21, -17, -54,
-59, -37, 23, -28, 46, 83, -90, 22, -51, 69,
80, 51, -80, -0, 68, -60, 76, 9, 47, 55, -50
};
END OF INDIVIDUAL ASSIGNMENT