You are on page 1of 5

#include<fstream.

h>

#include<conio.h>

#include<stdio.h>

#include<stdlib.h>

class STOCK

int ITNO;

char name[20];

public:

void enter();

void show();

int retITNO()

{ return ITNO;}

};

void STOCK::enter()

cout<<"Enter the ITEM number : ";

cin>>ITNO;

cout<<"Enter the ITEM : ";

gets(name);

getch();

void STOCK::show()

cout<<"ITEM number : "<<ITNO<<endl;

cout<<" ITEM : "<<name<<endl;


getch();

void insert_r()

STOCK p;

ofstream outfile;

outfile.open("STOCK.DAT",ios::binary);

p.enter();

outfile.write((char*)&p,sizeof(p));

outfile.close();

cout<<"STOCK's record has been created ";

getch();

void display_r(int n)

STOCK p;

ifstream infile;

infile.open("STOCK.DAT",ios::binary);

if(!infile)

cout<<"ERROR.....The file does not exist......";

getch();

return;

int flag=0;

while(infile.read((char*)&p,sizeof(p)))

if(p.retITNO()==n)

{
p.show();

flag=1;

infile.close();

if(flag==0)

cout<<"Record does not exist";

getch();

void modify_r(int n)

STOCK p;

fstream file;

file.open("STOCK.DAT",ios::binary|ios::out|ios::in);

if(!file)

cout<<"File could not be open";

getch();

return;

while(file.read((char*)&p,sizeof(p)))

if(p.retITNO()==n)

p.show();

cout<<"Enter the new details: "<<endl;

p.enter();

int pos=(-1)*sizeof(p);

file.seekp(pos,ios::cur);
file.write((char*)&p,sizeof(p));

cout<<"\nrecord updated";

file.close();

void main()

{ clrscr();

char ch;

int num;

do{

cout<<"\n1.Create STOCK record";

cout<<"\n2.Display STOCK record";

cout<<"\n3.Modify STOCK record";

cout<<"\n4.Exit The Function";

cout<<"\nEnter your choice : ";

cin>>ch;

switch(ch)

case '1':insert_r();

break;

case '2':cout<<"Enter the ITEM number: ";

cin>>num;

display_r(num);

break;

case '3':cout<<"Enter the ITEM number: ";

cin>>num;

modify_r(num);

break;
case '4':cout<<"Exit the function :";

exit(0);

break;

}}while(num!=4);

getch();

You might also like