/*
Write a program which define a class “Item” having data members as code and price. Accept data for five object and display data (Using array of object). Also display the total price of all items by passing array of object as parameter to function
*/
#include<iostream>
using namespace std;
class Item
{
int code,price;
public:
void accept()
{
cout<<"\n\n Enter code and price: ";
cin>>code>>price;
}
void display(Item a[])
{
for(int i=0;i<5;i++)
{
cout<<"\n\n "<<i+1;
cout<<"\n Code: "<<a[i].code;
cout<<"\n Price: "<<a[i].price;
}
}
void sum(Item a[])
{
int s=0;
for(int i=0;i<5;i++)
{
s=a[i].price+s;
}
cout<<"\n\n Sum of all items: "<<s;
}
};
int main()
{
Item e[5];
for(int i=0;i<5;i++)
{
cout<<"\n\n "<<i+1;
e[i].accept();
}
e[1].display(e);
e[1].sum(e);
return 0;
}
Write a program which define a class “Item” having data members as code and price. Accept data for five object and display data (Using array of object). Also display the total price of all items by passing array of object as parameter to function
*/
#include<iostream>
using namespace std;
class Item
{
int code,price;
public:
void accept()
{
cout<<"\n\n Enter code and price: ";
cin>>code>>price;
}
void display(Item a[])
{
for(int i=0;i<5;i++)
{
cout<<"\n\n "<<i+1;
cout<<"\n Code: "<<a[i].code;
cout<<"\n Price: "<<a[i].price;
}
}
void sum(Item a[])
{
int s=0;
for(int i=0;i<5;i++)
{
s=a[i].price+s;
}
cout<<"\n\n Sum of all items: "<<s;
}
};
int main()
{
Item e[5];
for(int i=0;i<5;i++)
{
cout<<"\n\n "<<i+1;
e[i].accept();
}
e[1].display(e);
e[1].sum(e);
return 0;
}