Thursday, October 16, 2014

Write a program to make a shopping list in which we can include data like code & cost and performed operation like add item, delete item,display item and display total of cost.

Prog 24 : Write a program to make a shopping list in which we can include data like code & cost and performed operation like add item, delete item,display item and display total of cost.
#include<iostream.h>
#include<conio.h>
 int const size=10;
class shop
{
int count;
int code[size];
int cost[size];
public:
void add();
void del();
void display(); void total(); void CNT()
{
count=0;
}
};
void shop::add()
{
cout<<"\n enter code"; cin>>code[count];
cout<<"\n enter cost";
cin>>cost[count]; count++;
}
void shop::del()
{
int a;
cout<<"\n enter item code";
cin>>a;
for(int i;i<count;i++)
{
if(code[i]==a)
cost[i]=0;
}
}
void shop::display()
{
for(int i=0;i<count;i++)
{
cout<<"\n code = "<<code[i];
cout<<"\n cost = "<<cost[i];
}
}
void shop::total()
{
int sum=0;
for(int i=0;i<count;i++)
{
sum=sum+cost[i];
}
cout<<"\n the sum is"<<sum;
}
void main()
{
clrscr(); shop s; int x; s.CNT();
cout<<"\n1 Add Item";
cout<<"\n2 Delete Item";
cout<<"\n3 Display Item";
cout<<"\n Display Total";
cout<<"\n Exit";
do
{
cout<<"\n Enter your choice";
cin>>x;
switch(x)
{
case 1:
s.add();
break;
case 2:
s.del();
break;
case 3:
s.display();
break;
case 4:
s.total();
break;
}
}while(x!=5);
getch();
}
Output:
1 Add Item
2 Delete Item
3 Display Item
4 Display Total
5 Exit
Enter your choice1 enter code1
enter cost100
Enter your choice1 enter code2
enter cost200
Enter your choice3 code = 1
cost = 100 code = 2 cost = 200

No comments: