Part 1: recurse a bit

Download part1.cpp. You have to complete three functions:
  1. harm(n): It computes the SUM of the first n terms of the harmonic series, 1/1 + 1/2 + ... 1/n.
  2. tri(1, n): It prints out an isosceles triangle with height n and width 2n-1 (see the sample run).
  3. diamond(1, n): It prints out a diamond with height 2n-1 and width 2n-1 (see the sample run).
Requirement:

Each function must be recursive. Add no loop in your code. You can use only rep() given in the source code.

A sample run (with user input in red).
~/$ ./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):
.........*.........
........***........
.......*****.......
......*******......
.....*********.....
....***********....
...*************...
..***************..
.*****************.
*******************
.*****************.
..***************..
...*************...
....***********....
.....*********.....
......*******......
.......*****.......
........***........
.........*.........

Submit

 ~/bin/submit -c=IC210 -p=lab09 part1.cpp

Part 2: sorting fish ... more cards? Really?

Download part2.cpp, which is a start at implementing a game of Go Fish. Right now, the game simply deals out seven cards to two players, and prints out those players' hands.

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♠  

Submit

 ~/bin/submit -c=IC210 -p=lab09 part*.cpp

Part 3: searching for fish ... yep, more cards!

Copy part2.cpp to part3.cpp.

My gift

To make your life a bit easier, and to allow you to concentrate on search, which is what this is really about, I'm gifting you the following function:

// 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;
}

Your task

The program should work as follows:
~/$ ./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

Submit

 ~/bin/submit -c=IC210 -p=lab09 part*.cpp

Part 4: Going Further ... Go Fish

Now make a full Go Fish game. In the complete game you could have player2's cards not printed out, and have player2 just randomly choose a card from his deck to ask for. If you were really ambitious, you could write it so player 2 followed a sophisticated strategy!