// // Program: volume // Author: B. Massingill // // Purpose: test "volume" function. // // Input: program prompts for one set of inputs to volume function. // Output: program prints results of calling volume function with // some fixed sets of input, plus user-supplied input. // #include // has input/output functions #include // has EXIT_SUCCESS // ---- Function prototypes (should precede main program). // Compute volume of a box. // Pre: h, w, d all positive. // Post: return value is volume of box with dimensions h, w, d. int volume(int h, int w, int d); // Test volume function. // Pre: h, w, d all positive. // Post: volume(h, w, d) printed to standard output, with // explanatory text. void try_volume(int h, int w, int d); // Get a positive integer from standard input (prompt user). // Pre: none. // Post: user has been prompted to enter positive integer, return // value is what was entered. // (This is a rather silly function, included mostly as an example // of a function with a return value but no input parameters. int get_positive(void); // Print some text before prompting for box dimensions. // Pre: none. // Post: text printed to standard output. // (This is a rather silly function, included mostly as an example // of a function with no input parameters and no return value.) void print_prompt(void); // ---- Main program. int main(void) { try_volume(1,1,1); try_volume(2,3,4); int height, width, depth; print_prompt(); height = get_positive(); width = get_positive(); depth = get_positive(); try_volume(height, width, depth); return EXIT_SUCCESS; } // ---- Function definitions (should follow main program). // For function documentation (descriptions, preconditions // and postconditions), refer to corresponding function // prototypes above. int volume(int h, int w, int d) { return h*w*d; } void try_volume(int h, int w, int d) { cout << "Box dimensions: " << h << " by " << w << " by " << d << endl; cout << "Box volume: " << volume(h, w, d) << endl; return; } int get_positive(void) { int temp; cout << "Enter a positive integer: "; cin >> temp; return temp; } void print_prompt(void) { cout << "You will now be prompted for box dimensions.\n"; return; }