Homework

Homework

# What it Looks Like to the UserThe program will loop, asking

Understand the Application What it Looks...
Understand the Application

What it Looks Like to the User

The program will loop, asking the user for a bet amount from 0 to 100 (assume dollars, you can use ints or longs). If the user types a 0 that means she wants to quit. Otherwise, accept the amount as their bet and simulate a slot machine pull. Your program will print out a line that looks like a slot machine result containing three strings. Some examples are: BAR 7 BAR, 7 7 cherries, cherries BAR space, space BAR BAR, or cherries cherries BAR.

Each of the three positions in the string could be one of the following: "BAR", "7", "cherries" or "space".
Each of the three output positions is must be generated by your program randomly with probabilities:
BAR 1/2 (50%)
cherries 1/4 (25%)
space 1/8 (12.5%)
7 1/8 (12.5%)
Therefore, BAR should be the most frequent symbol seen and space or 7 the least frequent.
The following combinations should pay the bet as shown (note ORDER MATTERS):
cherries [not cherries] [any] pays 5 × bet (5 times the bet)
cherries cherries [not cherries] pays 15 × bet
cherries cherries cherries pays 30 × bet
BAR BAR BARpays 50 × bet
7 7 7 pays 100 × bet
After the pull, display the three strings regardless of the outcome. If the user did not win, tell him/her "Sorry, you lose.". If he won, pay him by displaying his winnings (his original bet times the winning factor from the above table). Then, repeat the whole process by requesting another bet amount.
Position counts! If you read the above bullet that contains the warning "ORDER MATTERS", you will see that cherries bar cherries pays 5× while cherries cherries bar pays 15× and bar cherries cherries pays nothing.

A Helper Class: TripleString

We create a new data type to use for this assignment: class TripleString. TripleString will consist of three private member strings as its basic data: (string1, string2, and string3). There will be few instance methods to support that data. The class will be very modest. Once defined, we will use it to instantiate TripleString objects that can be used in our main() method and/or the global-scope methods that main() invokes to simulate this casino project.

The Global-Scope Client Methods

Each global-scope method that you have to write to simulate this casino app plays a special role. For example, there will be one method that gets the bet from the user and returns it to main():

int getBet()
Another method will simulate a random pull of the slot machine -- it generates three random strings and returns them as a TripleString object to main():

TripleString pull()
An output method will be used at the end of each loop-pass when the user needs to see the results of her pull, and receive the news about how much she won (or not):

void display (TripleString thePull, int winnings )
We will describe each method -- and a few others -- in the next section.

The Program Spec

Class TripleString Spec

The first step in writing this program is to create a simple, working class TripleString.

The Data
It will contain three private member strings as its main data: string1, string2, and string3. We will also add a public static member which is to be a const int MAX_LEN set to 20. This represents the maximum length that our class will allow any of its strings to be set to. We can use MAX_LEN in the TripleString method whose job it is to test for valid strings (see below).

In summary, three private instances strings and one public static MAX_LEN. That's all the data for this class.

Default Constructor
TripleString() -- a default constructor that initializes all members to "". We do not need any parameter-taking constructors.

A Private Helper Method
bool validString( string str ) -- a helper function that the mutators can use to determine whether a string is legal. This method returns true if its length <= MAX_LEN and false, otherwise.

Mutators/Accessor
set()s and get()s for these members.

Where it All Goes
There are now a variety of program elements, so let's review the order in which things appear in your .cpp file:

includes and namespace
class prototype(s)
global-scope method prototype(s)
main() definition
global-scope method definition( )
class method definition(s)
After writing this class, test it using a simple main() which instantiates an object, mutates the members, displays the object, etc. Don't turn this test in. It's part of your development cycle.

The Global Scope Method Specs

int getBet()
This prompts the user for input and returns the bet amount as a functional return. It should vet the amount before it returns and insist on a legal bet (0 < bet < 100) until it gets one from the user. It must return the legal value to the client and not take any other action besides getting the legal amount.

TripleString pull()
This method instantiates and returns a TripleString object to the client. The data of the TripleString object has to be filled with three randomly chosen strings according to the probabilities described in the "Understand the Application" section above. For example, it might return a TripleString object that contains the three strings ["cherries", "BAR" , "space"].

The way it determines and loads the three strings is by using another global scope helper method, described, next, randString(). So this method, pull() will call the next method randString() three times to get the three strings that will be stored into the TripleString object. Once that's done, pull() just returns the TripleString object to the client and its job is done.

string randString()
This helper method does a little work -- yet is still quite short. It produces and returns a single random string based on the required probabilities. It does this by calling the C++ rand() function and using the return result of that function as a means of deciding which of the four possible strings to return. Take this in stages. rand() returns an int between 0 and RAND_MAX. One idea (but not the only one) is to turn that into an int between 1 and 100 using techniques from five weeks ago. Then, decide which of those numbers should trigger a "7", which should trigger a "cherries", etc. based on the desired probabilities. Since a "Bar" should happen half the time, which numbers would you want to trigger a "Bar"? Since a "cherries" should happen 25% of the time, which numbers would trigger a "cherries"? So you see, this is a very simple -- and even short -- function, even though it has to be designed carefully. Common sense will go a long way here.

int getPayMultiplier (TripleString thePull)
After main() gets a TripleString object from pull() (which I will call thePull), it needs to know what the payout will be. That's the job of this function, getPayMultiplier(), which takes the TripleString result from pullString() (thePull) as a parameter, and inspects it to determine what its pay multiplier should be: 5? 15? 100? 0? It does this by looking at the three strings inside the passed-in TripleString object and using if statements to determine and return the right value. For example, if all three of the strings are "cherries", which is easily checked using an if statement, then this method returns a pay multiplier of 30. You can use logic like this to create a sequence of if or else if statements that will give you the desired multiplier. However you do it, the method will return one of the values; 0, 5, 15, 30, 50 or 100.

void display (TripleString thePull, int winnings )
This method takes the winnings (a dollar amount) and thePull as parameters and displays the three strings inside thePull along with " sorry - you lost " or "congrats, you won \$X".

main()'s Workflow
You can debug each of the above methods individually using a test main() that consists of a statement or two. That way you will make sure each component works before trying to write the final main() client.

main() will be a loop controlled by value returned from getBet(). As long as that value is non-zero, we keep playing.

Each time through the loop, we have to call pull() to get the pullString as a return value. Then we need to pass that to getPayMultiplier() to find the multiplier. We then compute the winnings based on the previous information, and finally we display it all using display(). That's all that each loop pass does. So main() is quite neat and clean.

Input Errors

The only place the user can make an input error is in getBet(), so that's the method that deals with such errors. Don't worry about non-numbers. Assume that a number was entered. But do test for range and only return to main after you have a valid range. getBet() may not decide about ending the program. That's up to main().

Test Run Requirements:

Submit one run that lasts about 20 to 40 pulls -- enough to see a few wins. At least once enter an illegal amount to make sure that your program handles it correctly.

General Requirements

Communicate all values as parameters or return values, not through globals. The meaning of these terms and examples are contained in the module reading.

Also, I will emphasize that in keeping with the separation of I/O and computation, we would not have any method other than display() output results to the screen, and display() is called from main(), not from any other method. Similarly, getBet() is the only method that does input. The other methods do no input, no output and do not call any methods that do input or output. Let's keep that idea fresh.
Show More
Show Less
5/21/2013
Ingo U, Software Engineer
Category: Homework
Satisfied Customers: 755
Experience: Over 25 years experience in software development. Expert in Microsoft .Net, C#, C++, VB, SQL
Verified
Hello,
what compiler/tools are you using for this? And, what is your deadline? I may be able to help.
Thanks,
Ingo U
Customer reply replied 4 years ago
Hi,
Deadline is wednesday at 1:00 p.m
And I am using Eclipse.
thanks

and let me know if you need me to make any changes.

Regards,
Ingo U
Hi,
just following up; were you able to download and use my code?
Thanks,
Ingo
Customer reply replied 4 years ago
Hi,
I am not able to run the program in my laptop.
It's showing bunch of errors.
can you make sure it runs on eclipse and send me.
so what should I do now.
thanks
Customer reply replied 4 years ago
may sure I can run the program in eclipse.
OK, I'll work on that. What compiler are you using inside eclipse? MinGW or cygwin?
Also, did you make sure to uncompress the zip folder I sent before trying to use the files? What specific errors are you getting?
Customer reply replied 4 years ago
I am using Xcode compiler.
ye I uncompress the zip folder also and there are bunch of errors.
Try this one:
The other 2 files were not changed. It needed an #include for stdlib.h to find rand() and srand(). I used eclipse with the cygwin toolchain, though.l Don't have Xcode.
If you're still getting errors, could you copy them and paste here?
Thanks!
Customer reply replied 4 years ago
Description Resource Path Location Type
Method 'setString1' could not be resolved santosh.cpp /santosh/src line 45 Semantic Error
Method 'setString2' could not be resolved santosh.cpp /santosh/src line 46 Semantic Error
Function 'rand' could not be resolved santosh.cpp /santosh/src line 31 Semantic Error
Method 'getString1' could not be resolved santosh.cpp /santosh/src line 54 Semantic Error
Method 'getString2' could not be resolved santosh.cpp /santosh/src line 54 Semantic Error
Method 'setString3' could not be resolved santosh.cpp /santosh/src line 47 Semantic Error
Type 'TripleString' could not be resolved santosh.cpp /santosh/src line 52 Semantic Error
Type 'TripleString' could not be resolved santosh.cpp /santosh/src line 65 Semantic Error
Type 'TripleString' could not be resolved santosh.cpp /santosh/src line 79 Semantic Error
Method 'getString3' could not be resolved santosh.cpp /santosh/src line 54 Semantic Error
Invalid overload of 'endl' santosh.cpp /santosh/src line 54 Semantic Error
Invalid arguments '
Candidates are:
int getPayMultiplier(?)
' santosh.cpp /santosh/src line 107 Semantic Error
Invalid arguments '
Candidates are:
void display(?, int)
' santosh.cpp /santosh/src line 108 Semantic Error
Function 'srand' could not be resolved santosh.cpp /santosh/src line 82 Semantic Error
Function 'time' could not be resolved santosh.cpp /santosh/src line 82 Semantic Error
make: *** [src/santosh.o] Error 1 santosh C/C++ Problem
TripleString.h: No such file or directory santosh.cpp /santosh/src line 7 C/C++ Problem
expected primary-expression before 'int' santosh.cpp /santosh/src line 52 C/C++ Problem
'TripleString' was not declared in this scope santosh.cpp /santosh/src line 52 C/C++ Problem
variable or field 'display' declared void santosh.cpp /santosh/src line 52 C/C++ Problem
'TripleString' does not name a type santosh.cpp /santosh/src line 41 C/C++ Problem
Type 'TripleString' could not be resolved santosh.cpp /santosh/src line 43 Semantic Error
Method 'getString1' could not be resolved santosh.cpp /santosh/src line 67 Semantic Error
Method 'getString2' could not be resolved santosh.cpp /santosh/src line 67 Semantic Error
Method 'getString1' could not be resolved santosh.cpp /santosh/src line 68 Semantic Error
Method 'getString2' could not be resolved santosh.cpp /santosh/src line 68 Semantic Error
Method 'getString3' could not be resolved santosh.cpp /santosh/src line 68 Semantic Error
Method 'getString1' could not be resolved santosh.cpp /santosh/src line 69 Semantic Error
Method 'getString2' could not be resolved santosh.cpp /santosh/src line 69 Semantic Error
Method 'getString3' could not be resolved santosh.cpp /santosh/src line 69 Semantic Error
Method 'getString1' could not be resolved santosh.cpp /santosh/src line 70 Semantic Error
Method 'getString2' could not be resolved santosh.cpp /santosh/src line 70 Semantic Error
Method 'getString3' could not be resolved santosh.cpp /santosh/src line 70 Semantic Error
Method 'getString1' could not be resolved santosh.cpp /santosh/src line 71 Semantic Error
Method 'getString2' could not be resolved santosh.cpp /santosh/src line 71 Semantic Error
Method 'getString3' could not be resolved santosh.cpp /santosh/src line 71 Semantic Error
comparison between signed and unsigned integer expressions Assignment05.cpp /Assignment05/src line 74 C/C++ Problem
comparison between signed and unsigned integer expressions Assignment05.cpp /Assignment05/src line 64 C/C++ Problem
comparison between signed and unsigned integer expressions Assignment05.cpp /Assignment05/src line 102 C/C++ Problem
comparison between signed and unsigned integer expressions Assignment05.cpp /Assignment05/src line 89 C/C++ Problem
Type 'TripleString' could not be resolved santosh.cpp /santosh/src line 41 Semantic Error

