0% found this document useful (0 votes)
7 views

SampleExperimentNo4 2022

Uploaded by

namishkhotre
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)
7 views

SampleExperimentNo4 2022

Uploaded by

namishkhotre
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/ 2

PP Lab Name: PRN:

Practical No 4 Date: / /

Title: Write a C++ program using class to process shopping list for a departmental store. The list
includes details such as item code no, item name and price of each item and perform the operations
like adding, deleting items to the list and printing the total value of an order.
Description:
A class in C++ is the building block, that leads to Object-Oriented programming. It is a user-
defined data type, which holds its own data members and member functions, which can be
accessed and used by creating an instance of that class.

Classes are like templates that define common properties or attributes. Objects are instances of a
class. Once a class has been defined, we can create any number of objects belonging to that class.
Each object is associated with the data or type class with which they are created.

Declaration of class:
class <class_name>
{
data members;
member functions;
};

Syntax for creating object:


classname objectname;
Example: fruit mango;

Hint:
Menu:
Add an item and Quantity
Display total value
Delete an item
Display all items
Exit

class item
{
int itemcode[50];
float itemprice[50];
int count;
public:
void cntzero(); //initialize count to zero
void getitem(); (hint: cin>>itemcode[count]; count++;) //assigns value to data members of class item
void displaysum(); //display total value of all items
void remove(); //ask the user to enter item code and delete the specified item
void displayitems(); // displaying items
};
PP Lab Name: PRN:

Display all items


Code Quantity price Total
567 2 100 200
678 5 50 250
Grand Total: Rs.450

Total value of inventory: 150

Program Code:

Input and Output

Conclusion: Thus we have implemented the concept of classes in C++

Practice programs: Write a program that would print the information (name, year of joining,
salary, address) of three employees by creating a class named 'Employee'. The output should be as
follows:
Name Year of joining Address
Rahul 2010 64C- WallsStreat
Samar 2000 68D- WallsStreat
Ishita 2018 26B- WallsStreat

You might also like