Hi, Need clarity on a comsci project... Don't understand what it's asking for

The directions are to "complete functions code() and sum(), which are called by the main() program. Do not make any changes to the main() or to function declarations. All variables you declare must be local."

I just don't understand what it's asking. If someone could please clarify how I should go about I'd appreciate it. Thank you very much.


Here is the skeleton code.

#include <iostream>
#include <string>
using namespace std;

// GLOBAL CONSTANT DECLARATIONS
const int CHARACTER_OFFSET = 33; // Character offset
const int CHARACTER_RANGE = 93; // Character range
const int CHARACTER_MODULUS = 94; // Character modulus
const int CHECKSUM_MODULUS = 10000;// Checksum modulus
const char SPECIAL_LIMIT = ' '; // Special character limit
const char UPPER_LIMIT = '~'; // Upper character limit
const char CARET = '^'; // Caret character

string code (char key, char in); // Encode a character
string sum (string in); // Generate a string checksum

int main()
{
bool done; // Done indicator
char key; // Key character
int pos; // Input line position
string iline; // Input line
string oline; // Output line
cout << "Input: String to be encoded " << endl;
cout << "Output: Encoded string " << endl << endl;
cout << "Empty string exits the program." <<endl;
cout << endl;
done = false;
while (!done)
{
cout << "Input: ";
getline(cin, iline);
if (iline == "") //If line is empty, set done to true
{
done = true;
}
else
{
key = iline[0]; // Extract the key character
oline = ""; // Initilalize the output line
for (pos = 1; // Append each coded character string
(pos < iline.length() &&
(iline[pos] != 0) &&
(iline[pos] <= UPPER_LIMIT));
pos++)
{
oline += code(key, iline[pos]); // Append the coded string for one character
}
oline += sum(oline); // Append the output string checksum
oline = key + oline; // Prepend the output with the key character
cout << "Output:" << oline << endl; // Display the output line
cout << endl; // Display a blank line
}
}
cout << endl;
cout << "Done." << endl;
return 0;
}
// CODE FUNCTION
// This function encodes one character.
// The return value is the string of encoded characters.
string code // Encode a character
(char key, // Key character
char in) // Input character
{
string out = ""; // Output string

// ***TO DO generate the encoded value of one character.***

return out; // Return the encoded characters
}

// SUM FUNCTION
// This function generates a checksum for a text string.
// The return value is a string of four decimal digits that is the checksum.
string sum // Generate a string checksum
(string in) // Input string
{
string out = ""; // Output string

// ***TO DO generate a checksum for a text string.***

return out; // Return the checksum string
}
Just... do what it says under the "TO DO" comments. So add to the CODE function the ability to generate the encoded value of one character, and add to the SUM function the ability to generate a checksum for a text string.
Topic archived. No new replies allowed.