Chapter 9 Topics: Introduction to Pointers Problem 1 (20 points) Name lab2out.ep
ID: 3746178 • Letter: C
Question
Chapter 9 Topics: Introduction to Pointers Problem 1 (20 points) Name lab2out.epp Write a C++ program tha entered as the dealer. First, wments a basie 2-player card game. One player represents you while the 2ad player entered as an integer value as an integeyour program will allow the user to enter a wager amount. The wager is always must e and must be greater than or equal to S5. You will use the getWager function to accomplish this -see the required functions section: The getwager function will perform all data validation An input example the wager amount is greater than or getWager function will equal to S5 is shown below: C:IWINDO WSIsystem321cmd.exe nter your wager: ($5 nininun): 18 Once the user has entered a wager greater than or equal to $5, your program will perform the card game. Your game will utilize the following rules: The game is played with a standard deck of cards. There are 4 suits - hearts (), diamonds (), clubs () and spaids (). There are 13 possible cards associated with each suit. These cards, and the amount of points Rules associated with each card are shown below in Table 1:Explanation / Answer
Hey! Here is what I can assist you with.
Considering type of game. It is not possible to fully eliminate "if else".
But we can avoid it in most cases as follows-
1. We can make some changes in driver function. while calling display and deal function we can pass reference which is subsequent to pc1 (assumed base pointer)
int *pc1,*pc2,*deal1,*deal2;
pc2 = pc1+1;
deal1 = pc2+1;
deal2 = deal1+1;
// Now give call to display function.
//Inside display function we can use for loop to refer to all four cards pointers
for(int i=pc1; i<=deal2; i++)
{
// here you can have access to every card no using i*
}
2. Card No and Correspoding points are same till the Card No - 10. We can directly use card no as point while calculating score.
e.g.
yourTotal = *pc1 + *pc2;
dealerTotal = *deal1 + *deal2;
1. Display function : we can avoid using if else statement for every different card to show
Solution :
string str1,str2,str3;
String card1,card2,card3,card4;
str3 = ".bmp";
str1 = "h";
str2 = *pc1;
card1 = str1 + str2 + str3;
str1 = "s";
str2 = *pc2;
card2 = str1 + str2 + str3;
str1 = "d";
str2 = *deal1;
card3 = str1 + str2 + str3;
str1 = "c";
str2 = *deal2;
card4 = str1 + str2 + str3;
// Open card image using file name stored in card string variable