harm(n)
: It computes the SUM of the first n terms of the harmonic
series, 1/1 + 1/2 + ... 1/n.
tri(1, n)
: It prints out an isosceles triangle with height n
and width 2n-1 (see the sample run).
diamond(1, n)
: It prints out a diamond with height 2n-1 and
width 2n-1 (see the sample run).
Each function must be recursive. Add no loop in your code. You can use only rep() given in the source code.
~/$ ./part1 n? 1 harm(1) = 1 tri(1, 1): * diamond(1, 1): * |
~/$ ./part1 n? 2 harm(2) = 1.5 tri(1, 2): .*. *** diamond(1, 2): .*. *** .*. |
~/$ ./part1 n? 3 harm(3) = 1.83333 tri(1, 3): ..*.. .***. ***** diamond(1, 3): ..*.. .***. ***** .***. ..*.. |
~/$ ./part1 n? 4 harm(4) = 2.08333 tri(1, 4): ...*... ..***.. .*****. ******* diamond(1, 4): ...*... ..***.. .*****. ******* .*****. ..***.. ...*... |
~/$ ./part1 n? 10 harm(10) = 2.92897 tri(1, 10): .........*......... ........***........ .......*****....... ......*******...... .....*********..... ....***********.... ...*************... ..***************.. .*****************. ******************* diamond(1, 10): .........*......... ........***........ .......*****....... ......*******...... .....*********..... ....***********.... ...*************... ..***************.. .*****************. ******************* .*****************. ..***************.. ...*************... ....***********.... .....*********..... ......*******...... .......*****....... ........***........ .........*......... |
~/bin/submit -c=IC210 -p=lab09 part1.cpp
Modify the program so that the hands are printed out sorted by face value (smallest to largest) with ties broken by suit (clubs before diamonds before hearts before spades).
before | ~/$ ./part2 seed? 2019 Player1: A♠ 7♠ K♠ 6♥ 9♥ 6♠ 5♦ Player2: K♦ Q♠ 9♦ A♥ 4♥ 7♦ Q♦ |
after | ~/$ ./part2 seed? 2019 Player1: 5♦ 6♥ 6♠ 7♠ 9♥ K♠ A♠ Player2: 4♥ 7♦ 9♦ Q♦ Q♠ K♦ A♥ |
before | ~/$ ./part2 seed? 2017 Player1: 4♥ 2♣ K♣ K♥ 10♥ 9♠ 3♥ Player2: 5♣ 6♠ Q♠ 8♣ J♠ Q♥ 9♥ |
after | ~/$ ./part2 seed? 2017 Player1: 2♣ 3♥ 4♥ 9♠ 10♥ K♣ K♥ Player2: 5♣ 6♠ 8♣ 9♥ J♠ Q♥ Q♠ |
~/bin/submit -c=IC210 -p=lab09 part*.cpp
part3.cpp
.
// In: string s representing a face value or a full card (e.g. "10" or "J")
// Out: the facevalue (2-14) represented by the string
int stringToFaceValue(string s);
int stringToFaceValue(string s)
{
char c = s[0];
int fv = c - '0';
if (c == '1') fv = 10;
if (c == 'J') fv = 11;
if (c == 'Q') fv = 12;
if (c == 'K') fv = 13;
if (c == 'A') fv = 14;
return fv;
}
'X'
is entered as a
card choice.
~/$ ./part3 seed? 2019 Player1: 5♦ 6♥ 6♠ 7♠ 9♥ K♠ A♠ Player2: 4♥ 7♦ 9♦ Q♦ Q♠ K♦ A♥ Player1 choose card: 4 yes Player1: 5♦ 6♥ 6♠ 7♠ 9♥ J♣ K♠ A♠ Player2: 4♥ 7♦ 9♦ Q♦ Q♠ K♦ A♥ Player2 choose card: Q go fish Player1: 5♦ 6♥ 6♠ 7♠ 9♥ J♣ K♠ A♠ Player2: 4♥ 7♦ 9♦ J♥ Q♦ Q♠ K♦ A♥ Player1 choose card: 10 go fish Player1: 3♣ 5♦ 6♥ 6♠ 7♠ 9♥ J♣ K♠ A♠ Player2: 4♥ 7♦ 9♦ J♥ Q♦ Q♠ K♦ A♥ Player2 choose card: A yes Player1: 3♣ 5♦ 6♥ 6♠ 7♠ 9♥ J♣ K♠ A♠ Player2: 4♥ 7♦ 9♦ J♥ Q♦ Q♠ K♦ A♣ A♥ Player2 choose card: X
~/bin/submit -c=IC210 -p=lab09 part*.cpp