Get the Rollno, Names and Marks Obtained of N students. The data should be stored in “RESULT” data file.
Use the same file to print the result along with aggregate percentage for all the students.
Use the same file to print the result along with aggregate percentage for all the students.
#include
#include
#include
class Cstud{
private:
char name[10];
int roll, marks;
public:
void getdata();
void putdata();
int calc() const;
};
void Cstud :: getdata(){
cout<<"\n Enter Name: ";
cin>>name;
cout<<"\n Enter Roll No: ";
cin>>roll;
cout<<"\n Enter Marks: ";
cin>>marks;
}
int Cstud :: calc() const{
return marks;
}
void Cstud :: putdata(){
cout<<"\n Name: "< cout<<"\n Roll No: "< cout<<"\n Marks: "< }
void main(){
int n, tot, avg;
Cstud Ostu1, Ostu2;
clrscr();
cout<<"\n How many Students: ";
cin>>n;
ofstream fout;
fout.open("result.txt", ios::out);
for(int i=0; i cout<<"\n Student No: "< Ostu1.getdata();
fout.write((char *) &Ostu1, sizeof(Ostu1));
}
fout.close();
ifstream fin;
fin.open("result.txt", ios::in);
tot = 0;
clrscr();
cout<<"\n Data read from File:- \n";
for(i=0; i fin.read((char *) &Ostu2, sizeof(Ostu2));
cout<<"\n\n Student No: "< Ostu2.putdata();
tot += Ostu2.calc();
}
avg = tot/n;
cout<<"\n\n Total marks: "< cout<<"\n\n Average Marks: "< fin.close();
getch();
}
#include
#include
class Cstud{
private:
char name[10];
int roll, marks;
public:
void getdata();
void putdata();
int calc() const;
};
void Cstud :: getdata(){
cout<<"\n Enter Name: ";
cin>>name;
cout<<"\n Enter Roll No: ";
cin>>roll;
cout<<"\n Enter Marks: ";
cin>>marks;
}
int Cstud :: calc() const{
return marks;
}
void Cstud :: putdata(){
cout<<"\n Name: "<
void main(){
int n, tot, avg;
Cstud Ostu1, Ostu2;
clrscr();
cout<<"\n How many Students: ";
cin>>n;
ofstream fout;
fout.open("result.txt", ios::out);
for(int i=0; i
fout.write((char *) &Ostu1, sizeof(Ostu1));
}
fout.close();
ifstream fin;
fin.open("result.txt", ios::in);
tot = 0;
clrscr();
cout<<"\n Data read from File:- \n";
for(i=0; i
cout<<"\n\n Student No: "< Ostu2.putdata();
tot += Ostu2.calc();
}
avg = tot/n;
cout<<"\n\n Total marks: "<
getch();
}
Comments
Post a Comment
share your thoughts ....