I'm having issues linking the main program to the function program/file. Not sure whats causing the error. This is the first time I'm linking to programs together. Also I'm having a issue designing a function to convert a "float int" into binary. Any help would be appreciated.
Thank you,
Robert Brown
---------------------BinaryPrograms.cpp---------------------------------------
Code:
// Programmer: Robert Brown
// Project Number: 1
// Project Desc: Binary Representation of Data
// Course: Data Structures
// Date: Sep. 03, 2011
//
// Write a small main program (driver) to test your functions.
// It should be menu-driven.
//
// 1) A function called printChar that takes a character (char) argument.
// The function should print the binary representation of the character
// argument.
// 2) A function called printShort that takes a short integer (short) argument.
// The function should print the binary representation of the short argument.
// 3) A function called printFloat that takes a single-precision floating-point
// float) argument. The function should print the binary representation of
// the float argument.
#include <iostream>
using namespace std;
// include the PrintFunctions program file
#include "PrintFunctions.cpp"
int main()
{
// declare objects of PrintFunction
printChar();
printShort();
printFloat();
int choice;
char charValue;
int intValue;
float floatValue;
// Display menu
do
{
cout<< "\nMenu: \n";
cout<< "\t1 - Print the binary representation of a character.\n";
cout<< "\t2 - Print the binary representation of a short integer\n";
cout<< "\t3 - Print the binary representation of a float\n";
cout<< "\t4) Exit program. \n\n";
cout << "Enter your choice ( 1, 2, 3, or 4): ";
cin>>choice;
//
if (choice >=1 && choice <=4)
{
// WHICH CHOICE DID USER SPECIFY?
switch(choice)
{
// GET INPUT
case 1:
cout << "\nEnter a character (-9999 to Stop): " << endl;
cin>>charValue;
while (charValue != -9999)
{
//
// THE FUNCTION RECEIVES VALUE.
printChar(charValue);
cout << "Enter a character (-9999 to Stop): "<<endl;
cin>>charValue;
}
break;
//
//
// GET INPUT
case 2:
cout<<"\nEnter a short: (-9999 to Stop): " << endl;
cin>>intValue;
while (intValue != -9999)
{
//
// THE FUNCTION RECEIVES VALUE.
printShort(intValue);
cout << "Enter a short: (-9999 to Stop): " << endl;
cin>>intValue;
}
break;
//
//
// GET INPUT
case 3:
cout<<"\nEnter a float: (-9999 to Stop): " << endl;
cin>>floatValue;
while (floatValue != -9999)
{
//
// THE FUNCTION RECEIVES VALUE.
printFloat(floatValue);
cout << "Enter a float: (-9999 to Stop): " << endl;
cin>>floatValue;
}
break;
//
//
// EXIT
case 4:
cout<<"\n\n\nProgram terminated successfully!\n\n\n";
system("pause");
break;
} // end case
}
else if (choice != 4)
{
cout << "\nThe valid choices are 1 through 4.\n";
cout << "\nSelect one of the valid choices.\n";
}
} while (choice != 4); // loop for more data
//
//
//
// DISPLAY TERMINATION MESSAGE
cout<<"\n\n\nProgram terminated successfully!\n\n\n";
system ("pause");
return 0;
} // END MAIN
---------------------2nd File : PrintFunctions.cpp------------------------------
Code:
// Programmer: Robert Brown
// Project Number: 1
// Project Desc: Binary Representation of Data
// Course: Data Structures
// Date: Sep. 03, 2011
//
// Function to convert a character into binary
char *printChar (unsigned char c)
{
static char bin[CHAR_BIT + 1] = {0};
int i;
for(i=CHAR_BIT - 1;i >= 0;i--)
{
bin[i]=(c%2) +'0';
c /= 2;
}
return bin;
}
// Function to convert a short integer into binary
int *printShort (int number)
{
int remainder;
if(number <= 1)
{
cout << number;
return;
}
remainder = number%2;
printShort(number >> 1);
cout << remainder;
}
// Function to convert a float integer into binary
float *printFloat (int)
{
}