Write a C++ program
to read a list containing item name, item code and cost interactively and
display the data in a tabular format as shown below:
NAME CODE
COST
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
int main()
{
int n,itcode[10]; char item[10][10]; float itcost[10]; clrscr();
cout<<"Enter the no of item:"; cin>>n;
for(int i=0;i<n;i++)
{
cout<<"Enter the item details:"<<i+1;
cout<<"\nEnter name:"; cin>>item[i];
cout<”Enter code:";
cin>>itcode[i]; cout<<"Enter cost:"; cin>>itcost[i];
}
cout<<endl<<setw(15)<<"Item
name"<<setw(15)<<"item code"<<setw(15)<<"cost"<<endl;
cout<<"\n-------------------------------------
|
\n";
|
for(i=0;i<n;i++)
|
|
{
|
|
cout.fill( ' - ' );
|
|
cout.setf(ios::left,ios::adjustfield);
|
|
cout.width(15);
cout<<item[i];
cout.setf(ios::left,ios::adjustfield);
cout.width(15);
cout<<itcode[i];
cout.setf(ios::right,ios::adjustfield);
cout<<itcost[i]<<endl;
}
getch();
return 0;
}
***********************************OUTPUT*************************
Enter the no of item:3
Enter the item
details:1
Enter name:Rice
Enter code:111
Enter cost:35.4
Enter the item
details:2
Enter name:Sugar
Enter code:112
Enter cost:12.3
Enter the item
details:3
Enter name:Soap
Enter code:113
Enter cost:60.4
Item
name item code cost
------------------------------------------------
Rice-----------
|
111------------
|
35.400002
|
Sugar----------
|
112------------
|
12.3
|
Soap-----------
|
113------------
|
60.400002
|
No comments:
Post a Comment
Comment Here