#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<iomanip.h>
class inventory
{
char name[10];
int code;
float cost;
public:
void getdata()
{
cout<<"ENTER NAME:";
cin>>name;
cout<<"ENTER CODE:";
cin>>code;
cout<<"ENTER COST:";
cin>>cost;
}
void putdata()
{
cout<<"NAME:-"<<name<<endl;
cout<<"CODE:-"<<code<<endl;
cout<<"COST:-"<<cost<<endl;
}
};
int main()
{
inventory item;
fstream a;
a.open("stock.txt",ios::ate|ios::in||ios::out||ios::binary);
cout<<"enter the current stock";
item.getdata();
char ch;
cin.get(ch);
a.seekg(0);
a.write((char *)&item, sizeof(item));
//a.close();
//ifstream q;
//q.read((char*)&item, sizeof(item));
item.putdata();
int last=a.tellg();
int n=last/sizeof(item);
cout<<a.tellg()<<endl<<sizeof(item)<<endl;
cout<<"NUMBER OF OBJECTS:-"<<n<<"\n";
cout<<"TOTAL BYTES:-"<<last<<"\n";
cout<<"enter object number to be updated\n";
int object;
cin>>object;
cin.get(ch);
int location=(object-1)*sizeof(item);
/*if(a.eof())
a.clear();*/
a.seekp(location);
cout<<"Enter the new values";
item.getdata();
cin.get(ch);
a.write((char*) &item, sizeof(item));
a.seekg(0);
cout<<"update file";
item.putdata();
a.close();
return 0;
}
for more Codes you can visit http://codesofprogramming.blogspot.in/
#include<conio.h>
#include<fstream.h>
#include<iomanip.h>
class inventory
{
char name[10];
int code;
float cost;
public:
void getdata()
{
cout<<"ENTER NAME:";
cin>>name;
cout<<"ENTER CODE:";
cin>>code;
cout<<"ENTER COST:";
cin>>cost;
}
void putdata()
{
cout<<"NAME:-"<<name<<endl;
cout<<"CODE:-"<<code<<endl;
cout<<"COST:-"<<cost<<endl;
}
};
int main()
{
inventory item;
fstream a;
a.open("stock.txt",ios::ate|ios::in||ios::out||ios::binary);
cout<<"enter the current stock";
item.getdata();
char ch;
cin.get(ch);
a.seekg(0);
a.write((char *)&item, sizeof(item));
//a.close();
//ifstream q;
//q.read((char*)&item, sizeof(item));
item.putdata();
int last=a.tellg();
int n=last/sizeof(item);
cout<<a.tellg()<<endl<<sizeof(item)<<endl;
cout<<"NUMBER OF OBJECTS:-"<<n<<"\n";
cout<<"TOTAL BYTES:-"<<last<<"\n";
cout<<"enter object number to be updated\n";
int object;
cin>>object;
cin.get(ch);
int location=(object-1)*sizeof(item);
/*if(a.eof())
a.clear();*/
a.seekp(location);
cout<<"Enter the new values";
item.getdata();
cin.get(ch);
a.write((char*) &item, sizeof(item));
a.seekg(0);
cout<<"update file";
item.putdata();
a.close();
return 0;
}
for more Codes you can visit http://codesofprogramming.blogspot.in/
No comments:
Post a Comment