0% found this document useful (0 votes)
21 views8 pages

FINAL EXAMINATION OF Object Oriented Progra,,ing C++

ex

Uploaded by

bahati david
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views8 pages

FINAL EXAMINATION OF Object Oriented Progra,,ing C++

ex

Uploaded by

bahati david
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

FINAL EXAMINATION

SCHOOL OF COMPUTING AND SCIENCES

DEPARTMENT: SOFTWARE ENGINEERING

MODULE CODE AND TITLE


CSC2403 LEVEL 2 AND TRIMESTER 4
OBJECT ORIENTED PROGRAMMING
DATE: /5/2024 TIME AND SESSION:

DURATION: 3 HOURS TOTAL MARKS: 70


EXAMINER/LECTURER:BAHATI DAVID MODERATOR(S):

INSTRUCTIONS TO THE CANDIDATE


1. Questions must be attempted in the answer booklet provided

2. All queries should be directed to the invigilator; do not communicate or attempt to


communicate with any other candidate

3. You have TWO HOURS to complete this paper. You are not allowed to leave the examination
room within the first hour and in the last 15 minutes of this examination.

4. This is a CLOSED BOOK examination.

5. Question 1 (SECTION A ) is Compulsory and choose any 3 other questions in Section B

6. Please, do not write on the question paper

1
SECTION A: PRACTICE

Question: 1 C++ Object Oriented Programming Final Project Johnny is planning to expand his
bookstore to sell Compact Disks and DVDs. He needs your help. Write Johnny a program to
manage his inventory. The program must do the following: 1. Allow entering new items into
the program from the keyboard – this identifies the items Johnny will sell, Book, CD, or DVD
and the inventory of the shop

C++ Object Oriented Programming

Final Project

Johnny is planning to expand his bookstore to sell Compact Disks and DVDs. He needs your help.
Write Johnny a program to manage his inventory.

The program must do the following:

1. Allow entering new items into the program from the keyboard – this identifies the items Johnny
will sell, Book, CD, or DVD and the proper inventory record created for each one. The SKU (automatic
number is the best option), number on hand, description and so-on, are initialized at this time. Some
of these items will be updated when receiving an order. NOTE: some data members will reside in the
base class and some in the derived classes (see below), and you must provide for appropriate
member functions and data.

2. Receiving an order -- this means that the number of items received is entered into the program
along with it’s cost per item and other pertinent details (see below). If there is a change in the cost,
the new selling price is calculated.

3. Calculate the selling price of each item from its cost based on a markup. The markup for books is
25%, for CDs is 30% and for DVDs is 40%.

Price = Cost + Cost * percentage

4. Sell an item. This means that the on hand is checked, and if there is enough merchandise, the sale
is recorded by decrementing the number on hand by the number sold, computing the total price,
including sales tax at 8.25%. Use a constant to store the tax percentage. If there is not enough
inventory, sell whatever is available and issue a message.

5. Output a report of all items on hand, including their total dollar value (not total cost). Include a
warning whenever there are fewer than 10 of an item currently on hand.

For each item your inventory program must maintain the following:

1. When new items are created by using feature 1, assign an inventory number for the item.

2. For Books, maintain the title, author and short description.

2
3. For CDs maintain the title, artist name, number of tracks, playing time, and genre such as: Pop, Jazz,
Rock, Country, Rap, etc. Make this open ended so new classifications can be entered. A text field will
do.

4. For DVDs maintain the title, director, lead actor, playing time and genre such as: Drama, Comedy,
etc.(a text field)

5. For all items, compute price based on cost and markup, keep count of the number on hand.

The report called for by requirement 5 should output all information about each inventory item.

You will need to take advantage of the capabilities of C++ classes, inheritance and polymorphism,
including virtual functions.

Program Design:

1. Create a class called Inventory that does the inventory. All data members have to be private. Your
main function and any function that it calls should use the member functions of this class for all
transactions. The other classes (below) are not directly referred to in the main function.

2. Create a class called Item which will serve as a base class for each of the several derived classes for
Johnny’s merchandise. The classes Book, DVD and CD will inherit this class.

3. The inventory class must maintain an array of pointers to Item objects to keep the inventory. Please
do not use anything more sophisticated than an array. These pointers can point to Book, CD, and DVD
objects.

4. Keep the program simple. I am not interested in how slick you can make it. I am interested in
whether you can demonstrate basic competence in the use of classes, inheritance, virtual functions
and good design.

5. Make your Item class an abstract base class. All data members in the classes Book, CD, DVD and
Inventory must be private. This is to assure that you use the C++ capabilities that this assignment is
all about. Do not use any global variables.

NOTE: To test your project to turn in, I want to see several items of each type, book, CD, DVD created,
an order received for each type item, and several sales recorded to verify the various transactions.
Include at least one sale that tries to sell more of something than you have on hand to test that aspect
of your program. Also include a report as per requirement 5 to complete the test. Test, test, test, and
test again.

This image gives you an idea how polymorphism works.

Output Example:

Main Menu:

1) To enter a new item enter 1

3
2) To enter an order enter 2

3) For Sale enter 3

4) For a complete report enter 4

5) To quit enter 5

New Item:

B) To add a new book enter B

C) To add a new CD enter C

D) To add a new DVD enter D

M) To return to the main menu enter M

Enter title: ………………………

Enter author: ……………………

Enter description: ……………….

Enter cost: ………………………

Order:

Enter SKU for new order: ………

Enter quantity received: ………..

Enter cost: ………………………

Sale:

SKU: …………………………….

Quantity: …………………………

Next SKU or O to total: …………

SKU: …………………………….

Quantity: ………………………...

4
Next SKU or O to total: …………

Receipt:

1008 2 $12.50 $25.00 (message if not enough)

1041 3 $21.00 $63.00

Total $88.00

Tax $7.70

Subtotal $95.70

Report:

SKU 1001 (Book)

Number on hand: 9 (Inventory is low, place an order)

Cost: $12.45

Title: The Art of War

Price: $15.56

Total $ value $140.04

Author: Sun Tzu

Description: A book of strategy by a mysterious philosopher

……………………………………………………………………….

SKU 1002 (CD) So on and so forth

SECTION B

5
QUESTION 1

Cross out all the lines that will not compile in the main function of the following program:

6
QUESTION 2

A) What will be the output of this code?


B) Explain each and every line of this code

QUESTION 3
Write a program that has an abstract base class named Quad. This class should have four member
data variables (floats) representing side lenghts and a pure virtual function Area. It should also have
a method for setting the data variables. Derive a class Rectangle from Quad and override the Area
method so that it returns the area of the Rectangle. Write a main function that creates a Rectangle
and sets the side lengths. Also write a top-level function that will take a parameter of type Quad and
return the value of the appropriate Area function.
QUESTION 4
Declare a class named Triple with three private data members (floats) x, y, and z. Provide public
functions for setting and getting values of all the private data members. Define a constructor that
initializes the values to user-specified values or, by default, sets the values all equal to 0. Also overload
the following operators:

7
—Addition so that corresponding elements are added together
—Output so that it displays the Triple in the form “The triple is (x, y, z).”
—Assignment that copies x to z, y to x, and z to y.
—Post-increment so that x and z are increased by one each.
—Function call operator so that the values for x, y and z can be set.

You might also like