Questionnaire Type Program in C++ with 3 items of questions. When the user finish answering the 3 items of questions, the program will compute the total number of correct and wrong answer(s). Then, the program will ask if the user want to take the examination again. If the user did not want to take examination again, the program will end/stop with oop loop and arrays
#include <iostream> #include <string> using namespace std; class Question{ int answer[3]; int correct,wrong; double a,b,c; double sc = 0; double wsc = 0; public: int name, age; void studentInfo(); void getAnswerQuestion(); void displayAnswerQuestionInfo(); }; void Question:: studentInfo(){ cout<<"Enter your Name: "; cin>>name; } void Question:: getAnswerQuestion(){ char answer; for(int x=0;x<=2;x++){ cout<<"What is 1 + 1 :"; cout<<"\na. 2"; cout<<"\nb. 3"; cout<<"\nc. 5"; cin>>answer; if (x=='a'||x=='A'){sc=sc+1;} else {wsc=wsc+1;} cout<<"\nWhat is 2 + 1 ? :" ; cout<<"\na. 2"; cout<<"\nb. 3"; cout<<"\nc. 5"; cin>>answer; if (x=='b'||x=='B'){sc=sc+1;} else {wsc=wsc+1;} cout<<". \nWhat is 2 + 4 ?: "; cout<<"\na. 2"; cout<<"\nb. 3"; cout<<"\nc. 6"; cin>>answer; if (x=='c'||x=='C'){sc=sc+1;} else {wsc=wsc+1;} } } void Question:: displayAnswerQuestionInfo(){ cout<<"Name: "<<name<<endl; cout<<"Age: "<<age<<endl; cout<<" "<<endl; cout<<"Your Correct score is: "<<+sc<<endl; cout<<"Your Incorrect score is : "<<+wsc<<endl; } int main(){ Question qashinfo; qashinfo.studentInfo(); qashinfo.getAnswerQuestion(); qashinfo.displayAnswerQuestionInfo();
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.
studentInfo
age
displayAnswerQuestionInfo
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)