Part 1:
Write a class called (Student) which contains the following data members:
- Private members:
• First name (as a string).
• Last Name (as a string).
• GPA (as a double).
• ID (as an integer).
- Public members:
• A default constructor that will assign all the private data to its default values (ID = 0, GPA = 0.00, First and last name should be equal to an empty string).
• All the accessors and mutators functions (set and get functions) for the previous private members. Make sure you validate the gpa (the GPA should not exceed 4.00, if it does then assign it to its default value).
• A function that prints the student’s data as the following:
Name: First_Name Last_Name
ID: Student’s_ID
GPA: Current_GPA
Note: Divide your code into three different files (header, implementation, main).
Part 2:
Write a main program that contains 3 students, read their information from a file (called data.txt) and store them into the objects. Then your program should print the information of the students with the highest GPA and check if he’s an honored student or not (if GPA is greater than or equal to 3.67 then he’s an honored student).
So how read their information from a file (called data.txt) and store them into the objects ??
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include "student.h"
#include<fstream>
int main()
{
student s1,s2,s3;
ifstream in;
in.open ("Data.txt");
s1.
return 0;
}
|
#include <iostream>
using namespace std;
class student
{
private:
string fname;
string lname;
int id;
double gpa;
public:
student();
student(string,string, int, int);
~student();
void setFname(string);
string getLname();
void setLname(string);
string getLname();
void setID(int);
int getID();
void setGPA(double);
double getGPA();
void print();
void honorList();
};
student::student()
{
fname = " ";
lname=" ";
id = 0;
gpa = 0.0;
}
student::student(string f,string l, int a, double g)
{
setFname(f);
setLname(l);
setID(a);
setGPA(g);
}
void student::seFname(string f)
{
if(s.length() >= 2)
fname = f;
}
string student::getFname()
{
return fname;
}
void student::setLname(int l)
{
lname = l;
}
int student::getLname()
{
return lname;
}
void student::setGPA(double g)
{
if(g >= 0 && g <= 4)
gpa = g;
}
double student::getGPA()
{
return gpa;
}
void student::print()
{
cout << "Name: " << fname << lname<<endl;
cout << "ID " << id << endl;
cout << "GPA: " << gpa << endl;
}
/* should be in the main
void student::honorList()
{
if (gpa >= 3.5)
cout << name << " is on the honor list" << endl;
else
cout << name << " is NOT on the honor list" << endl;
}*/
|