CIS-251 “C++ Programming” Program #7 (Arrays and Vectors)
1) Using Visual Studio or your selected IDE, create a C++ program solution for Chapter #7 Programming Challenges #21 “2D Array Operations” on page 461 of the textbook.
2) You must use good programming style as shown in the examples in the textbook to include ample comments in your source code. You must include helpful information in a header block such as the program description, the source of your program, your name, and the date.
3) Your program must use a 2-dimensional array of integers of 2 rows and 5 columns. The first row must have the values 5, 10, 8, 7, and 3. The second row must have the values 4, 9, 6, 2, and 1.
4) You must input your data for the array from a file (e.g. “Program7.txt”). Note that you don’t need to specify a pathname to your file if you put it in the same directory as your .cpp file.
5) You must create and use all 6 of the C++ functions specified in the textbook for this program. You must pass the arguments specified to your functions.
6) The getTotal, getRowTotal, getHighestInRow, and getLowestInRow functions must be called for each of the 2 rows individually. The getColumnTotal function must be called for each of the 5 columns individually.
7) You must determine and display the correct results for all required calculations using the specified array values in Step #3. All functions except getAverage should return integer results. The getAverage function should return a floating point result.
8) You must have only a single execution of your program. Do not rerun your program to test each function.
I have no clue how to do it. help needed, please and thank you !
Number Six is very important part, I don't know how to code that. although , I have a code, and can't make it run right.
I use visual studio 2022.
#include <bits/stdc++.h> using namespace std; int getTotal(int arr[][5], int row, int col) { int total = 0; for(int i = 0 ; i < row ; i++) for(int j = 0 ; j < col ; j++) total += arr[i][j]; return total; } int getRowTotal(int arr[][5], int row, int col) { int total = 0; for(int j = 0 ; j < col ; j++) total += arr[row][j]; return total; } int getHighestInRow(int arr[][5], int row, int col) { int highest = arr[row][0]; for(int j = 1 ; j < col ; j++) if(highest < arr[row][j]) highest = arr[row][j]; return highest; } int getLowestInRow(int arr[][5], int row, int col) { int lowest = arr[row][0]; for(int j = 1 ; j < col ; j++) if(lowest > arr[row][j]) lowest = arr[row][j]; return lowest; } int getColumnTotal(int arr[][5], int row, int col) { int total = 0; for(int i = 0 ; i < row ; i++) total += arr[i][col]; return total; } float getAverage(int arr[][5], int row, int col) { int total = getTotal(arr, row,col); int numberOfElements = row*col; float avg = (float)total/numberOfElements; return avg; } int main() { string filename("Program7.txt"); ifstream fin(filename); if (!fin.is_open()) { cout << "Error opening the file " << endl; return 0; } int row = 2, col = 5; int arr[2][5]; for (int i = 0; i < 2; i++) for (int j = 0; j < 5; j++) fin >> arr [i][j]; cout<<"Array:\n"; for(int i = 0 ; i < row ; i++) { for(int j = 0 ; j < col ; j++) cout<<arr[i][j]<<"\t"; cout<<endl; } cout<<"\nTotal: " << getTotal(arr, row, col) <<endl; for(int i = 0 ; i < row ; i++) cout<<"\nRow " << (i+1) << " Total : " << getRowTotal(arr, i, col); cout<<endl; for(int i = 0 ; i < row ; i++) cout<<"\nHighest in Row " << (i+1) << " : " << getHighestInRow(arr, i, col); cout<<endl; for(int i = 0 ; i < row ; i++) cout<<"\nLowest in Row " << (i+1) << " : " << getLowestInRow(arr, i, col); cout<<endl; for(int i = 0 ; i < col ; i++) cout<<"\nColumn " << (i+1) << " Total : " << getColumnTotal(arr, row, i); cout<<endl; cout<<"\nAverage: " << getAverage(arr, row, col) <<endl; return 0; }
It doesn't output anything, too many errors.
I either need help with fixing this code or a new code.
it keep saying those errors
Tell me how to fix those issues. ALSO, it won't let me open this kind of file (#include <bits/stdc++.h>)
It's not the file problem, I can't even get it to run. please help me fix above these errors.