Contents

Overview

We have just learned about recursion. The goal of this assignment is to give you practice applying a divide-and-conquer strategy to problems and using that to establish a recursive solution. This assignment consists of several unrelated problems, but that you will implement in a single C++ program. You will start from the partially implemented skeleton below. The skeleton includes a function to interact with the user to test the various solutions you've come up with. You need to implement the portions with comments that read // TODO: IMPLEMENT THIS..

There are four problems you need to implement, and you can create additional functions if you need (e.g., to implement multiple recursion if that's required by your solution). They are:

Here's an example of my version of PA1 running (my input is in orange just to make it obvious):

$ ./pa1 
Pick an operation to perform. One of: 
    mod a b (mod a by b)
    commas a    (insert commas into a)
    minPos x b  (find the min. positions to represent x in base b)
    toBinary x  (convert x to binary)
    quit    (exit)
: mod 13 2
1

Pick an operation to perform. One of: 
    mod a b (mod a by b)
    commas a    (insert commas into a)
    minPos x b  (find the min. positions to represent x in base b)
    toBinary x  (convert x to binary)
    quit    (exit)
: commas 29293484
29,293,484

Pick an operation to perform. One of: 
    mod a b (mod a by b)
    commas a    (insert commas into a)
    minPos x b  (find the min. positions to represent x in base b)
    toBinary x  (convert x to binary)
    quit    (exit)
: minPos 127 2
7

Pick an operation to perform. One of: 
    mod a b (mod a by b)
    commas a    (insert commas into a)
    minPos x b  (find the min. positions to represent x in base b)
    toBinary x  (convert x to binary)
    quit    (exit)
: toBinary 127
1111111

Pick an operation to perform. One of: 
    mod a b (mod a by b)
    commas a    (insert commas into a)
    minPos x b  (find the min. positions to represent x in base b)
    toBinary x  (convert x to binary)
    quit    (exit)
: quit
Bye!
(Back to top)

Requirements

Here's a skeleton to get you started:

PA1 Skeleton
(Back to top)

Extra credit

Make sure you indicate in your program header (in the description) whether you've attempted the extra credit, otherwise I won't count it!!!

EC-1 (2 points)

Make a new recursive function to convert a decimal into octal (0–7) or hexadecimal (0–f).

(Back to top)

Submissions

Everything should be uploaded to Canvas by the deadline posted.

(Back to top)