Fixed the code and create the exactly the same output as the sample output that
ID: 3779702 • 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 {
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
{
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
{
char name;
int times;
int money;
public:
Player(char 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()
{
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_t(NULL));
int input;
int count=3, betMoney, bet, wrong=1;
char ch, chOdd;
Number n;
Oddness o;
for (int i = 0; i<count; i++)
{
cout << "What is your full name? "<<endl;
cout << "How many times would you like to play Roulette? "<<endl;
cin >> input;
cin>>count;
}
Player p(input, count);
for (int i = 0; i<count; i++)
{
cout << " Roulette Game "<<i+1<<endl;
cout << "How much would you like to bet? "<<endl;
cin >> betMoney;
cout << "Would you like to bet on a specific number (N) or on odd/even (O)? "<<endl;
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:
What is your full name? //This line is wrong and Please fixed the code.
How many times would you like to play Roulette? //This line is wrong and Please fixed the code.
3 3
What is your full name? //This line is wrong and Please fixed the code.
How many times would you like to play Roulette? //This line is wrong and Please fixed the code.
3 3
What is your full name? //This line is wrong and Please fixed the code.
How many times would you like to play Roulette? //This line is wrong and Please fixed the code.
3 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 0 //This line is wrong and Please fixed the code.
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 5 //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 34 //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 totoal 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
Explanation / Answer
#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 {
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
{
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()
{
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;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.