Those are the errors.
Did you include the files TripleString.cpp and TripleString.h in the project?
Or, would you prefer that I put all code in a single file?
Customer reply replied 4 years ago
yes
You can view this answer by clicking here to Register or Login and paying \$3.
Ingo U, Software Engineer
Category: Homework
Satisfied Customers: 755
Experience: Over 25 years experience in software development. Expert in Microsoft .Net, C#, C++, VB, SQL
Verified
Ingo U, Software Engineer
Category: Homework
Satisfied Customers: 755
755 Satisfied Customers
Experience: Over 25 years experience in software development. Expert in Microsoft .Net, C#, C++, VB, SQL

Ingo U is online now

A new question is answered every 9 seconds

• Ask an ExpertExperts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
• Get a Professional AnswerVia email, text message, or notification as you wait on our site. Ask follow up questions if you need to.

Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.

## What Customers are Saying:

Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help.

Mary C.Freshfield, Liverpool, UK

This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!!

AlexLos Angeles, CA

Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult.

GPHesperia, CA

I couldn't be more satisfied! This is the site I will always come to when I need a second opinion.

JustinKernersville, NC

Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around.

EstherWoodstock, NY

Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know.

RobinElkton, Maryland

He answered my question promptly and gave me accurate, detailed information. If all of your experts are half as good, you have a great thing going here.

DianeDallas, TX

< Previous | Next >

## Meet the Experts:

LogicPro

Engineer

5,672 satisfied customers

Expert in Java C++ C C# VB Javascript Design SQL HTML

Manal Elkhoshkhany

Tutor

4,549 satisfied customers

More than 5000 online tutoring sessions.

Linda_us

Finance, Accounts & Homework Tutor

3,138 satisfied customers

Post Graduate Diploma in Management (MBA)

Chris M.

M.S.W. Social Work

2,635 satisfied customers

Master's Degree, strong math and writing skills, experience in one-on-one tutoring (college English)

F. Naz

Chartered Accountant

2,158 satisfied customers

Experience with chartered accountancy

Bizhelp

CPA

1,887 satisfied customers

Bachelors Degree and CPA with Accounting work experience

Seanna

Tutor

1,781 satisfied customers

3,000+ satisfied customers, all topics, A+ work

< Previous | Next >

