Number Converter


CS 2308

Due: Monday 5/4/15 at 10:00pm
100 points


As part of our studies of Abstract Data Types, we will be using a stack to solve a problem.

Given an integer in base 10 (decimal) your task is to convert to another base (2-16). We will discuss the algorithm in class.
Decimal  0123456789101112131415
Hexadecimal  0123456789ABCDEF
Octal  012345671011121314151617
Binary  01101110010111011110001001101010111100110111101111

We will be using the Stack provided by the Standard Template Library (STL)



Input to program:

We will get the input to the program form the command line in the following format.

prompt> progName numberToConvert newBase 

For example:

linux prompt > ./convert 27 2

27 - base 10

11011 - base 2

linux prompt > ./convert 29 8

29 - base 10

35 - base 8

linux prompt > ./convert 44 16

44 - base 10

2C - base 16


You must name your turned in file:   converter_xxxxxx.cpp   where xxxxxx is your TXstate id number. 

Note: The function atoi(char *), included in the library cstdlib will convert a C-style string to an integer.

To convert an int to a string you can do the following:
#include <sstream>
...
int a = 10;
stringstream ss;
ss << a;
string str = ss.str();

Upload your solution on TRACS

Note: This program must be done using a Linux environment using the G++ compiler. You really need to learn how to use Linux and an editor!

There is a lot of help regarding Linux, the STL, editors, stacks, everything, on the web. Use it.


Last Updated: 4/27/15