forked from Dashark/hello-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Student.cpp
52 lines (51 loc) · 1.13 KB
/
Student.cpp
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
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Student {
public:
Student(string &fn, string &ln, char s):sex(s) {
firstname = fn;
lastname = ln;
gpa = 0.0f;
grade = 1;
}
Student(const char fn[], const char ln[], char s):firstname(fn), lastname(ln), sex(s) {
gpa = 0.0f;
grade = 1;
}
~Student() {
}
//method
void show_myself() {
std::cout << firstname << lastname << sex << grade << gpa << std::endl;
}
void study_time(int study_time) {
gpa = gpa + log(study_time);
gpa = gpa > 4.0f ? 4.0f : gpa;
}
int upgrade() {
int tmp = this->grade;
this->grade += 1;
this->grade = grade > 4 ? 4 : grade;
return tmp;
}
private:
float gpa;
std::string firstname, lastname;
char sex;
int grade;
};
int main() {
char buffer[5][100]={{"Mike", "Barnes", 'M'},{"Jim", "Nickerson", 'F'}}
string fn("Mike"), ln("Barnes");
Student st1(fn, ln, 'M'), st2("Jim", "Nickerson", 'F');
std::vector<Student> student_list;
student_list.push_pack(st1);
st1.upgrade();
st1.study_time(60);
st2.study_time(1000);
st1.show_myself();
st2.show_myself();
return 0;
}