Programing I Sample
Programing I Sample
Exercise 1: (5 points)
1. Write a program to calculate the sum as the expression with the given value n: (2 points)
𝑛"1
1
𝑆𝑢𝑚 = %
𝑛
1
2. Write a program to solve equation as follows: (3 points)
𝑎𝑥1 − 𝑏𝑥$ = 1
(𝑎𝑥1 + 𝑏𝑥$ = 0
Given values of a and b from input, find x1 and x2
Exercise 2: (5 points)
Suppose you are developing a program to manage students’ marks of 4 subjects.
The information of a students is described as follows:
struct students{
char name[30];
char[10] class;
float average;
};
The records of the students list are stored in a file named “students.dat”.
Write the program that has the interface as follows:
Please choose:
1. Insert students records to the database.
2. Read all students information from database
3. Print/show information of all students
4. Ranking of students based on the average.
5. Calculate the Average mark of all students of a given class name.
0. Exit
When the user chooses:
0. The program will exit. (0.5 point)
1. The program will require the user to prompt information of student such as: name, class and
mark average. Then, all of the information will be stored to the database file name: students.dat.
(1.5 point)
2. The program will read all the file named “student.dat” and store in an array. (1 point)
3. The program will display all student information (each student information will be display on
a line) from the array. (0.5 point)
4. The array will be sorted descending and display to the output (1 point)
5. The program will require the user to enter a class name, then it will take the average mark of
all students in that class and print it out. (1.5 point)