-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudenti.cpp
71 lines (63 loc) · 1.21 KB
/
studenti.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
// studenti.cpp -- Student class using private inheritance
#include "studenti.h"
using std::ostream;
using std::endl;
using std::istream;
using std::string;
// public methods
double Student::Average() const
{
if (ArrayDb::size() > 0) {
return ArrayDb::sum()/ArrayDb::size();
} else {
return 0;
}
}
const string & Student::Name() const
{
return (const string &) *this;
}
double & Student::operator[](int i)
{
return ArrayDb::operator[](i);
}
double Student::operator[](int i) const
{
return ArrayDb::operator[](i);
}
ostream & Student::arr_out(ostream & os) const
{
int i;
int lim = ArrayDb::size();
if (lim > 0) {
for (i = 0; i < lim; i++) {
os << ArrayDb::operator[](i) << " ";
if (i % 5 == 4) {
os << endl;
}
}
if (i % 5 != 0) {
os << endl;
}
} else {
os << " empty array ";
}
return os;
}
// use string version of operator>>()
istream & operator>>(istream & is, Student & stu)
{
is >> (string &)stu;
return is;
}
istream & getline(istream & is, Student & stu)
{
getline(is, (string &)stu);
return is;
}
ostream & operator<<(ostream & os, const Student & stu)
{
os << "Scores for " << (const string &)stu << ":\n";
stu.arr_out(os); // use private method for scores
return os;
}