1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
// ------------------------------------------------------------------
// File name: intarray_a.cpp
// Assign ID: PROG11a
// Author: cop3014cjoe Dr. Jones
//
// Purpose: Use functions to perform the following sequence.
//
// 1. Load exactly 5 values into array ID using prompt "Next value: ".
// 2. Display the values in array ID, with label "Array ID: ".
// 3. Load array Num with values from keyboard terminated by sentinel 7777,
// using prompt "Enter next value (7777 to STOP): ".
// 4. Display the values in array Num, with label "Array Num: "..
// 5. Display the sum of values in Num as NUM SUM = xxxx
// 6. Display the average (2 decimal places) of values in Num as NUM AVG = xxxx.xx
// 7. Load array Score with the number of values specified by the user.
// using prompt "Value: ".
// 8. Display the values in array Score, with label "Score: ".
// 9. Display the average (2 decimal places) of values in Score
// as AVERAGE SCORE = xxxx.xx
//
// NOTE: All prompts begin with a new line.
// All output labels begin with a new line.
//-------------------------------------------------------------------
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
#include "intarrayfunctions.h"
int main()
{
// -----------------------------------------------------------
// Declare required constants, variables and arrays.
// ----
// NOTE: Have a separate size variable for each array.
// -----------------------------------------------------------
const int CAPACITY = 10; // Max capacity of ALL arrays.
int ID[CAPACITY], // ID array;
ID_size = 0; // Size of ID -- #values being used.
// -----------------------------------------------------------
// Declare calculation variables.
// -----------------------------------------------------------
float Avg; // Average of array values.
int Sum; // Sum of array values.
//-| -----------------------------------------------------------
//-| Print copyright notice.
//-| -----------------------------------------------------------
cout << endl << "(c)2012 cop3014cjoe Dr. Jones" << endl << endl;
//-| -----------------------------------------------------------
//-| 1. Load exactly 5 values into array ID using prompt "Next value: ".
//-| -----------------------------------------------------------
LoadArray(ID, 5, "Next value: ");
//-| -----------------------------------------------------------
//-| 2. Display the values in array ID, with label "Array ID: ".
//-| -----------------------------------------------------------
DisplayArray(ID, 5, "Array ID: ");
//-| -----------------------------------------------------------
//-| 3. Load array Num with values from keyboard terminated by
//-| sentinel 7777, using prompt "Enter next value (7777 to STOP): ".
//-| -----------------------------------------------------------
LoadArray(ID, 10, ID_size, 7777, "Enter next value (7777 to STOP): ");
//-| -----------------------------------------------------------
//-| 4. Display the values in array Num, with label "Array Num: "..
//-| -----------------------------------------------------------
DisplayArray(ID, ID_size, "Array Num: ");
//-| -----------------------------------------------------------
//-| 5. Display the sum of values in Num as NUM SUM = xxxx
//-| -----------------------------------------------------------
DisplayArray(ID, ArraySum(ID, ID_size), "NUM SUM = ");
//-| -----------------------------------------------------------
//-| 6. Display the average of values in Num as NUM AVG = xxxx.xx.
//-| -----------------------------------------------------------
DisplayArray(ID, ArrayAvg(ID, ID_size), "NUM AVG = ");
//-| -----------------------------------------------------------
//-| 7. Load array Score with the number of values specified by the
//-| user, using prompt "Value: "
//-| -----------------------------------------------------------
LoadArray(ID, 10, ID_size, "Value: ");
//-| -----------------------------------------------------------
//-| 8. Display the values in array Score, with label "Score: ".
//-| -----------------------------------------------------------
DisplayArray(ID, ID_size, "Score: ");
//-| -----------------------------------------------------------
//-| 9. Display the average of values in Score as SCORE AVG = xxxx.xx
//-| -----------------------------------------------------------
int AVG = ArrayAvg(Score, ID);
DisplayArray(ID, AVG, "Score AVG = ");
//-| -----------------------------------------------------------
//-| Print copyright notice.
//-| -----------------------------------------------------------
cout << endl << endl << "(c)2012 cop3014cjoe Dr. Jones" << endl;
return 0;
}//main
|