Related Homework Questions
I cannot get started with this assignment in my DBM 381
I cannot get started with this assignment in my DBM 381 class … read more
F. Naz
Chartered Accountant
CA Finalist & Completed B.com
2,158 satisfied customers
Need a biography on a important leader during the civil war.
Need a biography on a important leader during the civil war. I have chosen Stonewall Jackson. I need a title page, two sources at least one from a book, sources need to be cited under MLA format, work… read more
eth1819
Bachelor's Degree
118 satisfied customers
I am conducting two surveys and trying to figure out how
Hello,I am conducting two surveys and trying to figure out how many responses I need in order for the findings to be significant or generalizable. I sent surveys out to two different populations.Popul… read more
GLENN
Master of Mathematics
330 satisfied customers
BusinessTutor: HELP ME. I need you to do the problem solved.
BusinessTutor: HELP ME. I need you to do the problem solved. Look below: http://www.mediafire.com/?ojdihu5x6eyofne http://www.mediafire.com/?aeb9wdeb2o374yl (problems questions & answers) Its due asap… read more
Manal Elkhoshkhany
Tutor
Foundation classes for MBA
4,549 satisfied customers
Smallest unit of matter that has all the properties of an element
Please help I only have one hour: 1. Which of the following is the smallest unit of matter that has all the properties of an element? (Points: 4) molecule element atom compound electron 2. Isotopes of… read more
Bizhelp
CPA
Bachelor's Degree
1,887 satisfied customers
Historical Example of Labor Supply and Demand Submit a 250-
Historical Example of Labor Supply and Demand Submit a 250- to 300-word response addressing one of the following historical events in terms of labor supply and demand: the Great Depression, the Luddit… read more
Joanne
Bachelor\u0027s Degree
252 satisfied customers
A low pass filter has the following specifications:
A low pass filter has the following specifications: Fp=2.4MHz Lp=3dB Fs=6MHz Ls=40dB 1. Determine the required order of a Butterworth filter that meets the above specifications.… read more
Ashok Kumar
Master\u0027s Degree
291 satisfied customers
Random variable is normally distributed with a mean
Random variable is normally distributed with a mean of μ = 50 and a standard deviation of σ = 5. What is the probability the random variable will assume a value between 45 and 55 (to 4 decimals)? What… read more
R.R. Jha
Bachelor\u0027s Degree
150 satisfied customers
HEALTH, SAFETY, AND NUTRITION FOR THE CHILD 605844RR -
HEALTH, SAFETY, AND NUTRITION FOR THE YOUNG CHILD 605844RR - Preventing Illness and Injuries When you have completed your exam and reviewed your answers, click Submit Exam. Answers will not be recorde… read more
GLENN
Master of Mathematics
330 satisfied customers
I need the following flowchart for Car Class in MS Word. The
I need the following flowchart for Car Class in MS Word … read more
Dr. Donna Kakonge
Doctor of Education
193 satisfied customers
FOR Discussion Question 1 • Due Date: Day 2 [post to the
FOR ANGELA Discussion Question 1 • Due Date: Day 2 [post to the Main forum] • Post your response to this question: Consider the statement “psychology has a long past but a short history.” What do you … read more
Seanna
Tutor
1,781 satisfied customers
When I open a word document it has a character string 20 and
When I open a word document it has a character string 20 and places that character after I type each line. This is just a recent problem and. How can have work not insert that character?… read more
F. Naz
Chartered Accountant
CA Finalist & Completed B.com
2,158 satisfied customers
I need help regarding javascript with custom objects and
I need help regarding javascript with custom objects and constructors. I am having trouble calling an onclick function in a form to an array.… read more
LogicPro
Engineer
Bachelor of Technology
5,672 satisfied customers
Fiscal restraint is defined as: a. Tax hikes or spending
Fiscal restraint is defined as: a. Tax hikes or spending cuts intended to reduce aggregate demand. b. Tax hikes or spending cuts intended to increase aggregate demand. c. Tax cuts or spending hikes in… read more
Chris M.
M.S.W. Social Work
Master's Degree
2,635 satisfied customers
Explain the types purpose and function of materials and
Explain the types purpose and function of materials and equipment needed for the administration of medication via the different routes … read more
Dr. Donna Kakonge
Doctor of Education
193 satisfied customers
I have a couple of basic java questions i need answered.
I have a couple of basic java questions i need answered … read more
LogicPro
Engineer
Bachelor of Technology
5,672 satisfied customers
The Use case diagram for a tracking system using clusters of
The Use case diagram for a tracking system using clusters of sensors. I am now in phase 3 and I did all the documentation but I need to deeply understand the logic behind the IoT to proceed correctly … read more
Dr. Donna Kakonge
Doctor of Education
193 satisfied customers
This week you'll be making the following refinements to the
This week you'll be making the following refinements to the class that you wrote in the last assignment. All the requirements from that class are still in force. For example, all MyStrings must always… read more
LogicPro
Engineer
Bachelor of Technology
5,672 satisfied customers
Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Show MoreShow Less