Answer to Question #204455 in C++ for Javeria

Question #204455

Create a class Students

•Data Members

•Students Name

•Student ID

•CGPA

•Department

•Member Functions


•Constructors / Destructors

•storeData // Reading from file

•fetchData // Writing into a file

•Driver


•Write 10 records in a file

•Read file contents from one file and store in another file

•Display file contents on screen


1
Expert's answer
2021-06-08T07:32:34-0400
#include<iostream>
#include<fstream>
#include<conio.h>
using namespace std;
class student
{
    int regNo;
    string name;
    float marks;
    public:
        void getData()
        {
        cout<<"\nEnter data: Roll no Name Marks\n";
        cin>>regNo>>name>>marks;
        }
        void display()
        {
        cout<<"\nRoll no\tName\tMarks\n";
        cout<<regNo<<"\t"<<name<<"\t"<<marks<<endl;
        }
};
int main()
    {
    fstream f;
    f.open("school.dat",ios::in|ios::out);
    student s;
    s.getData();
    f.write((char*)&s,sizeof(s));
    while(f.read((char*)&s,sizeof(s)));
        s.display();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog