Coders Packet

INTERESTING QUIZ GAME BUILD USING THE CONCEPT OF SIMPLE C++ FUNCTIONS

By Rupam Jha

  • IT IS AN INTERESTING QUIZ GAME BUILD USING THE CONCEPT OF SIMPLE C++ FUNCTIONS.docx
  • This quiz game built in C++ displays few questions to user who is playing this game and on the basis of performance score is incremented and at the end gives total score.

    In this we, will learn how to make our own quiz game using C++.

    This quiz game checks your general knowledge and on the basis of the performance it gives you total score.

    We have to provide questions to user and options are also provided and accordingly they have to choose the correct option.

    If user chooses correct option their score will incremented .

    EXPLANATION:

    Here we can see that we have provided 5 questions along with the four option and each correct option corresponds to 20 point else 0.

    At the end, it gives total score and if total score is greater than equal to 70 we receive a message congratulations else displays failed.

    The motive of this game is to increase intellectual skills and brainstorming

    #include 
    #include
    using namespace std;
    int guess,total;
    class Question
    {
    private:
         string qt;
         string ans1;
         string ans2;
         string ans3;
         string ans4;
         int correct_ans;
         int score;
    public:
    void setvalue(string ,string,string,string,string,int,int);
    void askq();
    
     };
     int main(){
     cout<<"********************************"<<endl;
     cout<<"*                              *"<<endl;
     cout<<"*     *Welcome TO c++ quiz     *"<<endl;
     cout<<"*     -------------------      *"<<endl;
     cout<<"*                               *"<<endl;
     cout<<"*********************************"<<endl;
     cout<<endl;
     cout<<"Press enter to start quiz...."<<endl;
     cin.get();
     string name;
     int age;
     cout<<"What is your name?"<<endl;
     cin>>name;
     cout<<endl;
     cout<<"How old are you?"<<endl;
     cin>>age;
     cout<<endl;
     string respond;
     cout<<"Are you ready to take quiz"<<name<<"?Yes/No."<<endl;
     cin>>respond;
     if(respond=="yes"){
         cout<<endl;
         cout<<"Ok,Good Luck!"<<endl;
         cout<<endl;
     }
     else{
         cout<<"Ok Goodbye!"<<endl;
         return 0;
     }
     Question q1;
     Question q2;
     Question q3;
     Question q4;
     Question q5;
    
     q1.setvalue("'OS' computer abbreviation usually means ?",
     "operating system",
     "open system",
     "optical sensor",
     "open symptom",
     1,
     20);
     q2.setvalue("What is the national sport in Japan?",
     "hockey",
     "Tennis",
     "sumo wrestling",
     "badmintion",
     3,
     20);
     q3.setvalue("Which sport does Messi play?",
     "cricket",
     "footbal",
     "hockey",
     "polo",
     2,
     20);
     q4.setvalue("'.MOV' extension refers usually to what kind of file?",
     "Image file",
     "animation/movie file",
     "audio file",
     "MS office document",
     2,
     20);
     q5.setvalue("In which decade with the first transatlantic radio broadcast occur?",
    "1850s",
    "1860s",
    "1870s",
    "1900s",
    4,
    20);
    q1.askq();
    q2.askq();
    q3.askq();
    q4.askq();
    q5.askq();
    cout<<"Your total score is"<<total<<"out of 100"<<endl;
    cout<<endl;
    if(total>=70){
        cout<<"Great you passed quiz!"<<endl;
        cout<<endl;
        cout<<"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
        cout<<"$                                 $"<<endl;
        cout<<"$     **CONGRATULATIONS**         $"<<endl;
        cout<<"$                                 $"<<endl;
        cout<<"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
    }
    else{
        cout<<"sorry,you failed."<<endl;
        return 0;
    }}
    
    void Question::setvalue (string qp,string a1,string a2,string a3,string a4,int ca,int cp){
        qt=qp;
        ans1=a1;
        ans2=a2;
        ans3=a3;
        ans4=a4;
        correct_ans=ca;
        score=cp;
    }
    
    void Question::askq(){
        cout<<endl;
        cout<<qt<<endl;
        cout<<"1."<<ans1<<endl;
        cout<<"2."<<ans2<<endl;
        cout<<"3."<<ans3<<endl;
        cout<<"4."<<ans4<<endl;
        cout<<endl;
        cout<<"What is your answer?"<<endl;
        cin>>guess;
        if(guess==correct_ans){
            cout<<endl;
            cout<<"Great! You are correct."<<endl;
            total=total+score;
            cout<<"Score:"<<score<<"out of"<<score<<"!"<<endl;
            cout<<endl;
    
        }
        else{
            cout<<endl;
            cout<<"Oh No! You are wrong."<<endl;
            cout<<"Score:0"<<"out of"<<score<<"!"<<endl;
            cout<<"The correct answer is"<<correct_ans<<"."<<endl;
            cout<<endl;
        }
    
    
       }
    

    Download Complete Code

    Comments

    No comments yet