First you'll need to create a directory and copy some files into it. For the prelab you should have created a subdirectory lab4 in your cps006 directory. If you didn't do this, make sure you do it now:
Do these five commands only if you didn't complete the prelab
cd cd cps006 mkdir lab4 cd lab4 cp ~ola/cps006/lab4/* .
cd cd cps006/lab4 pwd (make sure it's your lab4 directory) mkdir inlab cd inlab cp ~ola/cps006/lab4/inlab/* .
If you type the ls command you'll find three files
make drawtriangle
Then run the program twice entering 5 and 20 for the number of rows.
You should notice that for 5 stars the program printed a diagram like this:
* * * * * * * * * * * * * * *
Now, remove the comment marker// before the call to PrintSpaces and recompile the program. The for loop in PrintTriangle should look like
Before you run the program you should try to figure out how the diagram will change. This will be good practice for test questions.
Run the program and work hard to understand why and how the output changed.
Add this function to drawtriangle.cpp and then replace calls to PrintSpaces and PrintStars with calls to PrintStrings. The program should print the same shaped-triangle it did before you made the changes, i.e., the triangle whose top vertex is centered in the screen.
After making sure that PrintStrings works, modify the program so that the triangle is shaped as shown in the row below.
prompt> drawtriangle
how many rows: 10
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
You should be able to make this change by changing just the number of spaces printed before stars are printed in each row, i.e., by changing MIDDLE-k to some other expression.
As a hint, there are 78 spaces printed before the star in the first row, 76 spaces printed before the first star in the second row, 74 before the first star in the third row, and so on.
As long as the triangle has a "flat" right edge, it doesn't matter where the edge is located.
Make sure a TA sees your working drawtriangle program with the function PrintStrings.
The current version simulates a kind of slot machine by showing three random strings on a line, and showing seven lines each time the program is run.
You are to make three modifications to the program.
bool AllSame(string a, string b, string c) // post: return true if all strings are the same // otherwise returns false bool AllDifferent(string a, string b, string c) // post: return true if all strings are different // otherwise returns false
For example, if there only two strings, the function AllSame could be written as follows.
bool AllSame(string a, string b)
// post: returns true iff a and b are the same
{
return a == b;
}
You'll want to use either the and operator && or the or operator || in writing these two functions.
n You can ask the person near you for help if the TAs seem busy.
prompt> slots orange orange orange cherry lemon orange lemon orange orange cherry cherry cherry lemon lemon cherry lemon cherry lime orange orange cherry a loser prompt> slots lemon cherry orange lemon orange orange lime orange lemon lemon orange lemon cherry cherry cherry cherry lime cherry orange cherry lime a winner
Now call DoSlots(7) 10,000 times from main (write a loop) and accumulate a count of how many times the user wins. Print this result. Here's a start at the code in main, it's not complete.
int count=0;
for(int k=0; k < 10000; k++)
{
if (DoSlots(7))
{
}
}
write percentage here _______________
Be sure to call the TA over to check your program.
submit_cps006 lab4 *.cpp