Home / Expert Answers / Computer Science / cis-251-c-programming-program-7-arrays-and-vectors-1-using-visual-studio-or-your-selecte-pa548

(Solved): CIS-251 C++ Programming Program #7 (Arrays and Vectors) 1) Using Visual Studio or your selecte ...



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>)

[rror List **************
Entire Solution
x 8 Errors ? 0 Warnings
Code Description
?E1696 cannot open source fille bits/stcc

It's not the file problem, I can't even get it to run. please help me fix above these errors.

[rror List ************** Entire Solution x 8 Errors ? 0 Warnings Code Description ?E1696 cannot open source fille "bits/stcch identifier "string" is undefined. identifier "ifstream" is undefined [0020 abc F0020 E0020 identifier "cout" is undefined 0020 identifier "endl" is undefined F0020 identifier "cout" is undefined abc F0020 identifier "endl" is undefined E0020 identifier "enidl" is undefined ? Int-uninit Local variable is not initialized. Frror list Output Type here to search 0 1 Message 97 Build+ IntelliSense 0 C n 92°F Sunny @ Project Chapter7 Chapter7 Chapter7 Chapter/ Chapter/ Chapter7 Chapter7 Chapter 7 Chapter 7 ***************** ? ? X x Search Frror list File Chapter7.cop Chapter7.cpp Chapter7.cpp Chapter/.cpp Chapter/.cpp Chapter7.cpp Chapter7.cpp Chapter 7.upp Chapter7.cpp ENG 3:29 PM 7/2/2022 Line 7 62 63 66 66 76 80 83 70 ?.


We have an Answer from Expert

View Expert Answer

Expert Answer


The above program is correct Put the Program7.txt file in the
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe