hoe to combine three vectors together

This is a discussion on hoe to combine three vectors together within the C++ Programming forums, part of the General Programming Boards category; hello, i want to ask a question, how i can create a quiz system that can generate a questions for ...

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    3

    hoe to combine three vectors together

    hello,

    i want to ask a question, how i can create a quiz system that can generate a questions for me. for example quiz software to test knowledge of countries and their currencies

    what is the currency of UK?
    what is the currency of US?

    The questions should be generated dynamically and the name of the country must come from a map which initialized. The student answers by typing the name of the currency and pressing ENTER key and the software shows another question with the name of a different country - this should continue until the software the iterated over all the countries in the map

    Each time the student enters an answer you check the map to see if his/her answer is correct. The software should make a record of which questions were answered correctly and which questions were answered incorrectly.

    Use a Vector to store answers which were answered incorrectly so that they can displayed in the report

    i have started with this part of code:

    Code:
    #include<map>
    #include<iostream>
    using namespace std;
    
    
    int main(){
    
    
    map<string, string> currency;
    currency["china"]="yen";
    currency["US"]="dolar";
    
    
    map<string, string>:: iterator it;
    
    
    for(it=currency.begin(); it!=currency.end(); it++){
    
    
    cout<<"what is the currency of"<<(*it).first<<"?"<<"\n";
    cout<<"\n";
    cin>>(*it).second;
    cout<<"\n";
    }
    cin.get();
    
    
    }
    could you help me please, i stop in this point and i get confuse.

    thanks,

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    2,545
    Quote Originally Posted by loyal View Post
    Code:
    cin>>(*it).second;
    this is clearly not what you want to do. it will overwrite the existing value. what you want to do is create a string variable in which to store the user's input, and then compare that to it->second.

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    3
    i try this. i create a class that contains three vectors

    the first vector to store the questions.


    Code:
    #include <iostream>
    #include <vector>
    
    
    using namespace std;
    class Quiz{
                
           private:
            int countR;
            int countW;
            int result;
            string Ans;
            
            vector <string> Country;
            vector <string> Question;
            vector <string> Answers;
            vector <string> userAnsw;
            vector <string> ResultQuestions;
            
        public:
               Quiz();
              void inputanswer();
              void checkanswer();
    };
    
    
     Quiz::Quiz(){
          Country.push_back("US");
          Country.push_back("UAE");
          Country.push_back("China");
          Answers.push_back("dollar");
          Answers.push_back("Derham");
          Answers.push_back("Yen");
    }             
    
    
    
    
    void Quiz::inputanswer(){
         for(int i=0; i<3; i++){
    cout<< "what is the currency of "<<Country.at(i)<<" ?" << "\n";
    cin>>Ans;
    userAnsw.push_back(Ans);
    }
    cout<<"********************"<<endl;
    cout<<" "<<"\n";
    cout<<" "<<"\n";
    cout<<" "<<"\n";
    for(int i=3; i<userAnsw.size(); i++){
    cout<<userAnsw.at(i)<< "\n";
    
    
    }
         
    }       
    
    
    main(){
      Quiz q;
      q.inputanswer();
      cin.get(); 
        
           }
    now, i want to create the second and third vector that check for the answers, if the answer is correct or not and display the result as below:

    === Result of Currency Quiz ===
    Total Questions : 10
    Correct answers : 5
    Wrong answers: 5
    You scored 50% on this quiz.

    The Questions which you answered incorrectly were
    Q2. What is the currency of Singapore?
    Q5. What is the currency of UK?
    Q7. What is the currency of Malaysia?
    Q8. What is the currency of Pakistan?
    Q9. What is the currency of Australia?
    Last edited by loyal; 01-09-2013 at 02:23 AM.

  4. #4
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    Well next you should define your checkanswer() function.

    The beginning of the code looks nice and neat and then the end of the code "forgets" indentation and then main doesn't even have a type. Whats going on?

    main.cpp: In member function ‘void Quiz::inputanswer()’:
    main.cpp:49:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    main.cpp: At global scope:
    main.cpp:58:6: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
    Last edited by Lesshardtofind; 01-09-2013 at 02:42 AM.

  5. #5
    Registered User
    Join Date
    Jan 2013
    Posts
    3
    i make some changes on the code and try to solve it using Qt Create. But there is just three errors i try to solve it. Could you help me please

    Code:
    #include<QtCore/QCoreApplication>
    #include<QVector>
    #include<QMap>
    #include<QString>
    #include<QDebug>
    
    classQuiz{
    
    private:
    inti,countR,countW;
    
    QMap<QString,QString>my_map;
    QVector<QString>my_vec;
    
    public:
    Quiz();
    voidstart();
    };
    
    Quiz::Quiz(){
    }
    
    voidQuiz::start(){
    my_map["UK"]="Dollarl";
    my_map["UAE"]="Derham";
    my_map["China"]="Yen";
    
    QVector<QString>::iteratormy_it;
    QMap<QString,QString>::iteratorit;
    
    i=1;
    countR=0;
    countW=0;
    
    QStringans;
    
    for(it=my_map.begin();it!=my_map.end();it++){
    qDebug()<<"Q"<<i<<"whatisthefullformfor"+(*it).first<<"?\n";
    cin>>ans;
    
    if((*it).second==ans){
    countR++;
    }
    else{
    countW++;
    }
    i++;
    }
    
    qDebug()<<"ResultofITacronymsQuize"<<endl;
    qDebug()<<"TotalQuestion:10"<<endl;
    
    qDebug()<<"Correctanswers:"<<countR<<""<<endl;
    qDebug()<<"Wronganswers:"<<countW<<""<<endl;
    
    qDebug()<<"Youscored"<<countR*10<<"%onthisquize"<<endl;
    system("pause");
    
    }
    
    intmain(intargc,char*argv[]){
    QCoreApplicationa(argc,argv);
    QuizQ;
    Q.start();
    
    }
    Last edited by loyal; 01-09-2013 at 10:44 AM.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    2,545
    you really need to pick one way to do this and stick with it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vectors in vectors - pointers and iterators
    By fisherking in forum C++ Programming
    Replies: 8
    Last Post: 07-27-2010, 10:34 AM
  2. Combine Two Buffers - How To?
    By Superfreak3 in forum C++ Programming
    Replies: 7
    Last Post: 03-26-2010, 11:59 PM
  3. how do I combine two strings together
    By freeman_peterso in forum C Programming
    Replies: 19
    Last Post: 06-27-2003, 02:35 PM
  4. combine C with other languages?
    By drharv in forum C Programming
    Replies: 1
    Last Post: 06-17-2002, 11:24 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21