1 HCMC UNIVERSITY OF TECHNOLOGY AND EDUCATION Faculty for High Quality Training Program name:_ECET FINAL EXAMINATION SEMESTER 1 – ACADEMIC YEAR 2018-2019 Course name: C Programming L
Trang 11
HCMC UNIVERSITY OF
TECHNOLOGY AND EDUCATION
Faculty for High Quality Training
Program name:_ECET
FINAL EXAMINATION SEMESTER 1 – ACADEMIC YEAR 2018-2019 Course name: C Programming Language
Course ID: PRLA335164E Exam code: 01 Number of pages: 06
Duration: 90 minutes
Only used one A4-handwriting paper
Student writes answers directly in space reserved in exam paper and submit back all exam papers.
Signature of Proctor 1 Signature of Proctor 2
Marks / Signature
Signature of Marker 1 Signature of Marker 2
Student name:
Student ID:
Exam number: Exam room:
Question 1: (2.0/10) Give a following program, please perform:
#include "stdafx.h"
#include <stdio.h>
// function main begins program execution
int main(void)
{
unsigned int counter; // number of grade to be entered next
int grade; // grade value
int total; // sum of grades entered by user
int average; // average of grades
// initialization phase
total = 0; // initialize total
counter = 0; // initialize loop counter
// processing phase
while (counter < 5) { // loop 5 times
printf("%s", "Enter grade: "); // prompt for input scanf("%d", &grade); // read grade from user
total = total + grade; // add grade to total
counter = counter + 1; // increment counter
} // end while
// termination phase
average = total / counter; // integer division
printf("Class average is %d\n", average); // display result
} // end function main
a) Draw a flowchart?
b) Show contents on the screen after entering numbers as 6, 7, 8, 9, 10?
Trang 22
c) Rewrite this program using “do…while”?
d) Rewrite this program using “for”?
#
Trang 33
Question 2: (1.5/10) Show results on the screen after performing a following program:
#include <stdio.h>
void main()
{
int a[6] = { -2, -1, 0, 1, 2, 3};
int *p1 = &a[1];
int *p2 = &a[2];
*(p1 - 1) = 2**p2 - 4;
*p1 = *p2 + 3;
*p2 = *(p1 + 4) + *(p2 + 2);
++p2;
*(p2 + 2) = a[0] + ++a[1];
*(p2 + 1) = a[2] + a[3];
*p2 = *(p1 + 4) + *(p2 + 2) + 2;
printf("%d %d %d %d %d %d", a[0], a[1], a[2], a[3], a[4], a[5]);
}
Question 3: (1.5/10) Draw flowchart and write a complete program that calculates and prints the product of the odd integers from 1 to 9 Flowchart: Complete program: ………
………
………
………
………
………
………
………
………
………
………
………
………
………
………
………
………
………
………
………
………
Trang 44
………
………
………
………
………
………
Question 4: (3.0/10)
- Edit bugs of a following program (2.0 points):
The program
#include <stdio.h>
#include <conio.h>
#include <malloc.h>
int Check(int x)
void main(void)
{
int n, *a, i, flag, max;
printf("Input n:” );
scanf("%f", &n);
a = (int*)malloc(n, sizeof(int));
for (i = 0; i < n; i++)
scanf("%d", *(a + i));
flag = 1;
for (i = 0; i < n; i++)
if (Check(*(a + i)) == 0)
{
flag = 0;
break;
}
if (flag == 0)
printf("Error data );
else
{
max = a;
for (i = 1; i < n; i++)
if (max < *(a + i))
printf("The maximum number: %d", max);
}
}
Edit bugs
Trang 55
int Check(int x)
{
if (x >= 0 && *x <= 10)
return 1;
else
return 0;
}
- Assume that the above program is edited correctly, then
✓ When four numbers 3, 1, 3, 2 are inputted from the screen, what are results showed
on the screen next (0.5 point)?
✓ And for the case four numbers 3, 1, -3, 2 ? (0.5 point)
Question 5: (2.0/10) Write a complete program using dynamic memory allocation which executes functions as follows:
a) Create a structure type, named ENodeB, to describe a base station in the 4G mobile network The base stations will collect capacities and include information as follows:
✓ Base station name (named ENodeBname): string format
✓ Base station code (named ENodeBcode): integer number format
✓ Capacity value (named Capa): real number format
b) Enter information including name, code and capacity of N different base stations in which N
is entered from the keyboard (N>0)
c) Print all information of the base stations on the screen where their capacity values are larger than and equal 2.5
d) Print all information of the best base station on the screen which has the largest capacity value
#
Trang 66
Note: Proctors are not allowed to give any unauthorized explanation
Learning outcome mapping Assessed in
[LO 1.1, 1.3]: Draw a flowchart, demonstrate command syntax, operation
and application of branching and iteration structures in C language
Question 1, 3
[LO 1.5]: Present how the pointer is declared and how to use the pointer to
retrieve the memory
Question 2, 4, 5
[LO 1.7]: Define structure type and use structure variables to store and
manage data
Question 5
[LO 2.1, 3.1]: Analyze the programming requirements from which to
build a flowchart, a complete program; apply control structures, apply
data manipulation, build support functions to design and solve application
programming requirements
Questions 1, 3, 5
18/12/2018
Approved by program chair
(signed and named)