Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include "pch.h"
- //array declarations
- const int NUM_ROWS = 3;
- const int NUM_COLS = 4;
- using namespace std;
- //Gets total for rows and colms to calculate sum
- int getTotal(int testArray[NUM_ROWS][NUM_COLS], int r, int c) {
- int total = 0;
- for (int i = 0; i < r; ++i) {
- for (int j = 0; j < c; ++j) {
- total = total + testArray[i][j];
- }
- }
- return total;
- }
- //takes getTotal's data to create an average sum
- double getAverage(int testArray[NUM_ROWS][NUM_COLS], int r, int c) {
- double avg;
- int total = getTotal(testArray, NUM_ROWS, NUM_COLS);
- avg = total / (1.0*NUM_ROWS*NUM_COLS);
- return avg;
- }
- //retrives the tow total
- int getRowTotal(int testArray[NUM_ROWS][NUM_COLS], int r, int c) {
- int total = 0;
- for (int j = 0; j < c; ++j) {
- total = total + testArray[r][j];
- }
- return total;
- }
- //Retrives the column total
- int getColumnTotal(int testArray[NUM_ROWS][NUM_COLS], int c, int r) {
- int total = 0;
- for (int j = 0; j < r; ++j) {
- total = total + testArray[j][c];
- }
- return total;
- }
- // to find the highest in the row
- int getHighestInRow(int testArray[NUM_ROWS][NUM_COLS], int r, int c) {
- int max = -100000;
- for (int j = 0; j < c; ++j) {
- if (testArray[r][j] > max)
- max = testArray[r][j];
- }
- return max;
- return 0;
- }
- // to find the lowest in the row
- int getLowestInRow(int testArray[NUM_ROWS][NUM_COLS], int r, int c) {
- int min = 100000;
- for (int j = 0; j < c; ++j) {
- if (testArray[r][j] < min)
- min = testArray[r][j];
- }
- return min;
- }
- int main(void)
- {
- // Array with test data type int
- // Random numbers I picked, should figure out how to randomize them later
- int testArray[NUM_ROWS][NUM_COLS] =
- { { 10, 17, 0, 1 },
- { 43, 60, 76, 3 },
- { 38, 4, 100, 2 }
- };
- // Display the total of the array elements.
- cout << "The total of the array elements is "
- << getTotal(testArray, NUM_ROWS, NUM_COLS)
- << endl;
- // Display the average of the array elements.
- cout << "The average value of an element is "
- << getAverage(testArray, NUM_ROWS, NUM_COLS)
- << endl;
- // Display the total of row 0.
- cout << "The total of row 0 is "
- << getRowTotal(testArray, 0, NUM_COLS)
- << endl;
- // Display the total of column 2.
- cout << "The total of col 2 is "
- << getColumnTotal(testArray, 2, NUM_ROWS)
- << endl;
- // Display the highest value in row 2.
- cout << "The highest value in row 2 is "
- << getHighestInRow(testArray, 2, NUM_COLS)
- << endl;
- // Display the lowest value in row 2.
- cout << "The lowest value in row 2 is "
- << getLowestInRow(testArray, 2, NUM_COLS)
- << endl;
- //int random(int a, int b)
- return 0;
- }
- // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement