Menu

[Solved]Need Help C Program S Functional 2 Dimension Array Program Read Data 2 Files Stnametxt Stg Q37019323

Names.txt John Smith Jane Doe Sam Smith Sean Glenn Andrew Clarks Carlos Lopez Mary Nguyen Amanda Garcia Joseph Smith Steve Jo

I need help with this c++program. It’s a functional 2 dimensionarray program that read data from 2 files (stname.txt andstgrade.txt), store, adds the grades of the student each row anddisplay in Result.txt. so far no error compiling but I have aproblem displaying the output

The result should display the Names.txt and total of the gradeas shown below: example

Result.txt

John Smith        412

so far this is the program I have written:

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

const int row = 10;

const int col = 7;

ifstream name;

ifstream grade;

ofstream out;

void readdata (string stname[row], int stgrade [row] [col]);

void displaydata (string stname [row], int stgrade [row] [col],int total[row]);

void sttotal (int stgrade [row] [col], int sttotal [row]);

int main()

{
int STG [row] [col] = { {0},{0} };

int STT [row] = {0};

string STN [row] = { };

readdata(STN, STG);
sttotal (STG, STT);
displaydata(STN, STG, STT);
system(“pause”);
name.close();

grade.close();

out.close();
}

///////////////////////////READFILES///////////////////////////////

void readdata (string stname [row], int stgrade [row][col])
{
name.open (“Stname.txt”);
grade.open (“Stgrade.txt”);
int r, c;
for (r = 0; r < row; r++)
{
getline(name, stname [row] );
for (c = 0; c < col; c++)
{
grade >> stgrade[r][c];
}
}
}

///////////////////////////ADDGRADES////////////////////////////////

void sttotal (int stgrade[row] [col], int total[row])

{
int r,c;
for (r = 0; r < row; r++)
{
for ( c = 0; c < col; c++)
total[r] = total[r] + stgrade [r][c];
}
}

////////////////////////DISPLAYRESULT//////////////////////////////////////////

void displaydata(string stname [row], int stgrade [row] [col],int total[row])
{
out.open (“Result.txt”);
int r, c;
for (r = 0; r < row; r++)
{
out << stname [r] << setw(5);
for (c = 0; c < col; c++)
out << setw (5) << stgrade [r] [c];
out << setw (7) << total[r] << endl;
}
}

Names.txt John Smith Jane Doe Sam Smith Sean Glenn Andrew Clarks Carlos Lopez Mary Nguyen Amanda Garcia Joseph Smith Steve Jobs Grades.txt 57 23 87 10 53 40 5 100 84 69 80 85 54 65 23 86 54 97 37 56 42 30 62 96 53 52 62 83 70 75 90 78 23 87 28 96 20 35 64 82 36 50 64 68 85 62 63 52 47 36 45 42 61 84 92 75 78 93 97 23 39 52 47 58 45 50 34 60 Show transcribed image text Names.txt John Smith Jane Doe Sam Smith Sean Glenn Andrew Clarks Carlos Lopez Mary Nguyen Amanda Garcia Joseph Smith Steve Jobs Grades.txt 57 23 87 10 53 40 5 100 84 69 80 85 54 65 23 86 54 97 37 56 42 30 62 96 53 52 62 83 70 75 90 78 23 87 28 96 20 35 64 82 36 50 64 68 85 62 63 52 47 36 45 42 61 84 92 75 78 93 97 23 39 52 47 58 45 50 34 60

Expert Answer


Answer to I need help with this c++program. It’s a functional 2 dimension array program that read data from 2 files (stname.txt … . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *