//Group Names: Daniel Gonzalez, Katrina Lawson, Arlene Darr, Benn Ruan, Vu Pham //Group Project //File Name: StringConvert.cpp //Discription: This program will convert a Sentance into Hex, Oct, and Dec //********************************************************************** // Header Files / Prototypes //********************************************************************** #include #include #include #include void binary(int number); void PrintOut (int StrSize, int IntString[]); //********************************************************************** // MAIN //********************************************************************** void main() { const int size = 101; char CharString[size]; int IntString[size], StrSize; cout << "This program will display an inputed line in it's" << endl << "ASCI character format in Decimal, Hex, Octal, and Binary." << endl << endl; cout << "Please type in a sentance that you would like to convert :\n"; cin.getline(CharString,size,'\n'); StrSize = strlen(CharString); for (int index=0; index < StrSize; index++) IntString[index] = (int)CharString[index]; PrintOut (StrSize, IntString); return; } //********************************************************************** // Convert to Binary //********************************************************************** void binary(int number) { int remainder; if(number <= 1) { cout << number; return; } remainder = number%2; binary(number >> 1); cout << remainder; } //********************************************************************** // Print Conversion //********************************************************************** void PrintOut (int StrSize, int IntString[]) { int index; cout << endl << "The sentance that you entered has an ASCI code\n"; cout << "in Decimal (Base 10) of :\n"; for (index=0; index < StrSize; index++) cout << setw(4) << IntString[index]; cout << endl; cout << "\nin Hexadecimal (Base 16) it is :\n"; for (index=0; index < StrSize; index++) cout << setw(3) << hex << IntString[index]; cout << endl; cout << "\nin Octal (Base 8) it is :\n"; for (index=0; index < StrSize; index++) cout << setw(4) << oct << IntString[index]; cout << endl; cout << "\nand in Binary (Base 2) it is :\n"; for (index=0; index < StrSize; index++) { binary (IntString[index]); cout << " "; } cout << endl; return; }