-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStudent.cpp
More file actions
51 lines (50 loc) · 1.24 KB
/
Student.cpp
File metadata and controls
51 lines (50 loc) · 1.24 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
//
// Student class
//
#include "Student.h"
#include <sstream>
Student::Student(const std::string dataString)
{
std::istringstream dstream(dataString);
std::string datum;
name = "Unknown";
avgScore = calledOnCount = numAbsences = 0;
if (std::getline(dstream, datum, ','))
name = datum;
if (std::getline(dstream, datum, ','))
calledOnCount = std::stoi(datum);
if (std::getline(dstream, datum, ','))
numAbsences = std::stoi(datum);
if (std::getline(dstream, datum, ','))
avgScore = std::stof(datum);
}
bool Student::selected(int selValue) const
{
if (selValue <= calledOnCount)
return true;
return false;
}
const std::string Student::displayString() const
{
return name;
}
int Student::calls() const
{
return calledOnCount;
}
const std::string Student::saveString() const
{
return name + "," + std::to_string(calledOnCount) + "," +
std::to_string(numAbsences) + "," + std::to_string(avgScore);
}
bool Student::countResponse(int response)
{
calledOnCount++;
if (response == 0) {
numAbsences++;
return true;
}
double oldTotal = avgScore * (calledOnCount - 1);
avgScore = (oldTotal + response) / (double) calledOnCount;
return true;
}