Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1.  
  2.  
  3. #include <iostream>
  4. #include <time.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include "pch.h"
  8. //array declarations
  9. const int NUM_ROWS = 3;
  10. const int NUM_COLS = 4;
  11. using namespace std;
  12. //Gets total for rows and colms to calculate sum
  13. int getTotal(int testArray[NUM_ROWS][NUM_COLS], int r, int c) {
  14. int total = 0;
  15. for (int i = 0; i < r; ++i) {
  16. for (int j = 0; j < c; ++j) {
  17. total = total + testArray[i][j];
  18. }
  19. }
  20. return total;
  21. }
  22. //takes getTotal's data to create an average sum
  23. double getAverage(int testArray[NUM_ROWS][NUM_COLS], int r, int c) {
  24. double avg;
  25. int total = getTotal(testArray, NUM_ROWS, NUM_COLS);
  26. avg = total / (1.0*NUM_ROWS*NUM_COLS);
  27. return avg;
  28. }
  29. //retrives the tow total
  30. int getRowTotal(int testArray[NUM_ROWS][NUM_COLS], int r, int c) {
  31. int total = 0;
  32. for (int j = 0; j < c; ++j) {
  33. total = total + testArray[r][j];
  34. }
  35. return total;
  36. }
  37. //Retrives the column total
  38. int getColumnTotal(int testArray[NUM_ROWS][NUM_COLS], int c, int r) {
  39. int total = 0;
  40. for (int j = 0; j < r; ++j) {
  41. total = total + testArray[j][c];
  42. }
  43. return total;
  44. }
  45. // to find the highest in the row
  46. int getHighestInRow(int testArray[NUM_ROWS][NUM_COLS], int r, int c) {
  47. int max = -100000;
  48. for (int j = 0; j < c; ++j) {
  49. if (testArray[r][j] > max)
  50. max = testArray[r][j];
  51. }
  52. return max;
  53. return 0;
  54. }
  55. // to find the lowest in the row
  56. int getLowestInRow(int testArray[NUM_ROWS][NUM_COLS], int r, int c) {
  57. int min = 100000;
  58. for (int j = 0; j < c; ++j) {
  59. if (testArray[r][j] < min)
  60. min = testArray[r][j];
  61. }
  62. return min;
  63. }
  64. int main(void)
  65. {
  66.  
  67. // Array with test data type int
  68. // Random numbers I picked, should figure out how to randomize them later
  69.  
  70. int testArray[NUM_ROWS][NUM_COLS] =
  71. { { 10, 17, 0, 1 },
  72. { 43, 60, 76, 3 },
  73. { 38, 4, 100, 2 }
  74. };
  75.  
  76. // Display the total of the array elements.
  77. cout << "The total of the array elements is "
  78. << getTotal(testArray, NUM_ROWS, NUM_COLS)
  79. << endl;
  80. // Display the average of the array elements.
  81. cout << "The average value of an element is "
  82. << getAverage(testArray, NUM_ROWS, NUM_COLS)
  83. << endl;
  84. // Display the total of row 0.
  85. cout << "The total of row 0 is "
  86. << getRowTotal(testArray, 0, NUM_COLS)
  87. << endl;
  88. // Display the total of column 2.
  89. cout << "The total of col 2 is "
  90. << getColumnTotal(testArray, 2, NUM_ROWS)
  91. << endl;
  92. // Display the highest value in row 2.
  93. cout << "The highest value in row 2 is "
  94. << getHighestInRow(testArray, 2, NUM_COLS)
  95. << endl;
  96. // Display the lowest value in row 2.
  97. cout << "The lowest value in row 2 is "
  98. << getLowestInRow(testArray, 2, NUM_COLS)
  99. << endl;
  100. //int random(int a, int b)
  101.  
  102. return 0;
  103.  
  104.  
  105. }
  106.  
  107.  
  108.  
  109. // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement