-
Notifications
You must be signed in to change notification settings - Fork 1
/
student.cpp
77 lines (71 loc) · 1.68 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
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
#include <iostream>
#include "student.h"
#include <cstring>
using namespace std;
Student::Student(const char* first, const char* last, int fn, double grade) : firstName(NULL), lastName(NULL) {
setFirstName(first);
setLastName(last);
setFN(fn);
setGrade(grade);
}
Student::~Student() {
delete[] firstName;
delete[] lastName;
}
void Student::setFirstName(const char* value) {
if(firstName != NULL) {
delete[] firstName;
}
firstName = new char[sizeof(value)/sizeof(char)];
strcpy(firstName, value);
}
void Student::setLastName(const char* value) {
if(lastName != NULL) {
delete[] lastName;
}
lastName = new char[sizeof(value)/sizeof(char)];
strcpy(lastName, value);
}
void Student::setFN(const int value) {
fn = value;
}
void Student::setGrade(const double value) {
grade = value;
}
char* Student::getFirstName() const {
return firstName;
}
char* Student::getLastName() const {
return lastName;
}
int Student::getFN() const {
return fn;
}
double Student::getGrade() const {
return grade;
}
ostream& operator<<(ostream& o, const Student& s) {
o<<s.getFN()<<":"<<s.getFirstName()<<" "<<s.getLastName()<<":"<<s.getGrade()<<endl;
return o;
}
istream& operator>>(istream& i, Student& s) {
int fn;
double grade;
char nameBuffer[100];
i>>fn;
s.setFN(fn);
i.get();
i.getline(nameBuffer, 100, ' ');
cout<<nameBuffer<<endl;
s.setFirstName(nameBuffer);
i.getline(nameBuffer, 100, ':');
cout<<nameBuffer<<endl;
s.setLastName(nameBuffer);
i>>grade;
if(i.peek() == 10) {
i.get();
}
cout<<grade<<endl;
s.setGrade(grade);
cout<<i.peek()<<endl;
}