



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Assignment 3 of 2023 from University of South Africa
Typology: Assignments
1 / 7
This page cannot be seen from the preview
Don't miss anything!




21 August 2023
24 August 2023
TUTORIAL MATTER:
Chapters 10, 11, 12 and 15 of the Study Guide (Appendix D)
Chapters 10, 11, 12 (excluding “Creating a Namespace”)
Appendices 7 and 8 in Savitch
None
Question 1
Consider the following structure used to keep employee records:
struct Employee { string firstName; string lastName; float salary; }
Turn the employee record into a class type rather than a structure type. The employee record class should have private member variables for all the data. Include public member functions for each of the following:
Embed your class definition in a test program. The test program should create two Employee objects and display each object’s annual salary. Use the overloaded constructor to initialise one of the Employee records as Joe Soap with an annual salary of R145600.00. Obtain the following input values for the other Employee record from the keyboard: Joanne Soape R154460.
Now give each employee a 10% raise and display each Employee object’s annual salary again.
Quesion 2
Design and implement a C++ class called Module that handles information regarding your assignments for a specific module. Think of all the things you would want to do with such a class and write corresponding member functions for your Module class. Your class declaration should be well-documented so that users will know how to use it.
At a minimum your class Module should contain information on the module code, the module name, the marks for assignments, the year mark and the final mark.
Test your class in a small program where you instantiate an object of the class, initialize the member variables that represents the assignment marks, calculate a year mark and display the year mark.
Quesion 3
Implement your class Module from question 2, as an abstract data datatype (ADT) using separate compilation, so that separate files are used for the interface and implementation.
Write a main program that does the following:
Enrichment exercise:
Adapt the application program to use a vector instead of an array. It should not be necessary to change the class interface or implementation file in any way.
bool operator<(const Date &d); private: //the current day month and year int theday; int themonth; int theyear; //return the length of current month, taking into //account leap years int monthLength(); };
Implement and test the Date class, taking the following guidelines into account:
a) The default constructor should initialise the date to 14 September 1752. (1) b) The overloaded constructor should initialise the date with the given day, month and year. (1) c) The functions getDay(), getMonth() and getYear() should return the current day, month and year respectively. (1) d) The functions setDay(), setMonth() and setYear() should change the current day, month or year to the given value. (1) e) The operator ++ should advance the date by one, and return the new date. (2) f) The operator -- should set the date back by one day, and return the new date.(2) g) The operator < should calculate whether the receiving date object (left argument) precedes the parameter date (right argument). For example, Date(1,1,2002) < Date(1,3,2002). (3) h) The private member function monthLength() should return the number of days in the current month, taking into account leap years. A year is a leap year if it is either (i) divisible by 4, but not by 100, or (ii) divisible by 400. In a leap year, February has 29 days, otherwise it has 28 days. (3) i) Also overload the insertion operator << to output a date to the screen. For example, the date in (a) above should be written as: 14 September 1752. (3)
Test the Date class in a C++ program that will do the following:
Enrichment exercise:
Turn the Date class into an ADT, so that separate files are used for the interface and implementation. Use separate compilation to compile the implementation separate from the application program that tests the ADT.
Question 6
Define a class PhoneCall as an ADT that uses separate files for the interface and the implementation. This class represents a phone call and has three member variables:
In addition, the class should contain a default constructor that initializes number to an empty string, length to 0 and rate to 0. It should also contain an overloaded constructor that accepts a new phone number and sets length and rate both to 0, as well as a destructor that does not perform any action.
Include accessor functions that returns the values stored in each of an object of class PhoneCall’s member variables respectively.
Class PhoneCall also contains a member function calcCharge() to determine the amount charged for the phone call. Use the following prototype:
float calcCharge();
Overload the equality operator== as a friend function to compare two phone calls. Use the following prototype:
bool operator==(const PhoneCall & call1, const PhoneCall & call2)
This function returns true if both call1 and call2 have been placed to the same number and false otherwise.
Overload the stream extraction operator >> (implemented as a friend function) so that it can be used to input values of type PhoneCall, and the stream insertion << (implemented as a friend function) so that it can be used to output values of type PhoneCall.
Demonstrate the class in an application program (main()) that is used to determine the total amount spend on phone calls to a specific phone number in one month. Allow the user to enter the phone number for which the total amount spent should be determined. Use the overloaded constructor to initialise the PhoneCall object
student number: 12345678
address: Po Box 16, Pretoria, 0818
degree: BSc
(c) Derive and implement a class PostgradStd from class Student. This class has an additional member variable, dissertation (the title of the Masters of doctorate the student is doing). Class PostgradStd also has an overloaded constructor and an accessor member to return the member variable dissertation. The class PostgradStd should override function display_info() in order to display the values of all the member variables of PostgradStd. The class PostgradStd should also override function calcFee() to determine the additional fee for a postgraduate student which is R12000.
Implement the overloaded constructor for the class PostgradStd by invoking the base class constructor.
(d) Test class PostgradStd in a driver program that does the following:
name: Mary Mbeli
student number: 12345678
address: Po Box 16, Pretoria, 0818
degree: PhD
dissertation: How to get a PhD
© UNISA 2023