📄 teststudent.cpp
字号:
#include <iostream>
#include <string>
using namespace std;
#include "prompt.h"
class Student
{
public:
Student(const string& name);
void RespondTo( /* question needed here */);
int Score() const;
string Name() const;
private:
string myName;
int myCorrect;
};
Student::Student(const string& name)
: myName(name),
myCorrect(0)
{
// initializer list does the work
}
void Student::RespondTo( /* question needed here */)
{
string answer;
cout << "type answer after question " << endl << endl;
cout << "what is your favorite color? ";
cin >> answer;
if (answer == "blue")
{ cout << "that is correct" << endl;
myCorrect++;
}
else
{ cout << "No! your favorite color is blue" << endl;
}
}
int Student::Score() const
{
return myCorrect;
}
string Student::Name() const
{
return myName;
}
int main()
{
string name = PromptString("enter name: ");
int numQuest = PromptRange("number of questions: ",1,10);
Student st(name);
int k;
for(k=0; k < numQuest; k++)
{ st.RespondTo(); // question parameter missing
}
cout << st.Name() << ", your score is "
<< st.Score() << " out of " << numQuest << endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -