Clarification: You can assume that the number entered by the user is not too big to fit in the computer's int data type. You will probably need to make an assumption about how many bits are needed to represent the number; make an assumption you think is reasonable and document it in the program header. (For example, if you assume 4 bits will be enough, you would include in the program header a comment like "Input is a non-negative decimal integer X, with X < 16.")
Examples:
Clarification: You can assume that B is non-zero.
To solve this problem, it may be useful to know that each character is represented inside the computer as a small integer. For example, try the following lines of code:
int x = 'a'; cout << x << endl;One should be very careful about treating characters as integers since the same character may be represented using different numbers on different computers. However, it is fairly safe to write the following loop to print all the lowercase characters a, b, ..., z.
char c = 'a'; while (c <= 'z') { cout << c << endl; c += 1; }
Correction: For this problem, your output may be more than you want to print out and turn in. If that is the case, print a sample of the output (a page's worth, say) and indicate how many text strings your program prints in all.
Additional hint: You can capture output of a program into a text file outputfile like this (assuming your program executable is named a.out):
a.out > outputfileYou can then view outputfile with vi, print it with lpr, etc.
Clarification: Input to this program is somewhat long and complicated. First, each row in the table is represented by a line containing two characters and a number (F T x). (This is meant to represent a currency exchange rate, i.e., to convert currency F to currency T, we should multiply by x.) For example, the line d p 0.25 represents a row in the table indicating that to convert currency d (dollars?) to currency p (pounds?) we should multiply by 0.25. The end of the table is signalled by a line consisting of two characters (could be any characters) and the number 0. This is followed by one more line of input that contains two currency names (called a and b in the above) and an amount (A). Your program should look for a table row showing how to convert from a to b and use it to convert amount A. So for example with the table row shown previously, if the final line is d p 100.0, your program should compute and print 0.25 * 100.0 or 25.0. (You don't need to worry about how many decimal places are printed.)
Sample inputs and desired output:
d p 0.25 p d 4.0 d y 1.05 d e 0.95 z z 0.0 p d 100.0the program should print 400.
d p 0.25 p d 4.0 d y 1.05 d e 0.95 z z 0.0 d e 101.0the program should print 95.95.
d p 0.25 p d 4.0 d y 1.05 d e 0.95 z z 0.0 d z 100.0the program should print an error message, such as "Requested conversion is not in table."
Because it would be very tedious to type in the whole table every time, I suggest that you put your input data in files and use input redirection. So to test your program with the examples above, you could put the input lines shown in three text files (which you can create with whatever text editor you use to write your programs -- vi, emacs, etc.). If your program executable is called a.out, and you have put the above sets of input data in files called input1.data, input2.data, and input3.data, you can run the program by saying:
a.out < input1.data a.out < input2.data a.out < input3.data
Also, you will probably have to make an assumption about the maximum number of entries in the table. As in the binary-to-decimal problem, make an assumption that seems reasonable to you and document it in the header of your program.