-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClassRoom.cpp
179 lines (141 loc) · 4.13 KB
/
ClassRoom.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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// ClassRoom.cpp
// SP2022 CSC-134 Group Project
// Group 8
#include "ClassRoom.h"
#include <iostream>
#include <fstream>
using namespace std;
// Mason Scarbro:
// Instructions from instructor:
// Define the member functions of class ClassRoom in ClassRoom.cpp:
// Constructor with 1parameter
// Requests classroom’s name as parameter.
ClassRoom::ClassRoom(string _className)
{
className = _className; // Initialize classroom name with parameter value.
numOfStudent = 0; // Initialize number of students as 0.
}
ClassRoom::~ClassRoom()
{
}
// Getter and setter function for each data member.
string ClassRoom::getClassName()
{
return className;
}
int ClassRoom::getNumOfStudent()
{
return numOfStudent;
}
Student* ClassRoom::getStudentArray()
{
Student* ptr;
ptr = studentArray;
return ptr;
}
void ClassRoom::setClassName(string _className)
{
className = _className;
}
void ClassRoom::setNumOfStudent(int _numOfStudent)
{
numOfStudent = _numOfStudent;
}
void ClassRoom::setStudentArray(Student _studentArray[], int _numStudent)
{
for (int i = 0; i < _numStudent; i++) studentArray[i] = _studentArray[i];
}
// Void function which creates an array of Student objects by reading student data from input data file.
void ClassRoom::popArray(string _inFileName)
{
string fName, lName, ssn;
double scores[4];
ifstream _inFile;
_inFile.open(_inFileName);
while (_inFile >> lName >> fName >> ssn)
{
// Create a Student object by reading student record from the data file.
for (int i = 0; i < 4; i++)
{
_inFile >> scores[i];
}
Student student(fName, lName, ssn, scores);
// Add the student object in an array of Student.
studentArray[numOfStudent] = student;
// Count the number of student objects created.
numOfStudent++;
}
}
// Norma Hernandez-Cruz from this point:
//calculate number of students
int ClassRoom::numOfStudentsInClass()
{
int numOfStudents;
numOfStudents = Student::getNumStudent();
return numOfStudents;
}
// Void function which sorts array of student objects by student average score.
// Need to compare each student’s average score.
// May use the selection sorting code or other sorting algorithm.
void ClassRoom::sortArrayByAvg()
{
// Sort the array of student objects by student average score.
for (int i = 0; i < numOfStudent; i++)
{
for (int j = 0; j < numOfStudent - 1; j++)
{
if (studentArray[j].averageScore() > studentArray[j + 1].averageScore())
{
Student temp = studentArray[j];
studentArray[j] = studentArray[j + 1];
studentArray[j + 1] = temp;
}
}
}
}
// Void function which sorts array of student objects by student last name.
// Need to compare each student’s last name.
// May use the selection sorting code or other sorting algorithm.
void ClassRoom::sortArrayByLName()
{
//int index;
Student tempStudent;
for (int i = 0; i < numOfStudent; i++)
{
for (int n = 0; n < numOfStudent; n++)
{
if (studentArray[i].getLName() < studentArray[n].getLName())
{
tempStudent = studentArray[i];
studentArray[i] = studentArray[n];
studentArray[n] = tempStudent;
}
}
}
}
// Value-returning function which calculates and returns the average score of all students.
// average score = total of student’s average score / number of students
double ClassRoom::calcAvg()
{
double classAverage;
classAverage = 0.0;
for (int i = 0; i < numOfStudent; i++)
{
classAverage = (classAverage + studentArray[i].averageScore());
}
classAverage = (classAverage / numOfStudent);
return classAverage;
}
// Void function which displays last name, first name, 4 exam scores and average score for all students.
// All students’ information should be displayed using this format:
// An image is included in the original document, please refer there for it
void ClassRoom::displayStudentData()
{
cout << setfill(' ') << "Last Name" << setw(15) << "First Name" << setw(10) << "SSN" << setw(25) << "Score 1" << setw(10) << "Score 2" << setw(10) << "Score 3" << setw(10) << "Score 4" << setw(10) << "Average" << endl;
cout << setfill('-') << setw(100) << "" << endl;
cout << setfill(' ') << endl;
for (int i = 0; i < numOfStudent; i++)
{
studentArray[i].display();
}
}