Assignment 06

HOMEWORK #6

CS 53

Due: Friday, Oct. 12, 2012, at noon, 100 points

For this assignment you will submit (in the usual way) multiple files. These files will contain a C++ program that you have named appropriately, each file with an appropriate name and appropriate extension. Be sure that your program compiles using the g++ compiler before you submit it. To compile a program with multiple files, use the usual g++ command but instead of the single file you compiled before, compile *.cpp and the compiler will "grab" all the cpp files in that directory. So, you see, it's important that you put all the files for a particular program in their own directory! You don't have to list the header files; that will happen automatically. Use cssubmit in the usual way.

Background: assignment #4. You might have noticed while you were coding hw 4 that you were repeating code. As I said in class, this is NOT a good situation. Why? First, a waste of time. Second, if you ever need to fix the code, you have to fix it in multiple places and you are almost guaranteed to make a mistake in one of those multiple places. Furthermore, this angers Krusty and he becomes HUGE and irate (see image below).1

This is just one motivation for using functions in your programs. I've discussed others in class. You know what they are.

Specifications: Your program is to be a re-coding of the solution to hw 4, but this time using functions for all the good reasons that you and I both know. There is one modification of the functionality of the program that we demand. When options 2 or 3 are chosen, your program will not convert from decimal (base 10) to binary (base 2) or binary to decimal, respectively. It will convert to or from the base that the user specifies. Thus, in option 2, you will have to query the user for the base to which they wish to convert their decimal input. And, for option 3, you will again have to query the user for the base their input is supposed to be and then convert it. Thus, you will have to modify your menu a bit. We suggest this:

Menu 1. Enter a value 2. Display value in another base 3. Display value in decimal (base 10) 4. Display the largest digit in the input 5. Quit

After options 2 and 3 are chosen, an appropriate query for base is made. Note: you will not accept any base larger than 10. And, of course, you will need to validate their base value with their input value; e.g. input of .3452 cannot be base n < 6. Think carefully how to write your code efficiently, using the functions that you write in effective ways.

Details: There are many ways for you to divide this program into functions. It's going to be up to you. You will be graded on how well you do this - how efficient the code is, how effective you functions are, how clean/clear your main function becomes, how easy is is to understand your code, how maintainable the code is. I suggest you map out the program before you get started. Think carefully about the functions. Pseudo-code it to help you.

Here is an example of pseudo-code for a main function for this project:

begin main declare vars greet user repeat until quit present menu act upon choice option 1 get user input flag input done option 2 if input done query base convert otherwise error message option 3 . . . etc . . . end main

Note: Don't underestimate the time that it will take to write this program! Also, you should know that solution code for program #4 is out there on the web ... where you are now....but in a different place. You are welcome to gain ideas and thoughts from that code, but you are NOT welcome to copy 'n paste n'stuff, like.

When you submit the submit script will compile and execute your program in the process. This means that you will be the "user" of the program for that few minutes. Now, in order that the grader isn't driven crazy by a multitude of inputs/outputs, you will ALL input the same values so that he has uniform output to grade. They are:

    • option 1 and enter .345

    • option 2 and enter base 11

    • option 2 and enter base 10

    • option 2 and enter base 4

    • option 3 and enter base 5

    • option 3 and enter base 7

    • quit

As always, if you have questions, don't hesitate to ask your instructor or the LEAD tutors.

1This is more evident the larger your viewing screen is.