Task 1 — Read the Student class
- Find the private data members name and score. Find the constructor and show(). Run the starter; it will not display student information until the TODOs are completed.
WEEK 10 · LAB 4
Create two student objects and display their information.
Week 9: std::string, public and private members, constructors, and const member functions. A constructor sets up an object; show() const displays its data without changing its data members.
Complete the TODOs in the starter code, then compare your result with the expected output. The starter is intentionally unfinished.
#include <iostream>
#include <string>
class Student {
private:
std::string name;
int score = 0;
public:
Student(std::string studentName, int studentScore) {
// TODO 1: Set name and score.
}
void show() const {
// TODO 2: Print name and score.
}
};
int main() {
Student first("Alex", 85);
Student second("Sam", 92);
first.show();
second.show();
return 0;
}
Expected output after completing both TODOs.
Alex 85
Sam 92