CA 4 - Jeopardy Game

An in-class activity assigned Wednesday, 04/24/2019. Due Mon, Apr. 29 in class or via submission portal

Write a Jeopardy-style C++ game that includes the following elements:

  • A data structure for the Jeopardy Host (at least 3 attributes) [Update]: removed this requirement
  • A data structure for a Jeopardy Question
  • at least 5 instances of a Question
  • a menu that lets you select a question

Be creative! 75% of your grade on this activity is based on the creativity of your solution.

Things to Consider

  • Your program should follow the “pretty code” guidelines
  • How can you test that your program will work for most (or perhaps all) cases?
  • Which cases are the exceptions?

Class Progress

#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct Question {
  string category;
  string text;
  string answer;
  string prefix;
  double money;
};

vector<Question> questions;
double moneyCollected = 0.0;
string player;

void printMenu(){
  for (int i = 0; i < questions.size(); i++){
    cout << i << ". $" << questions.at(i).money << " - " << questions.at(i).category << endl;
  }
}

void printQuestion(Question q){
  cout << "$" << q.money << " - " << q.category << " - " << q.text << endl;
  cout << "Your answer: " << q.prefix << " ";
}

void initialize(){
   questions = {
    {"Programming", "A verb that describes creating an instance of an object", "instantiate", "What is to", 100.00},
    {"Artificial Intelligence", "This is an outdated test of a machine's ability to exhibit intelligent behavior ", "Turing test", "What is the", 200.00},
    {"Computer Architecture", "A design architecture for an electronic digital computer that includes I/O, Memory, CPU, and the ALU", "Von Neumann model", "What is the", 300.00},
    {"Cryptography", "A skilled computer expert that uses their technical knowledge to overcome a problem", "hacker", "Who is a", 400.00},
    {"Number Systems", "The most basic number system aka the language of computers", "binary", "What is", 500.00}
  };
  cout << "What is your name? ";
  cin >> player;
}


int main() {
  initialize();
  cout << "---------------------------------------" << endl;
  cout << " Welcome to Jeopardy Quizlet, " << player << "!" << endl;
  cout << "---------------------------------------" << endl;
  cout << "A twist on the traditional Jeopardy game " << endl 
       << "to help you improve your CS vocabulary. " << endl << endl;

  while (questions.size() > 0){
    int choice;
    printMenu();
    cin >> choice;
    cin.ignore(); // clear cin for getline

    string answer;
    printQuestion(questions.at(choice));
    getline(cin, answer);
    
    if (answer != questions.at(choice).answer){
      cout << "- $" << questions.at(choice).money << " Whoops, the correct answer is: " << questions.at(choice).prefix << " " << questions.at(choice).answer << endl << endl;
    } else {
      moneyCollected += questions.at(choice).money;
      cout << "Correct! Your total is now $" << moneyCollected << "." << endl << endl;
      questions.erase(questions.begin()+choice);
    }
  }
  cout << "You have completed this game of Jeopardy with $" << moneyCollected << endl;
}

Submission Portal: https://forms.gle/RTE76NJPJQKwjFag6


© 2020. Some rights reserved.