Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are tasked with enhancing a river quiz game by adding several new features. The game should measure the time taken for the user to

You are tasked with enhancing a river quiz game by adding several new features. The game should measure the time taken for the user to answer each question using std::chrono, and mark answers as incorrect if they take more than 10 seconds, displaying a time limit exceeded message as appropriate.
All random number generation should use std::random with a 64-bit Mersenne Twister initialized once with std::random_device. Ensure that a river cannot be regenerated for six calls after it was last generated.
Implement a function getFastest() in the Game class to return the players 5 fastest correctly answered questions in nonincreasing order of speed (or all if there are fewer than 5). It should return a vector of strings with each string formatted as River1,River2,time, with the time recorded in milliseconds.
Additionally, create three modes for random generation using std::discrete_distribution:
Each continent is equally likely to be selected.
Each river is equally likely to be selected.
Consecutive calls to the getRandomRiver method should have a 50% probability of producing rivers from the same continent.
Implement a method setGenerationMode(int mode) in the Game class to handle these customizations. The default mode should be either mode 1 or 2.
For performance, read the files in parallel in the Rivers constructor, protecting against data races where necessary. Also, modify the getContinent() function to operate in O(k) time, where k is the length of the river string in characters, without using third-party libraries.
The code should avoid global variables, excessively long functions, excessive nesting, and repetition. Ensure it is maintainable, readable, extendable, and simple, using templates, classes, and functions where appropriate.
Above is my question and below is my answer what should i change in the code to make it better.
#pragma once
#include "Rivers.h"
#include
#include
#define ASSIGNMENT_2//uncomment to switch to assignment 2
//#define RUN_PAUSE_TEST //uncomment to run pause test (for assignment 2 only)
class Game {
Rivers r;
//further variables...
public:
Game(Rivers& rivers) : r(rivers){}
int getScore(){ return 0; }
int getTotal(){ return 0; }
//reset score and total to 0
void reset(){}
//this method should implement one round of the game only,
//it should return true if the player wishes to continue ('s' or 'd') and false otherwise ('q')
bool playRound(std::ostream& out, std::istream& in);
std::vector getFastest(){ return std::vector(); }
};
game.cpp
#include "Game.h"
//Be sure to refer to in and out - NOT cin and cout in this code. Tests will fail otherwise
bool Game::playRound(std::ostream& out, std::istream& in){
return false;
}
Rivers.h
#pragma once
#include
#include
class Rivers
{
//Insert data structure(s) here...
public:
//Time complexity:
Rivers(const std::vector& filenames);
//Time complexity:
std::string getRandomRiver();
//Time complexity:
bool sameContinent(std::string river1, std::string river2);
//Time complexity:
std::string getContinent(std::string river);
//No need to implement this until assignment 2
void setMode(int mode){}
};
Rivers.cpp
#include "Rivers.h"
Rivers::Rivers(const std::vector& filenames)
{
}
std::string Rivers::getRandomRiver()
{
return "";
}
bool Rivers::sameContinent(std::string r1, std::string r2)
{
return false;
}
std::string Rivers::getContinent(std::string river)
{
return "";
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions