Академический Документы
Профессиональный Документы
Культура Документы
BSC 201:
PROGRAMMING IN C++
INSTRUCTION TO CANDIDATE:
QUESTION ONE:
A Vimachitika car rental company needs to keep extensive records to run their operation
correctly. Not only does a company need to keep track of their customers, but it is also
imperative to keep good records on employees. Keeping track of what car, a customer is
driving is a good example of a record. In addition, many times, cars need to be transported
between locations of a company. If a staff member is moving a car, it is important to know
which staff members are moving certain cars.
Suppose a NIPA wanted to create a car rental company called Vimachitika rentals. This
company has employed you to keep records for the company. The company is confident you
will succeed in creating a large-scale record system, but they would like you to prove your
coding skills first. Vimachitika rentals would like you to set up an initial program to hold
records before you begin the full-scale project.
You are tasked to create 2 ADTs: customers and staff. Each customer will have a first and
last name, an indication if the customer is enrolled in the “preferred” program, the car they
are driving, and the amount of money owed to the company. On the other hand, each staff
member will have a first and last name, the car they are driving, and their salary. In a real-
world problem, there would obviously be more records associated with each staff member
and customer.? Vimachitika rentals would like you to automatically process txt files and print
the information to the console screen. When you perform this process, ensure that your
member variables are private. In addition, be sure to use getter and setter functions to
manipulate and print your data.
[Total=20 marks]
QUESTION TWO:
#include <iostream>
using namespace std;
template <class any_data_type>
any_data_type MyMax(any_data_type Var1, any_data_type Var2)
{
return Var1> Var2 ? Var1:Var2;
}
int main()
{
cout<<"MyMax(10,20) = "<<MyMax(10,20)<<endl;
cout<<"MyMax('Z','p') = "<<MyMax('Z','p')<<endl;
cout<<"MyMax(1.234,2.345) = "<<MyMax(1.234,2.345)<<endl;
cout<<"\n Logical error, comparing pointers not the string..."<<endl;
char* p = "Function";
char* q = Template;
cout<<"Address of *p = "<<&p<<endl;
cout<<"Address of *q = "<<q<<endl;
cout<<"MyMax(\"Function\",\"Template\") = "<<MyMax(,q)<<endl;
cout<<"Should use Specialization, shown later..."<<end;
return 0;
}
a) For each of the highlighted lines, provide a c programming comment and explain the
significance of each line.
(6 marks)
b) Write the output for above program after correcting the syntax error. (14 marks)
[Total=20 marks]
SECTION B: Answer one Question from in this section
QUESTION THREE
You will create a C program that prints a menu and takes user choices as input. The user will
make choices regarding different "geometric shapes" that will be printed to the screen.
Your code must contain at least one of all of the following control types:
❖ nested for () loops
❖ a while () or a do-while () loop
❖ a switch () statement
❖ an if-else statement
❖ functions (see below)
Instructions
A prompt is presented to the user to enter a choice from the menu. If the user enters a choice
that is not a valid input, a message stating the choice is invalid is displayed and the menu is
displayed again.
In case of a rectangle, we assume its width is N+5. It should look like the following:
***********
***********
***********
***********
***********
***********
If the user selects Triangle, then it should print a left justified triange which looks like the
following:
*
**
***
****
*****
******
[Total=20 marks]
QUESTION FOUR
(i) Create a class named Shape with a function that prints "This is a shape". Create another
class named Polygon inheriting the Shape class with the same function that prints "Polygon is
a shape". Create two other classes named Rectangle and Triangle having the same function
which prints "Rectangle is a polygon" and "Triangle is a polygon" respectively. Again, make
another class named Square having the same function which prints "Square is a rectangle".
Now, try calling the function by the object of each of these classes. (10 marks)
(ii) A boy has his money deposited K2000, K5500 and K6000 in Banks-Bank X, Bank Y and
Bank Z respectively. We have to print the money deposited by him in a particular bank.
Create a class 'Bank' with a function 'getBalance' which returns 0. Make its three subclasses
named 'BankX', 'BankY' and 'BankX' with a function with the same name 'getBalance' which
returns the amount deposited in that particular bank. Call the function 'getBalance' by the
object of each of the three banks. (10 marks)
SECTION C: Answer one Question from in this section
QUESTION FOUR
[Total=20 marks]
QUESTION SIX
Write a C program to input basic salary of an employee and calculate gross salary according
to given conditions.
How to calculate gross salary of an employee using if else in C++ programming. Write a
Program to calculate gross salary of an employee using if else-if, Constructor and
Destructor concepts in C++ program.
Example
Input
Input basic salary of an employee: 2200
Output
[Total=20 marks]
*****END*****