Anonymous School
(Minds of Hacker)
--------------------------------
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{public:int code,price;};int main(){item a[5];int add =0 ;cout<<"Enter the code & price of five items\n";for(int i=0; i<5;i++){cin>>a[i].code;cin>>a[i].price;}cout<<"you enter code & price\n";for(int i=0; i<5;i++){cout<<"code = "<<a[i].code<<" Price = "<<a[i].price<<"\n";}for(int i=0; i<5;i++){add = add + a[i].price;}cout<<"Total sum of price = "<<add<<"\n";}
Output:
Enter the code & price
1 25
2 35
3 67
4 64
5 89
you enter code & price
code = 1 Price = 25
code = 2 Price = 35
code = 3 Price = 67
code = 4 Price = 64
code = 5 Price = 89
Total sum of price = 280
*******************Don't Make Learning Hard*****************
Follow us on :-
1) YouTube Channel :- Click Here
2) Blog :- Click Here