Program using class and object.
Code:
#include<iostream.h>
Code:
#include<iostream.h>
#include<conio.h>
class item
{
public:
char name[20];
float mrp;
item();
};
item::item()
{
for(int i=0;i<20;i++)
name[i]=0;
mrp=0;
}
class list
{
int sl;
item it[30];
float total;
int qu;
void hr(int,int);
void vr(int,int);
int y;
public:
void listform();
void read();
};
void list::hr(int x,int y)
{
for(int i=x;i<=60;i++)
{
gotoxy(i,y);
cout<<"-";
}
}
void list::vr(int x,int y)
{
for(int i=y;i<35;i++)
{
gotoxy(x,i);
cout<<"|";
}
void list::listform()
{
//x=getx();
y=5 ;
hr(2,y-1);
vr(1,y);
gotoxy(2,y);
cout<<" Sl. ";
vr(6,y);
gotoxy(7,y);
cout<<" Product Name ";
vr(30,y);
gotoxy(31,y);
cout<<" Qty ";
vr(40,y);
gotoxy(41,y);
cout<<" MRP ";
vr(50,y);
gotoxy(51,y);
cout<<" Total ";
vr(61,y);
hr(2,y+1);
hr(2,y+28);
gotoxy(18,y+29);
cout<<"Grand Total";
hr(2,y+30);
}
//void read();
void list::read()
{ qu=0;
total=0;
sl=0;
int x=7;
char s=0;
int qun;
while(x<30&&s!=5)
{
gotoxy(4,x);
cout<<++sl;
gotoxy(8,x);
cin>>it[sl].name;
gotoxy(34,x);
cin>>qun;
gotoxy(42,x);
cin>>it[sl].mrp;
total+=qun*it[sl].mrp;
qu+=qun;
gotoxy(52,x);
cout<<qun*it[sl].mrp;
x++;
s=getch();
}
gotoxy(34,y+29);
cout<<qu;
gotoxy(52,y+29);
cout<<total;
}
void main()
{
char ch;
list ob;
do{
cout<<"\t\t\tShoppinglist";
gotoxy(50,46);
cout<<"Press \'ctrl+E\' to finish/exit\n";
ob.listform();
ob.read();
ch=getch();
clrscr();
}while(ch!=5);
}
Ouput layout
------------------------------------------------------------------------------------------------------------------------
| sl. | Product name | Qty | MRP | Total |
------------------------------------------------------------------------------------------------------------------------
| 1 | | | | |
| 2 | | | | |
| 3 | | | | |
| 4 | | | | |
: . : : : : :
. . . . . . .
: . : : : : :
| 32 | | | | |
-------------------------------------------------------------------------------------------------------------------------
| | Grand Total | | | |