-
April 8th, 2010, 09:48 AM
#1
plz help me with virtual functions file handling code
here is the code
plz help me with the case 2 present in main...
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdlib.h>
class student
{
protected:
int rollno;
char name[50],degree;
public:
void virtual getdata()=0;
void virtual putdata()=0;
void virtual calresult()=0;
};
class acadmicublic student
{
protected:
int imk1,imk2,emk1,emk2;
float result;
public:
void getdata();
void putdata();
void calresult();
};
void acadmic::getdata()
{
cout<<"\n Enter Roll No:";
cin>>rollno;
cout<<"\n Enter Name:" ;
cin>>name;
cout<<"\n Enter Course:";
cout<<"\n E for Enginnering \n M for MCA:";
cin>>degree;
cout<<"\n Enter Internal Marks for test1 and test 2:" ;
cin>>imk1>>imk2;
cout<<"\n Enter Marks For Extrenal Test1 and Test 2:";
cin>>emk1>>emk2;
}
void acadmic:utdata()
{
cout<<"\n Roll No:"<<rollno;
cout<<"\n Name:"<<name;
cout<<"\n Course:"<<degree;
cout<<"\n Internal Marks";
cout<<"\n "<<imk1<<"\n "<<imk2;
cout<<"\n External Marks";
cout<<"\n "<<emk1<<"\n "<<emk2;
cout<<"\n The Result Is "<<result;
}
void acadmic::calresult()
{
result=(imk1+imk2+emk1+emk2)/4;
}
void main()
{
student *ptr;
acadmic a;
ptr=&a;
fstream file;
file.open("stud.txt",ios::in|ios:ut);//|ios::binary);
if(file==NULL)
{
cout<<"\nFile opening error....";
getch();
exit(1);
}
char ans;
do
{
clrscr();
cout<<"\n******** MENU ********\n\t1.Insert\n\t2.Display\n\t3.Search\n\t4.Modify\n\t5.Logical Delete\nEnter your choice?";
switch(getche())
{
case '1':
file.seekp(0,ios::end);
ptr->getdata();
ptr->calresult();
file.write((char *)ptr,sizeof(a));
file.clear();
break;
case '2': //DISPLAYING
file.seekg(0,ios::beg);
while(file)
{
file.read((char *)ptr,sizeof(a));
ptr->putdata();//wat is the reason that it ddnt work
//a.putdata(); //even this call works
}
//ptr->putdata(); //this works alone
file.clear();
break;
}
cout<<"\n Do you want to continue?";
ans=getche();
}while(ans=='y'||ans=='Y');
file.close();
cout<<"\nFile closed Successfully...";
}
thanks
Nilesh
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|