You are viewing a single comment's thread. Return to all comments →
This is my code if inputs were lines of string: class Student{ public: vector scores; void input(); int calculateTotalScore(); };
void Student::input(){ string container; cin.ignore(); //delete the first "enter"
//Parse size_t start = 0; while(true){ string temp_container; size_t pos = container.find(' ', start); //When there's no "space" if (pos == string::npos){ temp_container = container.substr(start); scores.push_back(stoi(temp_container)); break; } //String parsing temp_container = container.substr(start, pos-start); start = pos + 1; scores.push_back(stoi(temp_container)); }
} int Student::calculateTotalScore(){ int total =0; for (int i=0; i
Seems like cookies are disabled on this browser, please enable them to open this website
Classes and Objects
You are viewing a single comment's thread. Return to all comments →
This is my code if inputs were lines of string: class Student{ public: vector scores; void input(); int calculateTotalScore(); };
void Student::input(){ string container; cin.ignore(); //delete the first "enter"
} int Student::calculateTotalScore(){ int total =0; for (int i=0; i