[404218]: / Code / C++ / C++ Tutorial Source Files / 37_C++_ObjectFunctions.cpp

Download this file

37 lines (27 with data), 621 Bytes

 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
#include <iostream>
using namespace std;
class Student {
public:
string name;
string major;
double gpa;
Student(string aName, string aMajor, int aGpa){
name = aName;
major = aMajor;
gpa = aGpa;
}
bool hasHonors(){
if(gpa >= 2.0){
return true;
}
return false;
}
};
int main()
{
Student student1("Jim", "Business", 2.4);
Student student2("Pam", "Art", 3.6);
cout << student1.hasHonors() << endl;
cout << student2.hasHonors() << endl;
return 0;
}