0% found this document useful (0 votes)
114 views6 pages

Lab No. 04 Classes & Structures in C++: 1.3. Instructions

This lab manual introduces students to classes and structures in C++. It contains 4 tasks to help students learn how to define classes with data members, constructors, setter and getter functions. It also covers creating structures. The tasks involve creating classes for invoices, motor vehicles, dates and a structure for distances. Students will define the necessary data members and functions for each task.
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)
114 views6 pages

Lab No. 04 Classes & Structures in C++: 1.3. Instructions

This lab manual introduces students to classes and structures in C++. It contains 4 tasks to help students learn how to define classes with data members, constructors, setter and getter functions. It also covers creating structures. The tasks involve creating classes for invoices, motor vehicles, dates and a structure for distances. Students will define the necessary data members and functions for each task.
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/ 6

CS114-Programming Fundamentals Lab Manual

Lab No. 04
Classes & Structures in C++

In this lab you will be introduce with:


1. Learn to define classes in C++ to represent an object
2. Learn to define setters and getters for data members
3. Learn to define constructor of class
4. Learn to use Structures

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

Lab Objectives and CLOs Mapping

Lab objectives CLOs


A b c
1
2
3
4
5

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

You might also like