You are on page 1of 2

Object oriented programming language using C++

Final examination. Code: 1


May 31th 2016
Student name
Time limit: 120 minutes
Student ID
Note: You are not allowed to use textbooks or notes or anything else besides your brain.

1. (5 points) Write a program with a menu:


1. Find the sum of digits in a positive integer: press 1.
2. Exit: press 2.
Operation of the program:
If a user enters 1:
Ask the user to input a positive integer N .
Print out on the screen: the sum of digits in N .
Repeat until the user press 2.
If the user enters 2: close the program.
If the user enter other strings: ask him/her to re-input.
2. (5 points) Create a class named student with 3 string attributes: name, age, f aculty
and an integer attribute GP A. The class student includes the following methods:
A constructor with 3 string parameters: initialize a student-object with particular
values for its 3 attributes: name, age and f aculty.
A virtual method named GP A input to input a GP A value: input a number from
0 to 100 (by keyboard).
A virtual method named GP A check 1 to check if a GP A is good or not good.
A GP A value is considered good if it is greater than 80, and not good otherwise.
Create a class named hnue student inherited from the class student with additional
string attribute class name. Methods of hnue student include:
A constructor with 4 parameters: initialize a hnue student-object with particular values for its 4 attributes: name, age, class name and f aculty. It calls the
constructor of the class student.
A redefined method GP A input to input GP A: input a number from 0 to 10 (by
keyboard).
A redefined method GP A check to check if a GP A is good or not good. A
GP A value is considered good if it is greater than 8, and not good otherwise.
1

GP A check can be written in 1 in 2 ways: (1) return a string (good/not good) or (2) return a
boolean value (true if it is good, false otherwise)

Final examination. Code: 1 - Page 2 of 2

May 31th 2016

Create a class named hust student inherited from the class student with additional
string attribute school. Methods of hust student include:
A constructor with 4 string parameters: initialize a hust student-object with particular values for its 4 attributes: name, age, school and f aculty. It calls the
constructor of the class student.
A redefined method GP A input to input a GP A value: input one character A, B,
C, D, E or F . If A is entered, assign 5 to GP A. Similarly, if B, C, D, E or F is
entered, assign 4, 3, 2, 1 or 0 to GP A, respectively.
A redefined method GP A check to check if a GP A is good or not good. A
GP A is considered good if it is equal to A or B 2 , and not good otherwise.
Operation of the function main:
Create an array of 10 student pointers.
For each pointer:
Ask users to enter a number 0 or 1, corresponds to hnue student or hust student.
Ask users to enter values for the attributes of a hnue student object(or hust student
object) to temporary variables.
Based on the information entered, initialize an object.
Use f or loops to:
Ask users to enter GP A of 10 student objects.
Print out on the screen the names of 10 students and his/her GP A classification
(good or not good).

you have to compare GP A with integer values 0, 1, 2, 3, 4 and 5

You might also like