Answer to Question #184274 in C++ for Bilal

Question #184274

Comment this code line by line

include <iostream>
 
#include <fstream>
 
#include <string>
 
 
using namespace std;
 
 
class Student
 
{
 
public:
 
    Student(string fileName);
 
    Student();
 
    string GetName() { return name; }
 
    string GetRoll() { return roll; }
 
    int GetGPA() { return GPA; }
 
    double GetCreditHours() { return creditHours; }
 
private:
 
    string name;
 
    string roll;
 
    int GPA;
 
    double creditHours;
 
};
 
 
Student::Student()
 
{
 
    cout << "Enter name: ";
 
    cin >> name;
 
    cout << "Enter roll: ";
 
    cin >> roll;
 
    cout << "Enter GPA: ";
 
    cin >> GPA;
 
    cout << "Enter credit hours: ";
 
    cin >> creditHours;
 
}
 
 
Student::Student(string fileName)
 
{
 
    fstream fin;
 
    fin.open(fileName);
 
    if (!fin)
 
    {
 
        cout << "File not found!" << endl;
 
        return;
 
    }
 
    fin >> name >> roll >> GPA >> creditHours;
 
}
1
Expert's answer
2021-04-28T23:28:11-0400
#include <iostream>

#include <fstream>

#include <string>


using namespace std;
//define student class

class Student

{

public:

 //parametrised constructor
    Student(string fileName);

 //default constructor
    Student();

 //define getter function
    string GetName() { return name; }

    string GetRoll() { return roll; }

    int GetGPA() { return GPA; }

    double GetCreditHours() { return creditHours; }

//define variables
private:

    string name;

    string roll;

    int GPA;

    double creditHours;

};


Student::Student()

{

    cout << "Enter name: ";

    cin >> name;

    cout << "Enter roll: ";

    cin >> roll;

    cout << "Enter GPA: ";

    cin >> GPA;

    cout << "Enter credit hours: ";

    cin >> creditHours;

}


Student::Student(string fileName)

{

    fstream fin;

    fin.open(fileName);

    if (!fin)

    {

        cout << "File not found!" << endl;

        return;

    }

    fin >> name >> roll >> GPA >> creditHours;

}
int main(){
Student s;

return 0;
}


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
APPROVED BY CLIENTS