-
Notifications
You must be signed in to change notification settings - Fork 0
/
Student.cpp
127 lines (100 loc) · 2.62 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
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
// Student.cpp
// SP2022 CSC-134 Group Project
// Group 8
#include "Student.h"
#include <iomanip>
#include <iostream>
using namespace std;
// Taylor Sanderson
// Instructions from instructor:
// Define the member functions of class Student in Student.cpp:
// Initialize static variable number of students to 0 before defining any function.
int Student::numStudent = 0;
// Constructor without parameter
Student::Student()
{
// Initialize non-static data members to default initial value (string – “”, double – 0.0)
fName = "";
lName = "";
ssn = "";
for (int i = 0; i < 4; i++)
scores[i] = 0.0;
}
// Constructor with parameters
Student::Student(string _fName, string _lName, string _ssn, double _scores[4])
{
// Initialize non-static data members with the parameters.
fName = _fName;
lName = _lName;
ssn = _ssn;
for (int i = 0; i < 4; i++)
scores[i] = _scores[i];
// Update the static number of students by increasing 1.
numStudent++;
}
// Destructor
Student::~Student()
{
// Update the static number of students by decreasing 1.
numStudent--;
}
// Getter and setter function for each non-static data member.
string Student::getLName()
{
return lName;
}
string Student::getFName()
{
return fName;
}
string Student::getSSN()
{
return ssn;
}
double* Student::getScores()
{
double *ptr;
ptr = scores;
return ptr;
}
void Student::setLName(string _lName)
{
lName = _lName;
}
void Student::setFName(string _fName)
{
fName = _fName;
}
void Student::setSSN(string _ssn)
{
ssn = _ssn;
}
void Student::setScores(double _scores[4])
{
for (int i = 0; i < 4; i++)
scores[i] = _scores[i];
}
// Value-returning function to calculate and return the average of 4 exam scores.
double Student::averageScore()
{
double totalScore = 0.0;
for (int i = 0; i < 4; i++)
totalScore += scores[i];
return totalScore / 4;
}
// Void function to display student’s last name, first name, 4 exam scores and average score.
void Student::display()
{
cout << setw(14) << left << lName;
cout << setw(17) << left << fName;
cout << setw(16) << left << ssn;
for (int i = 0; i < 4; i++)
cout << setw(10) << right << showpoint << fixed << setprecision(1) << scores[i];
cout << setw(10) << right << showpoint << fixed << setprecision(1) << Student::averageScore() << endl;
}
// Value-returning function which returns the number of student object created.
int Student::getNumStudent()
{
return numStudent;
}
// Instructions unclear, made 2000 yew longbows on Oldschool Runescape. Can I turn these in for school credit?