Skip to content

Commit

Permalink
Include header and remove unneeded arguments from constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
aisair committed Feb 23, 2024
1 parent 9b75f67 commit 80e649e
Showing 1 changed file with 14 additions and 48 deletions.
62 changes: 14 additions & 48 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>

struct Person {
std::string first_name;
Expand All @@ -10,12 +11,11 @@ struct Person {
float zscore;
Person() : first_name(), last_name(), score() {}
Person(std::string first, std::string last, int score) : first_name(first),
last_name(last), score(score), deviation(0.0f), zscore(0.0f) {}
last_name(last), score(score) {}
};

std::vector<Person> initPeople();
void swap(int& first1, int& first2, std::string& last1, std::string& last2,
std::string& lname1, std::string& lname2);
void swap(int& first1, int& first2, std::string& last1, std::string& last2, std::string& lname1, std::string& lname2);
void sortArray();
float calcMean();
int calcMode();
Expand All @@ -41,6 +41,7 @@ int main(){
std::string temp;

auto students = initPeople();
numpeople = students.size();
sortArray();
mean = calcMean();
mode = calcMode();
Expand All @@ -57,63 +58,28 @@ int main(){
std::vector<Person> initPeople(){
std::vector<Person> students;
while (true) {
printf("enter first and last name (separated by a space) of person %d (leave blank to stop)\n", (students.size() + 1));
std::string name_temp;
std::getline(std::cin, name_temp);
if ((students.size() + 1) > 1 && name_temp.empty()) {break;}
std::cout << "enter first and last name (separated by a space) of person " << students.size() + 1 << " (leave blank to stop)" << std::endl;
std::string name_input;
std::getline(std::cin, name_input);
if (students.size() > 0 && name_input.empty()) break;
Person stu;
int idx = name_temp.find_last_of(' ');
stu.first_name = name_temp.substr(0, idx);
stu.last_name = name_temp.substr(idx + 1, std::string::npos);
int idx = name_input.find_last_of(' ');
stu.first_name = name_input.substr(0, idx);
stu.last_name = name_input.substr(idx + 1, std::string::npos);

do {
std::cout << "enter score for " << stu.first_name << " " << stu.last_name << std::endl;
std::string score_str;
std::getline(std::cin, score_str);
stu.score = std::stoi(score_str);
if (stu.score < 0) {printf("score cannot be less than zero\n");}
}
while (stu.score < 0);
if (stu.score < 0) printf("score cannot be less than zero\n");
} while (stu.score < 0);

students.push_back(stu);
}
numpeople = students.size();
return students;
}

// void initPeople(){
// while(!stop){
// int restart = 1;
// while(restart == 1){
// restart = 0;

// std::cout << "Please enter name of person " << i_person << " (enter END to stop) : ";
// std::cin >> temp >> temp1;
// if(temp == "END"){
// stop = 1;
// restart = 0;
// }
// else{
// names[i_person] = temp;
// lnames[i_person] = temp1;

// std::cout << "Please enter score of person " << i_person << ": ";
// std::cin >> scores[i_person];

// if(scores[i_person] < 0){
// std::cout << "The score for " << names[i_person] << ' ' << lnames[i_person] << " is " << scores[i_person] << " which cannot be less than zero.";
// restart = 1;
// }
// else{
// std::cout << "The persons name is " << names[i_person] << ' ' << lnames[i_person] << " and they have a score of " << scores[i_person] << '.' << std::endl;
// }
// numpeople++;
// }
// }
// i_person++;
// }
// }

void sortArray(){
std::cout << "Sort initialized." << std::endl;
int num = 0;
Expand Down Expand Up @@ -253,4 +219,4 @@ void print(float mean, int mode, float gmean, float median){

float round(float n, int place){
return round(n * place) / place;
}
}

0 comments on commit 80e649e

Please sign in to comment.