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;
}
#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;
}
Comments
Leave a comment