Fixed the code and create the exactly the same output as the sample output that
ID: 3779781 • Letter: F
Question
Fixed the code and create the exactly the same output as the sample output that I post the image below.Read the #1 Roulette instruction below and Write a C++ program which use virtual functions including at least one pure virtual function with polymorphism. The program should have one class for game along with a base-class that contains the appropriate data members and methods. Make sure to include the correct OUTPUT for the game.
// The code start here and fixed the wrong code and create the exactly the same output as the sample output:
#include<iostream>
#include<time.h>
#include<stdlib.h>
#include<string>
#include<iomanip>
using namespace std;
class Game {
public:
Game() {};
virtual int output(int a) = 0;
};
class Oddness: public Game { //The code is wrong and Please fixed the code.
public:
Oddness() {};
int output(int a){
int wheel = rand()%38;
if (wheel == 37 || wheel == 0) {
cout<< "The wheel came up 0/00 ";
return 0;
}
else {
cout<< "The wheel came up "<<wheel<<endl;
return (a == wheel%2);
}
}
};
class Number: public Game //The code is wrong and Please fixed the code.
{
public:
Number() {};
int output(int a){
int wheel = rand()%38;
if (wheel == 37)
{
cout<< "The wheel came up 00 ";
return 0;
}
else
{
cout<< "The wheel came up "<<wheel<<endl;
return (a == wheel);
}
}
};
class Player
{
string name;
int times;
int money;
public:
Player(string a, int b)
{
name = a;
money = 0;
times = b;
}
void win(int a)
{
money += a;
cout<< "You win $"<<a<<".00 ";
}
void lose(int a)
{
money -= a;
cout<< "You lose $"<<a<<".00 ";
}
Player::~Player() //The code is wrong and Please fixed the code.
{
cout<<"Final Results for "<<name<<" after "<<times<<" games of Roulette: ";
if (money>0)
{
cout<<name<<" won a total of "<<money<<".00 ";
cout<<"The casino will add a bonus of 1.3% to your winnings ";
cout<<"The casino bonus is "<<money*0.013<<endl;
cout<<name<<" total winnings are "<<money*1.013<<endl;
}
else
{
cout<<name<<" lose a total of "<<-1*money<<".00 ";
}
}
};
int main()
{
srand (time(NULL));
int input;
int count=3, betMoney, bet, wrong=1;
char ch, chOdd;
Number n;
Oddness o;
string name;
cout << "What is your full name? ";
getline(cin, name);
cout << "How many times would you like to play Roulette? ";
cin >> count;
Player p(name, count);
for (int i = 0; i<count; i++)
{
cout << " Roulette Game "<<i+1<<endl;
cout << "How much would you like to bet? ";
cin >> betMoney;
cout << "Would you like to bet on a specific number (N) or on odd/even (O)? ";
cin >> ch;
switch (ch)
{
case 'N':
cout<<"What number would you like to bet on? ";
cin >> bet;
while (bet< 0 || bet>36) {
cout<<"Wrong Input! Enter bet number: ";
cin >> bet;
}
if (n.output(bet))
p.win(35*betMoney);
else
p.lose(betMoney);
break;
case 'O':
cout<<"Are you betting on even (E) or odd (O)? ";
while (wrong==1) {
cin >> chOdd;
switch (chOdd){
case 'O':
bet = 1;
wrong = 0;
break;
case 'E':
bet = 0;
wrong = 0;
break;
default:
wrong = 1;
cout<<"Wrong Input ";
}
}
if (o.output(bet))
p.win(betMoney);
else
p.lose(betMoney);
break;
default:
cout<<"Wrong Input ";
}
}
system("PAUSE");
return 0;
}
// This code output with error part, Please fixed the error part:
What is your full name? Joe Gambler
How many times would you like to play Roulette? 3
Roulette Game 1
How much would you like to bet? 10
Would you like to bet on a specific number (N) or on odd/even (O)? N
What number would you like to bet on? 25
The wheel came up 25 //This line is wrong and Please fixed the code.
You win $350.00
Roulette Game 2
How much would you like to bet? 30
Would you like to bet on a specific number (N) or on odd/even (O)? O
Are you betting on even (E) or odd (O)? O
The wheel came up 19 //This line is wrong and Please fixed the code.
You win $30.00
Roulette Game 3
How much would you like to bet? 10
Would you like to bet on a specific number (N) or on odd/even (O)? N
What number would you like to bet on? 00
The wheel came up 12 //This line is wrong and Please fixed the code.
You lose $10.00
//Missing the part of output, Please write the code:
Final Results for Joe Gambler after 3 games of Roulette:
Joe Gambler won a total of $ 10.00
The casino will add a bonus of 1.3% to your winnings
The casino bonus is $0.13
Joe Gambler total winnings are $10.13
// The sample output start here:
For each game, first ask the user how many times they would like to play the game along with their full name. Please make sure to include output for each of the four games. For each game, print out the player's name, the results of each game played, the total winnings/losses, the additional winnings paid by the casino if any, and the total winnings/losses with the additional winnings paid by the casino if any. Your program should use virtual functions including at least one pure virtual function with polymorphism. Your program should have one class for each game along with a base-class that contains the appropriate data members and methods. Sample output for Roulette, the other 3 games should be similar: What is your full name? Joe Gambler How many times would you like to play Roulette? 3 Roulette Game 1 How much would you like to bet? 10 Would you like to bet on a specific number (N) or on odd/even (O)? N What number would you like to bet on? 25 The wheel came up 12 You lose $10.00 Roulette Game 2 How much would you like to bet? 30 Would you like to bet on a specific number (N) or on odd/even (O)? O Are you betting on even (E) or odd(O)? O The wheel came up 17 You win $30.00 Roulette Game 3 How much would you like to bet? 10 Would like bet on a specific number (N) or on oddleven (O)? N What number would you like to bet on? 00 The wheel came up 33 You lose $10.00Explanation / Answer
Hi, yes its simple.
See, obviously we would use random funstion for a random number , given a range. and this would produce random numbers. But instead of this plain rand() use srand(). See dtis function with time varaiable so that a unique random number gets generated at each time instant.
Change code to:
#inclide<ctime>
//and before using rand) write this:
Now do rand)%35+1;
// our condition for 00 is okay.
---Now for the final part---
1. for total win or loss: create a static global variable and manipulate wit with each win.
2. Condition for bonus is nt specified. if fixed then manipulate the global variavle again.
Thanks
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.