SlideShare une entreprise Scribd logo
1  sur  19
#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<<"Welcome to the Quiz Master"<<endl;
cout<<"Synonym & Antonym"<<endl;
cout<<"INSRUCTION"<<endl;
cout<<"*********************************************
**********"<<endl;
cout<<"* Choose one of the possible out of four. *"<<endl;
cout<<"* You have to get at least 70 or above *"<<endl;
cout<<"* to pass the quiz. *"<<endl;
cout<<"*********************************************
**********"<<endl;
cout<<"Press ENTER to start the quiz"<<endl;
cin.get();
string Name;
cout<<"What is your name?"<<endl;
cin>> Name;
string Respond;
cout<<"Are you ready to take the quiz, "<<Name<<"?
Yes/No?"<<endl;
cin>>Respond;
if (Respond == "yes")
{
cout<<endl;
cout<<"Good Luck!"<<endl;
cout<<endl;
}
else if (Respond == "no")
{
cout<<"Goodbye!"<<endl;
return 0;
}
Question q1;
Question q2;
Question q3;
Question q4;
Question q5;
Question q6;
Question q7;
Question q8;
Question q9;
Question q10;
q1.setValues("what is the synonym of stupid?",
"dumb",
"smart",
"clever",
"genious",
1,
10);
q2.setValues("what is the synonym of beautiful? ",
"helpful",
"happy",
"ugly",
"pretty",
4,
10);
q3.setValues("what is the synonym of stretch?",
"fetch",
"intense",
"expand",
"tease",
3,
10);
q4.setValues("what is the synonym of happy?",
"negative",
"impossible",
"joyful",
"hateful",
3,
10);
q5.setValues("what is the synonym of good?",
"dream",
"excellent",
"recycle",
"mean",
2,
10);
q6.setValues("what is the antonym of dark?",
"bright",
"green",
"dim",
"cloudy",
1,
10);
q7.setValues("what is the antonym of sucessful? ",
"stright",
"pass",
"fullfil",
"fail",
4,
10);
q8.setValues("what is the antonym of tight?",
"tiny",
"small",
"loose",
"stress",
3,
10);
q9.setValues("what is the antonym of advantage? ",
"benefit",
"disadvantage",
"favor",
"improvement",
2,
10);
q10.setValues("what is the antonym of strong?",
"hard",
"soft",
"weak",
"power",
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 100"<<endl;
cout<<endl;
if(Total >= 70)
{
cout<<"Great, you passed the quiz!"<<endl;
cout<<endl;
cout<<"Congratulation"<<endl;}
else
{
cout<<"Sorry, you failed the quiz"<<endl;
cout<<"Better luck next time!"<<endl;
}
return 0;
}
void Question::setValues(string q, string a1, string a2, string
a3, string a4, int ca, int qs)
{
Question_Text = q;
Answer_1 = a1;
Answer_2 = a2;
Answer_3 = a3;
Answer_4 = a4;
Correct_Answer = ca;
Question_Score = qs;
}
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;
}
else
{
cout<<endl;
cout<<"Incorect!"<<endl;
cout<<"The correct answer is "<<
Correct_Answer<<"."<<endl;
}
}
Please give me some comments as well as the clues of how this
program works. Thank you
Solution
Program Execution starts from the main method.The program
will wait till the user presses enter button.And asks for the
name, and asks for whether he is ready to take the quiz.if the
user enters “yes” It will start the quiz by wishing you good
luck.If the user enters “no” the program will terminate by
displaying a message good bye.
If the user enters “yes” then the program will create multiple
instances to the class “Question”.
Question q1;
Question q2;
Question q3;
Question q4;
Question q5;
Question q6;
Question q7;
Question q8;
Question q9;
Question q10;
After that using the instances it will call the function of the
class “Question” .
It will call the function by passing the parameters which will set
the values to the class variables.
After that it will call another function which will displays the
Questions And waiting for the user to enter the option.
If the answer is correct it will calculate the score by adding the
score to the total.If the user entered answer is wrong it displays
the correct answer.
Finally if the total score of the quiz is greater than or equal to
70.then it displays a message that the user passed the exam.
If he got less score than 70 it displays the message that he
failed in the exam.
_____________________________________________________
____________________________________
Quiz.cpp
#include <iostream>
#include <string>
using namespace std;
//Declaring Global Variables which we can use any where in the
program.
int Guess;
int Total;
// Creating the class
class Question
{
private:
//declaring variables.
string Question_Text;
string Answer_1;
string Answer_2;
string Answer_3;
string Answer_4;
int Correct_Answer;
int Question_Score;
public:
//Functions.
void setValues (string,string,string,string,string, int, int);
void askQuestion();
};
int main()
{
//Displaying messages.
cout<<"Welcome to the Quiz Master"<<endl;
cout<<"Synonym & Antonym"<<endl;
cout<<"INSRUCTION"<<endl;
cout<<"*********************************************
**********"<<endl;
cout<<"* Choose one of the possible out of four. *"<<endl;
cout<<"* You have to get at least 70 or above *"<<endl;
cout<<"* to pass the quiz. *"<<endl;
cout<<"*********************************************
**********"<<endl;
cout<<"Press ENTER to start the quiz"<<endl;
// Wait until user press enter
cin.get();
string Name;
cout<<"What is your name?"<<endl;
cin>> Name;
string Respond;
cout<<"Are you ready to take the quiz, "<<Name<<"?
Yes/No?"<<endl;
cin>>Respond;
//If the user enters "yes" the if block will execute.If enters
"no" else block will execute.
if (Respond == "yes")
{
cout<<endl;
cout<<"Good Luck!"<<endl;
cout<<endl;
}
else if (Respond == "no")
{
cout<<"Goodbye!"<<endl;
return 0;
}
//Creating an instance to Question class.
Question q1;
Question q2;
Question q3;
Question q4;
Question q5;
Question q6;
Question q7;
Question q8;
Question q9;
Question q10;
//Calling the function of Question class by using the instance of
Question.
//Calling the Function by passing the parameters.
q1.setValues("what is the synonym of stupid?",
"dumb",
"smart",
"clever",
"genious",
1,
10);
//Calling the function of Question class by using the instance of
Question.
//Calling the Function by passing the parameters.
q2.setValues("what is the synonym of beautiful? ",
"helpful",
"happy",
"ugly",
"pretty",
4,
10);
//Calling the function of Question class by using the instance of
Question.
//Calling the Function by passing the parameters.
q3.setValues("what is the synonym of stretch?",
"fetch",
"intense",
"expand",
"tease",
3,
10);
//Calling the function of Question class by using the instance of
Question.
//Calling the Function by passing the parameters.
q4.setValues("what is the synonym of happy?",
"negative",
"impossible",
"joyful",
"hateful",
3,
10);
//Calling the function of Question class by using the instance of
Question.
//Calling the Function by passing the parameters.
q5.setValues("what is the synonym of good?",
"dream",
"excellent",
"recycle",
"mean",
2,
10);
//Calling the function of Question class by using the instance of
Question.
//Calling the Function by passing the parameters.
q6.setValues("what is the antonym of dark?",
"bright",
"green",
"dim",
"cloudy",
1,
10);
//Calling the function of Question class by using the instance of
Question.
//Calling the Function by passing the parameters.
q7.setValues("what is the antonym of sucessful?",
"stright",
"pass",
"fullfil",
"fail",
4,
10);
//Calling the function of Question class by using the instance of
Question.
//Calling the Function by passing the parameters.
q8.setValues("what is the antonym of tight?",
"tiny",
"small",
"loose",
"stress",
3,
10);
//Calling the function of Question class by using the instance of
Question.
//Calling the Function by passing the parameters.
q9.setValues("what is the antonym of advantage? ",
"benefit",
"disadvantage",
"favor",
"improvement",
2,
10);
//Calling the function of Question class by using the instance of
Question.
//Calling the Function by passing the parameters.
q10.setValues("what is the antonym of strong?",
"hard",
"soft",
"weak",
"power",
3,
10);
//Calling the Function by using the class instance.
q1.askQuestion();
q2.askQuestion();
q3.askQuestion();
q4.askQuestion();
q5.askQuestion();
q6.askQuestion();
q7.askQuestion();
q8.askQuestion();
q9.askQuestion();
q10.askQuestion();
//Displaying the score.
cout<<"Your total score is"<<Total<<"out of 100"<<endl;
cout<<endl;
//If the total score is greater than 70 the if block is executed.If
not else block is executed which displays Messages to the user.
if(Total >= 70)
{
cout<<"Great, you passed the quiz!"<<endl;
cout<<endl;
cout<<"Congratulation"<<endl;}
else
{
cout<<"Sorry, you failed the quiz"<<endl;
cout<<"Better luck next time!"<<endl;
}
return 0;
}
//Function Implementation Which will set the values to the
varibles declared in the class.
void Question::setValues(string q, string a1, string a2, string
a3, string a4, int ca, int qs)
{
Question_Text = q;
Answer_1 = a1;
Answer_2 = a2;
Answer_3 = a3;
Answer_4 = a4;
Correct_Answer = ca;
Question_Score = qs;
}
//Function implementation which displays Each Question And
wait for the user to Answer each question.
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 the user enters correct answer add 10(Question_score) to
total.
// This will repeat till user answered all questions.
//If the user enters wrong answer the else block will get
executed which displays the correct answer.
if (Guess == Correct_Answer)
{
cout<<endl;
cout<<"Correct!"<<endl;
Total = Total + Question_Score;
}
else
{
cout<<endl;
cout<<"Incorect!"<<endl;
cout<<"The correct answer is "<<
Correct_Answer<<"."<<endl;
}
}
_____________________________________________________
______________________________

