Classes and Objects

  • + 0 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