-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc.cpp
More file actions
161 lines (135 loc) · 2.72 KB
/
Copy pathc.cpp
File metadata and controls
161 lines (135 loc) · 2.72 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
class Student
{
public:
Student();
Student(const Student & student);
~Student();
void set(const int uaid, const string name, const double gpa);
void get(int & uaid, string & name, double & gpa) const;
void print() const;
void read();
private:
int mUaid;
string mName;
double mGpa;
};
Student::Student()
{
mUaid = 0;
mName = "none";
mGpa = 0.0;
}
Student::Student(const Student & student)
{
mUaid = student.mUaid;
mName = student.mName;
mGpa = student.mGpa;
}
Student::~Student()
{
}
void Student::set(const int uaid, const string name, const double gpa)
{
mUaid = uaid;
mName = name;
mGpa = gpa;
if (mGpa < 0.0) mGpa = 0.0;
else if (mGpa > 4.0) mGpa = 4.0;
}
void Student::get(int &uaid, string & name, double &gpa) const
{
uaid = mUaid;
name = mName;
gpa = mGpa;
}
void Student::print() const
{
cout << mUaid << " " << mName << " " << mGpa << endl;
}
void Student::read()
{
cin >> mUaid >> mName >> mGpa;
if (mGpa < 0.0) mGpa = 0.0;
else if (mGpa > 4.0) mGpa = 4.0;
}
class Course
{
public:
Course(const int count=0);
Course(const Course & course);
~Course();
void print() const;
void read();
void topStudents(const double sGpa);
private:
static const int MAX_STUDENTS = 100;
Student mStudents[MAX_STUDENTS];
int mNumStudents;
};
void Course::print() const
{
cout << "Print" << endl;
for (int index = 0; index < mNumStudents; index++)
{
mStudents[index].print();
// Do some work
}
}
void Course::read()
{
cout << "Read" << endl;
for (int index = 0; index < mNumStudents; index++)
{
mStudents[index].read();
}
}
Course::Course(const int count)
{
cout << "Constructor" << endl;
mNumStudents = count;
}
Course::Course(const Course & course)
{
mNumStudents = course.mNumStudents;
cout << "Copy constructor" << endl;
for (int index = 0; index < mNumStudents; index++)
{
mStudents[index] = course.mStudents[index];
// Do some work
}
}
Course::~Course()
{
cout << "Destructor" << endl;
}
void Course::topStudents(const double sGpa)
{
cout << "topStudents" << endl;
for (int index = 0; index < mNumStudents; index++)
{
int tInt;
string tString;
double tGpa;
mStudents[index].get(tInt, tString, tGpa);
if(tGpa >= sGpa)
mStudents[index].print();
}
}
int main()
{
cout << "Testing Student class\n";
Student student1;
student1.set(1234, "John", 2.5);
student1.print();
cout << "Testing Course class\n";
Course course(5);
course.print();
course.read();
course.print();
course.topStudents(3.5);
return 0;
}