Contenu connexe

Similaire à C++ Quiz Program

Assessments
AssessmentsAssessments
Assessmentshccit
 
Below is my code for C++- I keep getting an error 43 5 C--Progr.pdf
Below is my code for C++- I keep getting an error  43    5    C--Progr.pdfBelow is my code for C++- I keep getting an error  43    5    C--Progr.pdf
Below is my code for C++- I keep getting an error 43 5 C--Progr.pdfanilbhagat17
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxpriestmanmable
 
javaloop understanding what is java.pptx
javaloop understanding what is java.pptxjavaloop understanding what is java.pptx
javaloop understanding what is java.pptxRobertCarreonBula
 
How to write clean tests
How to write clean testsHow to write clean tests
How to write clean testsDanylenko Max
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsTomek Kaczanowski
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3Dillon Lee
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentAll Things Open
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxamrit47
 
----------Evaluator-java---------------- package evaluator- import j.docx
----------Evaluator-java---------------- package evaluator-   import j.docx----------Evaluator-java---------------- package evaluator-   import j.docx
----------Evaluator-java---------------- package evaluator- import j.docxAdamq0DJonese
 
Program.cs class Program { static void Main(string[] args).pdf
Program.cs class Program { static void Main(string[] args).pdfProgram.cs class Program { static void Main(string[] args).pdf
Program.cs class Program { static void Main(string[] args).pdfanandshingavi23
 
Confitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsTomek Kaczanowski
 
OverviewWe will be adding some validation to our Contact classes t.pdf
OverviewWe will be adding some validation to our Contact classes t.pdfOverviewWe will be adding some validation to our Contact classes t.pdf
OverviewWe will be adding some validation to our Contact classes t.pdffathimaoptical
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good TestsTomek Kaczanowski
 
DeVry GSP 115 Week 3 Assignment latest
DeVry GSP 115 Week 3 Assignment latestDeVry GSP 115 Week 3 Assignment latest
DeVry GSP 115 Week 3 Assignment latestAtifkhilji
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to javaciklum_ods
 
Programming with Java: the Basics
Programming with Java: the BasicsProgramming with Java: the Basics
Programming with Java: the BasicsJussi Pohjolainen
 
Esoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsEsoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsRasan Samarasinghe
 

Similaire à C++ Quiz Program (20)

Assessments
AssessmentsAssessments
Assessments
 
JAVA LOOP.pptx
JAVA LOOP.pptxJAVA LOOP.pptx
JAVA LOOP.pptx
 
Below is my code for C++- I keep getting an error 43 5 C--Progr.pdf
Below is my code for C++- I keep getting an error  43    5    C--Progr.pdfBelow is my code for C++- I keep getting an error  43    5    C--Progr.pdf
Below is my code for C++- I keep getting an error 43 5 C--Progr.pdf
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
 
javaloop understanding what is java.pptx
javaloop understanding what is java.pptxjavaloop understanding what is java.pptx
javaloop understanding what is java.pptx
 
Kpi driven-java-development-fn conf
Kpi driven-java-development-fn confKpi driven-java-development-fn conf
Kpi driven-java-development-fn conf
 
How to write clean tests
How to write clean testsHow to write clean tests
How to write clean tests
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good Tests
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
 
----------Evaluator-java---------------- package evaluator- import j.docx
----------Evaluator-java---------------- package evaluator-   import j.docx----------Evaluator-java---------------- package evaluator-   import j.docx
----------Evaluator-java---------------- package evaluator- import j.docx
 
Program.cs class Program { static void Main(string[] args).pdf
Program.cs class Program { static void Main(string[] args).pdfProgram.cs class Program { static void Main(string[] args).pdf
Program.cs class Program { static void Main(string[] args).pdf
 
Confitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good Tests
 
OverviewWe will be adding some validation to our Contact classes t.pdf
OverviewWe will be adding some validation to our Contact classes t.pdfOverviewWe will be adding some validation to our Contact classes t.pdf
OverviewWe will be adding some validation to our Contact classes t.pdf
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
DeVry GSP 115 Week 3 Assignment latest
DeVry GSP 115 Week 3 Assignment latestDeVry GSP 115 Week 3 Assignment latest
DeVry GSP 115 Week 3 Assignment latest
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
Programming with Java: the Basics
Programming with Java: the BasicsProgramming with Java: the Basics
Programming with Java: the Basics
 
Esoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsEsoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basics
 

Plus de ajoy21

Please complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docxPlease complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docxajoy21
 
Please cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docxPlease cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docxajoy21
 
Please choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxPlease choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxajoy21
 
Please check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docxPlease check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docxajoy21
 
Please answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxPlease answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxajoy21
 
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docxPlease attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docxajoy21
 
Please answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxPlease answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxajoy21
 
Please answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docxPlease answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docxajoy21
 
Please answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docxPlease answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docxajoy21
 
Please answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docxPlease answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docxajoy21
 
Please answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docxPlease answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docxajoy21
 
Please answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docxPlease answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docxajoy21
 
Please answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docxPlease answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docxajoy21
 
Please answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docxPlease answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docxajoy21
 
Please answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docxPlease answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docxajoy21
 
Please answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docxPlease answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docxajoy21
 
Please answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docxPlease answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docxajoy21
 
Please answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docxPlease answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docxajoy21
 
Please answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docxPlease answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docxajoy21
 
Please answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxPlease answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxajoy21
 

Plus de ajoy21 (20)

Please complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docxPlease complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docx
 
Please cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docxPlease cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docx
 
Please choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxPlease choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docx
 
Please check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docxPlease check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docx
 
Please answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxPlease answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docx
 
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docxPlease attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
 
Please answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxPlease answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docx
 
Please answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docxPlease answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docx
 
Please answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docxPlease answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docx
 
Please answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docxPlease answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docx
 
Please answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docxPlease answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docx
 
Please answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docxPlease answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docx
 
Please answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docxPlease answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docx
 
Please answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docxPlease answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docx
 
Please answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docxPlease answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docx
 
Please answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docxPlease answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docx
 
Please answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docxPlease answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docx
 
Please answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docxPlease answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docx
 
Please answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docxPlease answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docx
 
Please answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxPlease answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docx
 

Dernier

The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Dernier (20)

The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

C++ Quiz Program

  • 1. #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<<"Welcome to the Quiz Master"<<endl; cout<<"Synonym & Antonym"<<endl; cout<<"INSRUCTION"<<endl; cout<<"********************************************* **********"<<endl; cout<<"* Choose one of the possible out of four. *"<<endl; cout<<"* You have to get at least 70 or above *"<<endl; cout<<"* to pass the quiz. *"<<endl;
  • 2. cout<<"********************************************* **********"<<endl; cout<<"Press ENTER to start the quiz"<<endl; cin.get(); string Name; cout<<"What is your name?"<<endl; cin>> Name; string Respond; cout<<"Are you ready to take the quiz, "<<Name<<"? Yes/No?"<<endl; cin>>Respond; if (Respond == "yes") { cout<<endl; cout<<"Good Luck!"<<endl; cout<<endl; } else if (Respond == "no") { cout<<"Goodbye!"<<endl; return 0; } Question q1; Question q2; Question q3; Question q4; Question q5; Question q6; Question q7; Question q8; Question q9; Question q10; q1.setValues("what is the synonym of stupid?", "dumb", "smart",
  • 3. "clever", "genious", 1, 10); q2.setValues("what is the synonym of beautiful? ", "helpful", "happy", "ugly", "pretty", 4, 10); q3.setValues("what is the synonym of stretch?", "fetch", "intense", "expand", "tease", 3, 10); q4.setValues("what is the synonym of happy?", "negative", "impossible", "joyful", "hateful", 3, 10); q5.setValues("what is the synonym of good?", "dream", "excellent", "recycle", "mean", 2, 10); q6.setValues("what is the antonym of dark?", "bright", "green", "dim",
  • 4. "cloudy", 1, 10); q7.setValues("what is the antonym of sucessful? ", "stright", "pass", "fullfil", "fail", 4, 10); q8.setValues("what is the antonym of tight?", "tiny", "small", "loose", "stress", 3, 10); q9.setValues("what is the antonym of advantage? ", "benefit", "disadvantage", "favor", "improvement", 2, 10); q10.setValues("what is the antonym of strong?", "hard", "soft", "weak", "power", 3, 10); q1.askQuestion(); q2.askQuestion(); q3.askQuestion(); q4.askQuestion();
  • 5. q5.askQuestion(); q6.askQuestion(); q7.askQuestion(); q8.askQuestion(); q9.askQuestion(); q10.askQuestion(); cout<<"Your total score is"<<Total<<"out of 100"<<endl; cout<<endl; if(Total >= 70) { cout<<"Great, you passed the quiz!"<<endl; cout<<endl; cout<<"Congratulation"<<endl;} else { cout<<"Sorry, you failed the quiz"<<endl; cout<<"Better luck next time!"<<endl; } return 0; } void Question::setValues(string q, string a1, string a2, string a3, string a4, int ca, int qs) { Question_Text = q; Answer_1 = a1; Answer_2 = a2; Answer_3 = a3; Answer_4 = a4; Correct_Answer = ca; Question_Score = qs; }
  • 6. 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; } else { cout<<endl; cout<<"Incorect!"<<endl; cout<<"The correct answer is "<< Correct_Answer<<"."<<endl; } } Please give me some comments as well as the clues of how this program works. Thank you
  • 7. Solution Program Execution starts from the main method.The program will wait till the user presses enter button.And asks for the name, and asks for whether he is ready to take the quiz.if the user enters “yes” It will start the quiz by wishing you good luck.If the user enters “no” the program will terminate by displaying a message good bye. If the user enters “yes” then the program will create multiple instances to the class “Question”. Question q1; Question q2; Question q3; Question q4; Question q5; Question q6; Question q7; Question q8; Question q9; Question q10; After that using the instances it will call the function of the class “Question” .
  • 8. It will call the function by passing the parameters which will set the values to the class variables. After that it will call another function which will displays the Questions And waiting for the user to enter the option. If the answer is correct it will calculate the score by adding the score to the total.If the user entered answer is wrong it displays the correct answer. Finally if the total score of the quiz is greater than or equal to 70.then it displays a message that the user passed the exam. If he got less score than 70 it displays the message that he failed in the exam. _____________________________________________________ ____________________________________ Quiz.cpp #include <iostream> #include <string> using namespace std; //Declaring Global Variables which we can use any where in the program. int Guess; int Total; // Creating the class class Question {
  • 9. private: //declaring variables. string Question_Text; string Answer_1; string Answer_2; string Answer_3; string Answer_4; int Correct_Answer; int Question_Score; public: //Functions. void setValues (string,string,string,string,string, int, int); void askQuestion(); }; int main() { //Displaying messages. cout<<"Welcome to the Quiz Master"<<endl; cout<<"Synonym & Antonym"<<endl; cout<<"INSRUCTION"<<endl; cout<<"********************************************* **********"<<endl;
  • 10. cout<<"* Choose one of the possible out of four. *"<<endl; cout<<"* You have to get at least 70 or above *"<<endl; cout<<"* to pass the quiz. *"<<endl; cout<<"********************************************* **********"<<endl; cout<<"Press ENTER to start the quiz"<<endl; // Wait until user press enter cin.get(); string Name; cout<<"What is your name?"<<endl; cin>> Name; string Respond; cout<<"Are you ready to take the quiz, "<<Name<<"? Yes/No?"<<endl; cin>>Respond; //If the user enters "yes" the if block will execute.If enters "no" else block will execute. if (Respond == "yes") { cout<<endl; cout<<"Good Luck!"<<endl; cout<<endl; } else if (Respond == "no")
  • 11. { cout<<"Goodbye!"<<endl; return 0; } //Creating an instance to Question class. Question q1; Question q2; Question q3; Question q4; Question q5; Question q6; Question q7; Question q8; Question q9; Question q10; //Calling the function of Question class by using the instance of Question. //Calling the Function by passing the parameters. q1.setValues("what is the synonym of stupid?", "dumb", "smart", "clever", "genious", 1, 10);
  • 12. //Calling the function of Question class by using the instance of Question. //Calling the Function by passing the parameters. q2.setValues("what is the synonym of beautiful? ", "helpful", "happy", "ugly", "pretty", 4, 10); //Calling the function of Question class by using the instance of Question. //Calling the Function by passing the parameters. q3.setValues("what is the synonym of stretch?", "fetch", "intense", "expand", "tease", 3, 10); //Calling the function of Question class by using the instance of Question. //Calling the Function by passing the parameters. q4.setValues("what is the synonym of happy?", "negative",
  • 13. "impossible", "joyful", "hateful", 3, 10); //Calling the function of Question class by using the instance of Question. //Calling the Function by passing the parameters. q5.setValues("what is the synonym of good?", "dream", "excellent", "recycle", "mean", 2, 10); //Calling the function of Question class by using the instance of Question. //Calling the Function by passing the parameters. q6.setValues("what is the antonym of dark?", "bright", "green", "dim", "cloudy", 1, 10);
  • 14. //Calling the function of Question class by using the instance of Question. //Calling the Function by passing the parameters. q7.setValues("what is the antonym of sucessful?", "stright", "pass", "fullfil", "fail", 4, 10); //Calling the function of Question class by using the instance of Question. //Calling the Function by passing the parameters. q8.setValues("what is the antonym of tight?", "tiny", "small", "loose", "stress", 3, 10); //Calling the function of Question class by using the instance of Question. //Calling the Function by passing the parameters. q9.setValues("what is the antonym of advantage? ", "benefit",
  • 15. "disadvantage", "favor", "improvement", 2, 10); //Calling the function of Question class by using the instance of Question. //Calling the Function by passing the parameters. q10.setValues("what is the antonym of strong?", "hard", "soft", "weak", "power", 3, 10); //Calling the Function by using the class instance. q1.askQuestion(); q2.askQuestion(); q3.askQuestion(); q4.askQuestion(); q5.askQuestion(); q6.askQuestion(); q7.askQuestion(); q8.askQuestion(); q9.askQuestion();
  • 16. q10.askQuestion(); //Displaying the score. cout<<"Your total score is"<<Total<<"out of 100"<<endl; cout<<endl; //If the total score is greater than 70 the if block is executed.If not else block is executed which displays Messages to the user. if(Total >= 70) { cout<<"Great, you passed the quiz!"<<endl; cout<<endl; cout<<"Congratulation"<<endl;} else { cout<<"Sorry, you failed the quiz"<<endl; cout<<"Better luck next time!"<<endl; } return 0; } //Function Implementation Which will set the values to the varibles declared in the class. void Question::setValues(string q, string a1, string a2, string a3, string a4, int ca, int qs)
  • 17. { Question_Text = q; Answer_1 = a1; Answer_2 = a2; Answer_3 = a3; Answer_4 = a4; Correct_Answer = ca; Question_Score = qs; } //Function implementation which displays Each Question And wait for the user to Answer each question. 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;
  • 18. cout<<"what is your answer?"<<endl; cin>>Guess; //If the user enters correct answer add 10(Question_score) to total. // This will repeat till user answered all questions. //If the user enters wrong answer the else block will get executed which displays the correct answer. if (Guess == Correct_Answer) { cout<<endl; cout<<"Correct!"<<endl; Total = Total + Question_Score; } else { cout<<endl; cout<<"Incorect!"<<endl; cout<<"The correct answer is "<< Correct_Answer<<"."<<endl;