Your assignment is to produce a header file and implementation file for a bunch of useful functions, and write a sample program that utilizes the functions. The header file (named something like “useful.h”) will be mostly comments. It will contain a prototype for each function, along with the function’s description, preconditions, postconditions, and list of libraries and namespace pieces that it needs.
Here’s an example of a header file – it only includes GetInteger.
// Filename: useful.h
//
// int GetInteger(char* prompt, int min = INT_MIN, int max = //INT_MAX)
// Libraries Used: iostream, cassert, climits
// Using: std::cin, std::cout, std::endl,
// Accepts the following parameters: prompt (a string that asks the user
// for input), min (the minimum acceptable return value, and max (the
// maximum acceptable return value).
// Preconditions: min < max
// Postconditions: Returns an integer between min and max, inclusively,
// as entered by the user.
//
//(other function descriptions here)
#ifndef USEFUL_H
#define USEFUL_H
#include <climits>
namespace aer //you must define your own namespace
{
int GetInteger(const char* prompt, int min = INT_MIN, int max = INT_MAX);
//(other function prototypes here)
}
#endif
The implementation file should just have the function definitions. Example:
// Filename: useful.cpp
// Function definitions
#include <iostream>
#include <cassert>
#include <climits>
using std::cin;
using std::cout;
using std::endl;
#include "useful.h"
namespace aer{
int GetInteger(const char* prompt, int min, int max)
{
//you have this code
}
//more function definitions go here
}//end namespace
You must write pre- and post-conditions for all the functions. Full error-checking is necessary (use assert for non-input functions).
Your sample program should use all the functions – see how many functions you can use at once. (That is, don’t have an enormous menu asking which function you want to test – combine tasks.)
A design document is not required for this assignment; the comments in the header file will serve this purpose. Don’t forget to turn in all your code as well as your executable and sample output.