CS304P Assignment 2 Solution Fall 2024
CS304P Assignment 2 Solution Fall 2024
SOLUTION
CODE
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
class Score {
private:
int score;
public:
// Constructor
Score(int initialScore) : score(initialScore) {}
class GuessingGame {
private:
int targetNumber;
Score playerScore;
public:
// Constructor to initialize the game
GuessingGame() : playerScore(5) {
targetNumber = generateRandomNumber(1, 10);
}
int attempt = 1;
while (playerScore.getScore() > 0) {
int guess = generateRandomNumber(1, 10);
cout << "Attempt " << attempt << ": Virtual player guesses " << guess << ". ";
cout << "The correct number was: " << targetNumber << endl;
cout << "Final score: " << playerScore.getScore() << endl;
cout << "-----------------------------------------" << endl;
}
};
int main() {
srand(static_cast<unsigned>(time(0))); // Seed the random number generator
GuessingGame game;
game.play();
return 0;
}
SCREENSHOT OUTPUT
REGARD - SARIM
WHATSAPP +923162965677
PLEASE NOTE:
Don't copy-paste the same answer.
Make sure you can make some changes to your solution file before
submitting copy paste solution will be marked zero.
If you found any mistake then correct yourself and inform me.
Before submitting an assignment must check your assignment requirement
file.
If you need some help or question about file and solutions feel free to ask.
VUAnswer.pk