Lab No. 04 Classes & Structures in C++: 1.3. Instructions
Lab No. 04 Classes & Structures in C++: 1.3. Instructions
Lab No. 04
Classes & Structures in C++
1.3.Instructions
This is individual Lab work/task.
Complete this lab work within lab timing.
Discussion with peers is not allowed.
You can consult any book, notes & Internet.
Copy paste from Internet will give you negative marks.
Lab work is divided into small tasks, complete all tasks sequentially.
Show solution of each lab task to your Lab Instructor.
In-Lab Exercises/Tasks
24
CS114-Programming Fundamentals Lab Manual
Task 1: Create a class called Invoice that a hardware store might use to represent an invoice for
an item sold at the store. An Invoice should include six data members a part number (type
string) , a part description (type string), a quantity of the item being purchased (type int), a price
per item (type int) a value-added tax (VAT) rate as a decimal (type double), and a discount rate
as a decimal (type double).
Your class should have a constructor that initializes the six data members. The constructor
should initialize the first four data members with values from parameters and the last two data
members to default values of 0.20 per cent and zero respectively.
Provide a set and a get functions for each data members. In addition, provide a member function
named getInvoiceAmount that calculates the invoice amount (i.e., multiplies the quantity by the
price per item and applies the text and discount amounts), then returns the amount. Have the set
data members perform validity checks on their parameters --- if a parameter value is not positive,
it should be left unchanged.
25
CS114-Programming Fundamentals Lab Manual
26
CS114-Programming Fundamentals Lab Manual
Task 2: Create a class called MotorVehicle that represents a motor vehicle using: make (type
string), fuel Type (type string), year Of Manufacture (type int), color (type string), and engine
Capacity (type int). Your class should have a constructor that initializes the three data members.
Provide a set and a get function for each data member. Add a member function called
displayCardDetails that displays the five data members in five separate lines in the form
es.
27
CS114-Programming Fundamentals Lab Manual
Task 3: Create a class called Date that includes three pieces of information as data members---a
month (type int), a day (type int), and a year (type int). Your class should have a constructor with
three parameters that uses the parameters to initialize the three data members. For the purpose of
this exercise, assume that the values provided for the year and day are correct, but ensure that the
month value in the range 1-
Provide a set and a get function for each data member. Provide a member function displayDate
that displays the month, day and year separated by forward slashes (/).
28
CS114-Programming Fundamentals Lab Manual
Task 4: Create a Structure called Distance that includes two pieces of information as data
members---feet (type int), ainches (type int). Your class should have a constructor which
initializes the two data members.
Provide a set and a get function for each data member. Provide a member function
displayDistance that displays the feet and inches in the form of .
29