You are on page 1of 3

COEN243

Assignment 1
Due date: October 2, 11:59PM

Fall 2016

Exercise 1
Factorial: Read an integer N from the user then display the factorial of this number, N!. Note
that, the factorial of a negative number is undefined. In case the user enters a negative number,
the program should notify the user and then ask him to enter a positive number instead.
Recall that, N! = N * (N-1)* (N-2)* * 2 * 1
Example:
Please enter a positive number: 6
The factorial of 6 is:
6! = 720

Exercise 2
Sum of first N: Read an integer N from the user then display the sum of the first N whole
numbers.
Example:
Please enter a positive number: 6
The sum of first 6 integers is: 21

Exercise 3
Cash Register:
1.
Ask the user to enter the total amount (in CAD) of the purchased items.
2.
Ask the user to enter the total amount (in CAD) paid by the customer.
3.
Now, the program should display the exact number of bills to be returned to the customer.
Example:
Enter the total amount of the bill: 326
Enter the amount paid by the customer: 405
You should return to the customer the following:
100$ bills: 0
20$ bills: 3
10$ bills: 1
5$ bills: 1
1$ coins: 4

Exercise 4
Student: You are required to design and implement a class called Student in a header file
called Student.h according to the following specifications:
The class has the following attributes:
id an integer which specifies the id of the student
name a string which holds the name of the student
grade1: an integer which specifies the grade of the student in his 1st year of school
grade2: an integer which specifies the grade of the student in his 2nd year of school
grade3: an integer which specifies the grade of the student in his 3rd year of school
1. Write a no-argument constructor that initializes the id and the grades attributes to 0 and
the name to an empty string.
2. Write a constructor which initializes the attributes of the class to specific values passed
as parameters.
3. Write a get and set member functions that get and set each of the class attributes.
4. Write a method called calculateGPA() which calculates and returns the GPA of a
student. The GPA is calculated as follows: gpa = (grade1+grade2+grade3)/3
5. Write a getInfo() method which returns a string with the student name, id, grade1, grade2,
grade3 and GPA (use the calculateGPA() method).
6. Write a getMaxGrade() method that will return the maximum grade got by the student
7. Create a StudentTest.cpp file which contains a main method that :
a) Creates a student object (student1) using the no-argument constructor
b) Updates the id, name, grade1, grade2, grade3 of student1 by setting them to new values
of your choice
c) Creates another student object (student2) using the argument constructor
d) Displays the information of the two students
e) Display the maximum grade of each of the two students
Example of the output of the program:
Student 1 has the following information:
Id: 1; Name: Rima; Grade 1=12; Grade 2=16; Grade 3=19; GPA=15.66
Student 2 has the following information:
Id: 2; Name: Karim; Grade 1=6; Grade 2=18; Grade 3=20; GPA=14.66
The maximum grade of student 1 is 19
The maximum grade of student 2 is 20

You might also like