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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;
// Global constants
const int ROWS = 26;
const int COLS = 26;
int row1;
int row2;
int col1it;
int col2it;
float data[ROWS][COLS];
//---------------------------------------------------
// Print command menu to user and get input
//---------------------------------------------------
int get_menu_choice()
{
// Print command menu
cout << "Welcome to MiniCalc\n"
<< " 1) Store specified data value\n"
<< " 2) Store random data values\n"
<< " 3) Calculate minimum of data values\n"
<< " 4) Calculate maximum of data values\n"
<< " 5) Calculate sum of data values\n"
<< " 6) Calculate product of data values\n"
<< " 7) Calculate average of data values\n"
<< " 8) Calculate standard deviation of data values\n"
<< " 9) Print data values\n"
<< " 0) Quit the program\n"
<< "Enter command: ";
// Get user input
int command;
cin >> command;
if (command >= 0 && command <= 9)
return command;
else
return get_menu_choice();
}
void specdata() {
float data[ROWS][COLS];
float input;
for (int i = row1; i <= row2; i++)
{
for (int j = col1it; j <= col2it; j++)
{
cout << "What would you like to store in " << (char)(j + 65) << ":" << i << endl;
cin >> input;
data[i][j] = input;
}
}
}
void checkrange(int& row1, int& row2, int& col1it, int& col2it) {
row1 = 0;
row2 = 0;
char col1 = 64;
char col2 = 64;
while (row1 > 26 || row1 < 1) {
cout << "Input the First Row" << endl;
cin >> row1;
}
while (col1 > 90 || col1 < 65) {
cout << "Input the First Column" << endl;
cin >> col1;
}
while (row2 > 26 || row2 < 1) {
cout << "Input the Second Row" << endl;
cin >> row2;
}
while (col2 > 90 || col2 < 65) {
cout << "Input the Second Column" << endl;
cin >> col2;
}
col1it = col1 - 65;
col2it = col2 -65;
}
//---------------------------------------------------
// Main program
//---------------------------------------------------
int main()
{
// Declare spreadsheet
// Loop processing menu commands
int command = get_menu_choice();
while (command != 0)
{
if (command == 1) {
checkrange(row1, row2, col1it, col2it);
specdata();
}
else if (command == 2) {
checkrange(row1, row2, col1it, col2it);
}
else if (command == 3) {
checkrange(row1, row2, col1it, col2it);
}
else if (command == 4) {
checkrange(row1, row2, col1it, col2it);
}
else if (command == 5) {
checkrange(row1, row2, col1it, col2it);
}
else if (command == 6) {
checkrange(row1, row2, col1it, col2it);
}
else if (command == 7){
checkrange(row1, row2, col1it, col2it);
}
else if (command == 8) {
checkrange(row1, row2, col1it, col2it);
}
else if (command == 9) {
checkrange(row1, row2, col1it, col2it);
}
command = get_menu_choice();
}
return 0;
}
|