SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 1 Day Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 31 Oct 2017 My Price 10.00

Copy and paste your finished code into a Word document,

I would like to get some help with this question soon as possible.

Week 7: Scope and Classes

Instructions

Complete the following assignments. Copy and paste your finished code into a Word document, clearly identifying which assignment it is. Also, capture the output of the program and paste that into the Word document. If there are questions to be answered, put the answers after the output. When you complete all three of this week’s assignments, save the document as yourLastName_GSP115_W7_Assignments.docx. Submit to the Week 7 assignment Dropbox.

1. Debugging Challenge

You should be busy designing and writing your expansion to the Course Project, so this week’s assignment will be a debugging challenge. We have revised the slot machine code to make the payouts easier to change, but a lot of bugs were created in the process—both compile time and run-time bugs. Your job is to get the code running correctly. As before, the code may look like it’s working but could still have the occasional bug that only rarely shows up. You will only be held responsible for bugs that cause a problem that can be detected. All other bugs will be declared as features or somebody else’s problemin honor of an age-old computer game development tradition.

Here are some clues.

·         You shouldn’t see any blank symbols.

·         There are only three bugs.

This version of the slot machine gets its payout table from a text file. The text file is a series of four numbers, such as 2, 2, 2, and 10. The first three are symbol numbers, and they match the enum numbers. In this case, 2 is Orange. The last number is the payout, so the set of numbers can be interpreted as Orange, Orange, Orange pays out 10. As a result, you can change the pay out by changing the table. However, to save space, payouts for the Cherry are hard coded in to the check4Win function. This was a short cut, but the Cherry payouts could have been set in the text file. In case you haven’t already figured it out, you will need to create the text file and put it in the same folder as your main.cpp file. Here is a copy of the text in the text file this program was tested with.

0 0 0 1 1 1 1 10 2 2 2 15 3 3 3 20 4 4 4 40 5 5 5 200 4 4 2 25 4 4 3 30

Here is the code.

// Week 7 Assignment-1

// Description:

//----------------------------------

 

//**begin #include files************

#include<iostream>// provides access to cin and cout

#include<iomanip>

#include<array>

#include<vector>

#include<sstream>

#include<fstream>

//--end of #include files-----------

//----------------------------------

 

usingnamespacestd;

//----------------------------------

 

//**begin global constants**********

// number of positions on a reel (10)

constintreelPositions = 11;

// create enum for symbols

enum symbol

{

        Lemon, Cherry, Orange, Bell, Bar, Jackpot

};

 

 

// define a struct for slot machine wheel

struct Wheel

{

        array<string, reelPositions> symbols;

        array<symbol, reelPositions>eSymbols;

        int position;

        string selected;

};//--end of global constants---------

//----------------------------------

 

//**begin function prototypes*******

voidloadWinSheet(vector <array<int,4>>&);

int check4Win(vector <int>, vector <array<int,4>>&, int);

//void createSlotMachine(array <Wheel, 3>&);

//--end of function prototypes------

//----------------------------------

 

//**begin main program**************

int main()

{

        // seed random number generator

        srand(time(NULL));

        // create the payout table

        // define a vector for the payout table

        vector<array<int,4>>winSheet;

        loadWinSheet(winSheet);

        //create an array of three slot machine wheels

        array<Wheel, 3>slotMachine =

        {

                {

                        {

                               {"Orange", "Cherry", "Orange", "Lemon", "Orange", "Bar", "Lemon", "Bell", "Jackpot", "Bell"},

                                {Orange, Cherry, Orange, Lemon, Orange, Bar, Lemon, Bell, Jackpot, Bell},

                                0,"Orange"

                        },

                        {

                                {"Bell", "Lemon", "Orange", "Bar", "Jackpot", "Bar", "Lemon", "Cherry", "Jackpot", "Bell"},

                                {Bell, Lemon, Orange, Bar, Jackpot, Bar, Lemon, Cherry, Jackpot, Bell},

                                1,"Lemon"

                        },

                        {

                               {"Cherry", "Lemon", "Bar", "Lemon", "Orange", "Orange", "Lemon","Cherry", "Jackpot", "Bell"},

                                {Cherry, Orange, Bar, Lemon, Orange, Orange, Lemon, Cherry, Jackpot, Bell},

                                3,"Bar"

                        }

                }

        };

 

        boolgameOn = true;

        intthePot = 100;

        bet = 1;

        bool winner = false;

        int winnings = 0;

        charcheckKey ='\n';

        vector<int> combo;

        cout<<"Hit 'enter' to bet. Hit 'space' and 'enter' to quit."<<endl;

        while (gameOn)

        {

                for (auto&s: slotMachine)

                {

                        s.position=(s.position + rand()%reelPositions)%reelPositions;

                        s.selected = s.symbols[s.position];

                        cout<<setw(10) << left <<s.selected.c_str() ;

                        combo.push_back(s.eSymbols[s.position]);

                }

                winnings = check4Win( combo, winSheet, -bet);

                if (winnings > 0) cout<<"You win "<< winnings <<"!   ";

                thePot += winnings;

                cout<<"You now have $"<<thePot<<endl;

                combo.clear();

                cout<<endl;

                if (thePot<= 0) gameOn = false;

                cin.get(checkKey);

                if (checkKey != '\n') gameOn = false;

        }

        while (!cin.get()){};

        if (winner) cout<<"You walk away a winner."<<endl;

        elseif (thePot> 0) cout<<"Good bye."<<endl;

        elsecout<<"You have lost all your money."<<endl;

        // Wait for user input to close program when debugging.

        cin.get();

        return 0;

}

//--end of main program-------------

//----------------------------------

 

//**begin function definitions******

// loads the pattern payout table from a text file

voidloadWinSheet(vector <array<int,4>>&pT)

{

        stringstreammyStream;

        ifstreaminFile;

        stringmyString;

        array<int, 4> combo;

        int pay;

        inFile.open("paytable.txt");

        if (inFile.is_open())

        {

                while ( getline (inFile,myString) )

                {

                        myStream<<myString;

                }

                inFile.close();

        }

        while (!myStream.eof())

        {

                myStream>> combo[0] >> combo[1] >> combo[2] >> combo[3];

                pT.push_back(combo);

 

        }

        return;

}

// Check for winning patterns

int check4Win(vector <int> pattern, vector <array<int,4>>&pT, inttheBet)

{

        for(auto p: pT)

        {

                if (((pattern[0] == p[0]) && (pattern[1] == p[1]) ) && (pattern[2] == p[2])) return p[3];

                if ((pattern[1] == Cherry) && (pattern[2] == Cherry)) return 3;

                if (pattern[2] == Cherry) return 1;

        }

        return -theBet;

}

//--end of function definitions------

//----------------------------------

Attachments:

Answers

(5)
Status NEW Posted 31 Oct 2017 12:10 PM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)