-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha.cpp
More file actions
100 lines (83 loc) · 1.63 KB
/
Copy patha.cpp
File metadata and controls
100 lines (83 loc) · 1.63 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
#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()
{
cout << "Constructor" << endl;
mUaid = 0;
mName = "none";
mGpa = 0.0;
}
Student::Student(const Student & student)
{
cout << "Copy constructor" << endl;
mUaid = student.mUaid;
mName = student.mName;
mGpa = student.mGpa;
}
Student::~Student()
{
cout << "Destructor" << endl;
}
void Student::set(const int uaid, const string name, const double gpa)
{
cout << "Set" << endl;
mUaid = uaid;
mName = name;
if(gpa < 0)
mGpa = 0.0;
if(gpa > 4.0)
mGpa = 4.0;
}
void Student::get(int & uaid, string & name, double & gpa) const
{
cout << "Get" << endl;
uaid = mUaid;
name = mName;
gpa = mGpa;
}
void Student::print() const
{
cout << "Print" << endl;
cout << mUaid << " " << mName << " " << mGpa << endl;
}
void Student::read()
{
cout << "Read" << endl;
cin >> mUaid >> mName >> mGpa;
if(mGpa < 0)
mGpa = 0.0;
if(mGpa > 4.0)
mGpa = 4.0;
}
int main()
{
cout << "Testing Student class\n";
Student student1;
student1.set(1234, "John", 2.5);
student1.print();
Student student2(student1);
student2.print();
student2.set(2345, "Susan", 3.9);
student2.print();
Student student3;
student3.read();
student3.print();
return 0;
}