Answer to Question #277784 in C++ for Michael Parenas

Question #277784

Create a c++ quiz program, in this program it has a 10 questions that the user will answer. The program has the following functions:




A. It will show the message (Correct) if the the answer is correct and (Wrong) if the answer is wrong




B. It can compute the total score




C. If the user Failed in the quiz it will ask the user if he wants to retake the quiz. ( 6 is the passing rate)




C1.1If he select Yes he will take the quiz again.




C1.2. If he select No the program will automatically closed.




Extra 10 points: use system(“clear”) to clear the the previous data in the screenx

1
Expert's answer
2021-12-10T00:36:27-0500
#include<iostream>
#include<string>
using namespace std;


int Guess;
int Total;


class Question;
{
	private:
		string Question_Text;
		string Answer_1;
		string Answer_2;
		string Answer_3;
		string Answer_4;
		
		int Correct_Answer;
		int Question_Score;
		
		public:
			void setValues(string, string, string, string, string, int, int);
			void askQuestion( );	
};




int main(){
   
   cout<<"\nWELCOME TO QUESTION ANSWER TEST. ";
   cout<<"\nPress Enter key to start the test";
   cin.get();
   
   string Name;
   int Age;
   
   cout<<"\nWhat is your name?";
   cin>>Name;
   
   cout<<"\nWhat is your Age?";
   cin>>Age;
   
   cout<<endl;
   
   string Respond;
    
    cout<<"\n Are you ready for the test"<<	Name<<" ? Yes/No";
    cin>>Respond;
    
    if(Respond == "yes"){
    	
    	cout<<endl;
    	cout<<"\nGood luck in your test!";
	}
	else {
		
		cout<<"\nGoodbye, welcome next time";
		return 0;
	}
   
     Question q1;
     Question q2;
     Question q3;
     Question q4;
     Question q5;
     Question q6;
     Question q7;
     Question q8;
     Question q9;
     Question q10;
     
     
     q1.setValue("What is the only function all c++ program must have?",
	 
	              "start()",
	              "system ()",
	              "main()",
	              "program ()",
	              3,
	              10);
	              
	    
      q2.setValue("Which of the following is the correct comment to use?",
	 
	              "*/ comments */",
	              "/* comments */",
	              "** comments **",
	              "()comments)",
	              2,
	              10);
	              
	  q3.setValue("the statement i++; is equivalent to?",
	 
	              "i = i+i",
	              "i = i+1",
	              "i = i-1",
	              "i--",
	              2,
	              10);
	              
	    q4.setValue("In C++, 14%4 = ?",
	 
	              "3",
	              "1",
	              "4",
	              "2",
	              4,
	              10);     
				  
	   q5.setValue("When a datatype must contain decimal numbers, assign the type",
	 
	              "int",
	              "char",
	              "double",
	              "long int",
	              3,
	              10);   
				  
		q6.setValue("the name of a variable is known as its?",
	 
	              "identifier",
	              "constant",
	              "data type",
	              "base",
	              1,
				  10);	
				  
		q7.setValue("in int main(), what does the int stand for?",
	 
	              "initialize",
	              "integer",
	              "inheritance",
	              "nothing",
	              2,
				  10);	
				  
		q8.setValue("The relational operator for equal is?",
	 
	              "=",
	              "/=",
	              "=/",
	              "==",
	              4,
				  10);	
				  
		q9.setValue("Which of the folowing is true",
	 
	              "All objects of the class share all data members of a class",
	              "Objects of a class do not share non-static members",
	              "objects of a class do not share codes of a non-static methods",
	              "None of the above",
	              2,
				  10);		    
		
		q10.setValue("Constructor is? ",
	 
	              "A class automatically called  whenever a new object of this class is created ",
	              "A class automatically called  whenever a new object of this class is destroyed",
	              "A function automatically called  whenever a new object of this class is created",
	              "A Class automatically called  whenever a new object of this class is destroyed",
	              3,
				  10);
	
	
	
	q1.askQuestion();
	q2.askQuestion();
	q3.askQuestion();
	q4.askQuestion();
	q5.askQuestion();
	q6.askQuestion();
	q7.askQuestion();
	q8.askQuestion();
	q9.askQuestion();
	q10.askQuestion();	    
	
	
	cout<<"Your total score is " <<Total<<" out of 10"<<endl;
	cout<<endl;
	
	if(Total >= 6) {
		cout<<"Congrats, you passed the test!"<<endl;
		cout<<endl;
	}
	else {
		cout<<"You failed, sorry"<<endl;
		cout<<endl;
		cout<<"Goodluck next time";
	}
	
	return 0;
}   
 void Question::setValues(string q, string a1,string a2,string a3,string a4,int ca, int pa )
 {
 	Question_Text=q;
	Answer_1=a1;
	Answer_2=a2;
	Answer_3=a3;
	Answer_4=a4;
	Correct_Answer = ca;
	Question_Score= pa;
 }
 
 void Question::askQuestion(){
 	cout<<endl;
 	
 	cout<<Question_Text<<endl;
 	cout<"1. "<<Answer_1<<endl;
 	cout<"2. "<<Answer_2<<endl;
 	cout<"3. "<<Answer_3<<endl;
 	cout<"4. "<<Answer_4<<endl;
 	cout<<endl;
 	
 	cout<<"What is your answer?"<<endl;
 	cin>>Guess;
 	
 	if(Guess == Correct_Answer){
 		cout<<endl;
 		cout<<"Correct"<<endl;
 		Total=Total+Question_Score;
 		cout<<"Score: "<<Question_Score<< "Out of"<<Question_Score<<"!"<<endl;
 		cout<<endl;
	 }
	 else{
	 	cout<<endl;
	 	cout<<"Wrong"<<endl;
	 	cout<<"Score: 0"<< "Out of"<<Question_Score<<"!"<<endl;
	 	cout<<"Correct answer is "<<Correct_Answer<<"."<<endl;
	 	cout<<endl;
	 	
	 }
 }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog