Академический Документы
Профессиональный Документы
Культура Документы
1. Answer all 4 Questions. Mark allocations are given under each question.
2. Marks will be given for proper comments. Therefore, use appropriate comments
in all programmes.
3. Write your registration number and name as a C++ comment at the end of each
programme you submit.
4. Programmes should be named as Question1.cpp, Question2.cpp etc. The text file,
object file and the executable file of each programme should be submitted. You
should copy all the programmes (programming codes) that you have written into a
word document and this also needs to be submitted along with the programmes.
5. Put all above mentioned files in to a folder and name the folder as
‘MEK3170_A3_2007_your student number’ and zip the folder and upload it to
the OUSL Virtual Class Room.
6. Last date of submission is 25th January 2008
7. Penalties will apply for late submissions
8. If you need further clarification, you may contact the academic coordinator via
email
Email: wsnan@ou.ac.lk
Question 1
This question is based on the concept of Inheritance. You should write a programme,
which produces an output, which is similar to a balance sheet provided by a bank at the
end of each month. Your output should be organized in the following manner.
---Nimal’s Account---
Page 1 of 8
Create a class called ‘Account’ and two derived classes called Current account
(Current_acc) and Savings Account (Savings_acc)
Account
• This class has a private data member called ‘amount’ and two protected data
members called ‘balance’ and ‘ini_amount’.
• Class Account has three public methods called ‘status’, ‘deposit’ and ‘withdraw’.
• You should define a constructor for the class account which initializes the default
initial bank balance to zero 0.
Page 2 of 8
(b) Class Current Account
• Every month a service charge of Rs.100 will be charged from the customer. Hence
at the end of each month Rs.100 will be deducted from the customers bank
balance. Create a public method to calculate the service charges and debit
(deduct) the service charge from the customer’s current account balance at the end
of the month and display the answer.
• 2% interest on the present balance will be added to the savings account at the end
of each month according to the bank balance.
Create a public method to calculate the interest and credit (add) it to the
customer’s savings account balance at the end of the month and display the
answer.
The tables 1, 2 and 3 show the transactions that Kamal, Saman and Mihiri has performed
during the month of November 2007. Create the objects and perform the following
transactions for the month of November and display the transactions according to the
format given at the beginning of the question.
Table 1:
Kamal’s Account
Type - Current Account
Date Transaction Amount (Rs)
01/11/2007 Opening the account 5000 (default value)
10/11/2007 Deposit 2300
15/11/2007 Deposit 7000
17/11/2007 Withdrawal 1750
20/11/2007 Withdrawal 1900
Page 3 of 8
Table 2:
Saman’s Account
Type: Savings Account
Date Transaction Amount(Rs)
02/11/2007 Opening the account 1000 (default value)
05/11/2007 Deposit 2500
15/11/2007 Deposit 3500
19/11/2007 Withdrawal 750
30/11/2007 Deposit 7500
Table 3:
Mihiri’s Account
Type: Savings Account
Date Transaction Amount(Rs)
06/11/2007 Opening the account 8000
12/11/2007 Deposit 2500
17/11/2007 Deposit 3500
22/11/2007 Deposit 4300
25/11/2007 Withdrawal 1200
Note: You do not need to include the date of the transactions in your programme.
Hint: Inside the main method, you should call the different types of methods you have
created (ex. deposit(), withdraw(), status(), etc ) for every object, in order to display the
transactions properly.
(30 marks)
Question 2
Create a base class called ‘Student’ and two derived classes called Regular Student
(Regular_stu) and Scholarship Student (Schol_stu).
Student
Page 4 of 8
• In the base class, define two protected members called ‘course’ and ‘material’ and
a public method called set_values in order to set the values for the protected
members ‘course’ and ‘material’.
• Students have to pay a course fee (‘course’) as well as a course material fee
(‘material’) depending on the courses that they have enrolled for. Total course
charges include the course chargers as well as the course material charges.
• Class Regular_stu has a public method called charges() which calculates the total
course charges.
• Class Schol_stu also has the public method called charges() which calculates the
total course charges but the scholarship students will be charged half of the course
charges and they also get a 10% discount for the course material charges.
• Create two objects called ‘regular’ and ‘scholar’, which are of classes regular_stu
and schol_stu respectively.
• Create two pointers of type Student and assign references to ‘regular’ and
‘scholar’ to these pointers.
• Using the pointers and set the values of the objects according to the values given
below.
o The regular student’s course charge is Rs.5000.50 and the material charge
is Rs.2000.75.
o The scholarship student’s course charge is 2000 and the material charge is
Rs.100.90.
• Using the pointers, call the charges() methods of the Regular_stu class and the
Schol_stu class and display the answers.
---Scholarship student---
Charges Rs. 1090.81
Page 5 of 8
(20 marks)
Question 3
You should write a programme which similar to an information system which stores
information on books.
a) The user should be given the opportunity to enter the information given below
into the system separately.
(b) The information that the user has entered should be stored in a text file called
‘books’ in the following manner.
Book Name - C++ Programming for Dummies
Author’s Name - Stephen Randy Davis
Book Details - C++ for Dummies is an introduction for C++ programmig
Book ISBN - 8126501200
Note:
o Every time a user enters a new book into the system, all the details should
be appended (added) to the text file.
o Even though the user enters the author’s first name and last name
separately, the author’s full name should be stored in the text file as given
above.
(c) After the user enters the details of the book into the system, your programme
should display the following message to the user.
Page 6 of 8
• If the user enters ‘y’ your programme should display all the information in
your text file into the output screen after clearing the screen. Your output
should be organized in the following manner.
---Sarasi Bookshop---
Available Books:
• If the user enters any other character, your programme should display an
error message and ask the user to enter the correct option until the user
enters a valid character. (‘y’ or ‘n’)
(30 marks)
Question 4
You should write a programme using a C++ data structure, which calculates the total
number of seconds when the user enters the number of hours, minutes and seconds.
(a) Define a structure called ‘Time’ and three integer members called ‘hours’,
‘minutes’ and ‘seconds’ and a object called ‘t’
(b) The user should be given the opportunity to enter the number of hours, minutes
and seconds, separately. Store the values that the user has entered in the data
members called ‘hours’, ‘minutes’ and ‘seconds’ respectively.
(c) Your programme should create an integer function and pass the data structure into
the function as a parameter. Using the above function calculate the total number
of seconds and return the answer into the main function.
Page 7 of 8
Your programme output should be organized in the following manner.
(20 marks)
Page 8 of 8