0% found this document useful (0 votes)
5 views3 pages

CPP Classes and Objects

The document contains a C++ program that defines a class 'Items' for managing a collection of items with their codes and prices. It provides functionalities to add items, display the total value of items, remove an item by its code, and display all items. The program runs in a loop, allowing the user to choose actions until they decide to quit.
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)
5 views3 pages

CPP Classes and Objects

The document contains a C++ program that defines a class 'Items' for managing a collection of items with their codes and prices. It provides functionalities to add items, display the total value of items, remove an item by its code, and display all items. The program runs in a loop, allowing the user to choose actions until they decide to quit.
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/ 3

21BCE5175 BCSE102P

C++ Classes and Objects

MADEPALLI MUKESH SAI


VIT CHENNAI
#include<iostream>
using namespace std;
int m=50;
class Items
{
private:
int itemCode[m]; float itemPrice[m]; int count;
public:
void CNT(){
count=0;
}
void getitem();
void displaySum();
void remove();
void displayItems();
};
void Items :: getitem()
{
cout<<"Enter item code";
cin>>itemCode[count];
cout<<"Enter Item cost";
cin>>itemPrice[count];
count++;
}
void Items :: displaySum()
{
float sum=0;
for(int i=0;i<count;i++){
sum=sum+itemPrice[i];
}
cout<<"\n Total Value:"<<sum<<"\n";
}
void Items :: remove()
{
int a;
cout<<"Enter Item Code";
cin>>a;
for(int i=0;i<count;i++){
if(itemCode[i] == a){
itemPrice[i]=0;
}
}
}
void Items :: displayItems()
{
cout<<"\n Code Price\n";
for(int i=0;i<count;i++){
cout<<"\n"<<itemCode[i];

1|P a ge
cout<<" "<<itemPrice[i];
}
cout<<"\n";
}
int main()
{
Items order; order.CNT(); int x;
do
{
cout<<"\n You can do the following;"<<"Enter appropriate number\n";
cout<<"\n1 : Add an Item";
cout<<"\n2 : Display Total Value";
cout<<"\n3 : Delete an Item";
cout<<"\n4 : Display all items";
cout<<"\n5 : Quit";
cout<<"\n\n What is your option?";
cin>>x;
switch(x)
{
case 1 : order.getitem(); break;
case 2 : order.displaySum(); break;
case 3 : order.remove(); break;
case 4 : order.displayItems(); break;
default : cout<<"Error in input";
}
}
while(x!=5);
return 0;
}

2|P a ge

You might also like