-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataStructuresStudent.cpp
78 lines (72 loc) · 2.07 KB
/
DataStructuresStudent.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
78
#include "DataStructuresStudent.h"
#include "Time.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
DataStructuresStudent::DataStructuresStudent() {
enterTime = 0;
numQuestions = numAwnsered = laptopSerialNum = 0;
firstName = lastName = " ";
}
void DataStructuresStudent::setTime(int minute) {
enterTime = Time(12, 00) + ((minute >= 0) ? minute : 0);
}
void DataStructuresStudent::setQuestions(int n) {
numQuestions = (n >= 0) ? n : 0;
}
void DataStructuresStudent::setAwnsered(int n) {
numAwnsered = (n >= 0) ? n : 0;
}
void DataStructuresStudent::setSerialNum(int serial) {
laptopSerialNum = (serial >= 0) ? serial : 0;
}
void DataStructuresStudent::setFirst(string first) {
firstName = (first.length() <= 20) ? first : "";
}
void DataStructuresStudent::setLast(string last) {
lastName = (last.length() <= 20) ? last : "";
}
Time DataStructuresStudent::getTime() {
return enterTime;
}
int DataStructuresStudent::getQuestions() {
return numQuestions;
}
int DataStructuresStudent::getAwnsered() {
return numAwnsered;
}
int DataStructuresStudent::getSerialNum() {
return laptopSerialNum;
}
string DataStructuresStudent::getFirst() {
return firstName;
}
string DataStructuresStudent::getLast() {
return lastName;
}
string DataStructuresStudent::getName() {
return firstName + " " + lastName;
}
bool DataStructuresStudent::isSatisfy() {
return numAwnsered == numQuestions;
}
float DataStructuresStudent::perc() {
return ((float) numAwnsered / (float) numQuestions);
}
bool DataStructuresStudent::operator == (DataStructuresStudent & d) {
return (getName() == d.getName()) && (d.laptopSerialNum == laptopSerialNum) && (numAwnsered == d.numAwnsered) && (numQuestions == d.numQuestions) && (enterTime == d.enterTime);
}
ostream & operator << (ostream & a, DataStructuresStudent s) {
cout << s.enterTime << " " << s.getName() << " " << s.numQuestions;
return a;
}
ifstream & operator >> (ifstream & f, DataStructuresStudent & s) {
int a;
f >> a;
s.setTime(a);
f >> s.firstName >> s.lastName;
f >> a;
s.setQuestions(a);
return f;
}