#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class item
{
public:
cha name[10];
int code;
float cost;
void getdata()
{
cout<<"\n Enter the name:";
cin>>name;
cout<<"\n Enter the code:";
cin>>code;
cout<<"\n Enter the cost:";
cin>>cost;
}
void putdata()
{
cout<<"\n Name:"<<name;
cout<<"\n Code:"<<code;
cout<<"\n Cost:"<<cost<<"\n";
}
};
void main()
{
int n;
char ch;
item itemrec;
ofstream fileobj;
clrscr();
cout<<"\n INVENTORY FILE";
cout<<"\n ----------------";
fileobj.open("inven.dat",ios::binary|ios::out);
cout<<"\n Enter the No of Records:";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"\n Product:"<<i+1<<"\n";
itemrec.getdata();
fileobj<<itemrec.name<<"\t";
fileobj<<itemrec.cost<<"\t";
fileobj<<itemrec.code<<"\t";
}
fileobj.close();
cout<<"\n Result:";
cout<<"\n ------";
ifstream fileobj1;
fileobj1.open("inven.dat",ios::in|ios::binary);
while(fileobj1)
{
fileobj1.get(ch);
cout<<ch;
}
fileobj1.close();
getch();
}
--------------
OUTPUT:
--------------
INVENTORY FILE
*****************
Enter the No of Records :2
Product :1
Enter the name:PAPER
Enter the code :420
Enter the cost :250
Product:2
Enter the name:PEN
Enter the code :145
Enter the cost :500
Result:
******
PAPER 250 420 PEN 500 145
D:\TC>TYPE INVEN.DAT
PAPER 250 420 PEN 500 145
#include<conio.h>
#include<fstream.h>
class item
{
public:
cha name[10];
int code;
float cost;
void getdata()
{
cout<<"\n Enter the name:";
cin>>name;
cout<<"\n Enter the code:";
cin>>code;
cout<<"\n Enter the cost:";
cin>>cost;
}
void putdata()
{
cout<<"\n Name:"<<name;
cout<<"\n Code:"<<code;
cout<<"\n Cost:"<<cost<<"\n";
}
};
void main()
{
int n;
char ch;
item itemrec;
ofstream fileobj;
clrscr();
cout<<"\n INVENTORY FILE";
cout<<"\n ----------------";
fileobj.open("inven.dat",ios::binary|ios::out);
cout<<"\n Enter the No of Records:";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"\n Product:"<<i+1<<"\n";
itemrec.getdata();
fileobj<<itemrec.name<<"\t";
fileobj<<itemrec.cost<<"\t";
fileobj<<itemrec.code<<"\t";
}
fileobj.close();
cout<<"\n Result:";
cout<<"\n ------";
ifstream fileobj1;
fileobj1.open("inven.dat",ios::in|ios::binary);
while(fileobj1)
{
fileobj1.get(ch);
cout<<ch;
}
fileobj1.close();
getch();
}
--------------
OUTPUT:
--------------
INVENTORY FILE
*****************
Enter the No of Records :2
Product :1
Enter the name:PAPER
Enter the code :420
Enter the cost :250
Product:2
Enter the name:PEN
Enter the code :145
Enter the cost :500
Result:
******
PAPER 250 420 PEN 500 145
D:\TC>TYPE INVEN.DAT
PAPER 250 420 PEN 500 145
0 comments:
Post a Comment