> Need help with C++ Data structures class This is the feed back I got from my instructor, but need help understanding.?

Need help with C++ Data structures class This is the feed back I got from my instructor, but need help understanding.?

Posted at: 2014-12-18 
Your "void printChar();" prototype describes a function that takes no input and produces no result. The only thing it can do is produce a side-effect. I can't imagine any such operation that I'd want to call "printChar".

Your professor wants a printChar that accepts a char value as input and returns some thing printable that can be sent to cout using the << operator. That's probably some kind of string.

Do you know about C++ strings yet? Those are defined in the header. If not, you probably need C strings, and tools for dealing with those are in the header. I don't see either in your code.

By the way, the header to use in C++ is , not .

Anyway, if the goal is to produce a function that converts a char to binary representation, the prototype should be one of:

std::string printChar( char ch ); // C++ string

const char *printChar( char ch); // C string

The C++ string is better, since it will manage memory safely. The C string version will probably have to use a static buffer to store the returned string, meaning the caller must use and forget the result before the next call to printChar().

I need, a function called printChar that takes a character (char) argument. That is, you need to be able to write a program that uses your printChar function like this:

cout << setw(8) << printChar( ‘A’); or: cout << setw(8) << printChar( static_cast(67));

My printChar, printShort and printFloat functions do not take arguments.

To do anything useful, you need to be able to decide what prints in addition to the binary representation. Any extra stuff printed in your functions may interfere with what you want to do. These statements belong in your driver, not in the print functions:

cout << "\n" ;

cout << " The binary representation for " << inputCharacter << " is: ";

. . .

cout << endl; cout << endl;

2.You need to keep the code for the print functions separate from the program to test the print functions. You included the code for your test functions displayMessage() and mainProcess() in the file with your test functions.

Lab1:

// To print the binary representation of a Character, a integer, and a float.

#include

#include

#include

using namespace std;

// Function prototypes

void displayMessage();

void mainProcess();

bool done( );

void printChar();

void printShort();

void printFloat();

#include "output.cpp"

// Function: main

int main()

{ displayMessage();

mainProcess();

bool done( );

system ("pause");

return 0; }