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

Example Program For Array of Objects

This C++ program defines a class 'item' to manage a shopping list with attributes for item name, quantity, rate, and amount. It allows users to input data for three items and then displays the shopping list with formatted output. The program uses basic I/O operations and includes functions for data entry and display.

Uploaded by

Hydra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Example Program For Array of Objects

This C++ program defines a class 'item' to manage a shopping list with attributes for item name, quantity, rate, and amount. It allows users to input data for three items and then displays the shopping list with formatted output. The program uses basic I/O operations and includes functions for data entry and display.

Uploaded by

Hydra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

//C++ program for array of object

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
const size=3;
class item
{
private:
char name[25];
int qty;
float rate,amount;
public:
void getdata()
{
cout<<endl<<"Enter the item name:";
cin>>name;
cout<<"\nEnter the Rate:";
cin>>rate;
cout<<"\nEnter the Quantity:";
cin>>qty;
}
void printdata()
{
cout<<setw(5)<<name;
cout<<setw(5)<<rate;
cout<<setw(5)<<qty;
amount=rate*qty;
cout<<setw(8)<<amount<<endl;
}
};

void main()
{
item shop[size];
clrscr();
for(int i=0;i<size;i++)
shop[i].getdata();
cout<<"Shopping List"<<endl;
cout<<"Name Quantity Rate Amount\n";
for(i=0;i<size;i++)
shop[i].printdata();
getch();
}

You might also like