A c++ program, thanks in advance , Assume the following input data stored in fil
ID: 3736620 • Letter: A
Question
A c++ program, thanks in advance ,
Assume the following input data stored in file (c:\ CSC.dat) . Given that the rows represents the students and the columns represents five test Scores
Write a program to calculate students’ average test scores by using a two-dimensional array to store the test scores, your program must read data from input file and store data into the two dimensional array then calculate the average test score, and output the average of each row.
85 83 77 91 76 80 90 95 93 48 78 81 11 90 73 92 83 30 69 87 23 83 30 69 87Explanation / Answer
here is your program : ---------->>>>>>>>
#include<iostream>
#include<fstream>
using namespace std;
int readLine(string file){
ifstream ifs;
int count = 0;
ifs.open(file.c_str());
if(ifs.is_open()){
char c;
while(!ifs.eof()){
ifs.get(c);
if(c == ' '){
count++;
}
}
ifs.close();
return count-1;
}else{
cout<<" File Opening Error !!";
exit(-1);
}
}
void readFile(string file,int arr[][5],int row){
ifstream ifs;
ifs.open(file.c_str());
if(ifs.is_open()){
for(int i = 0;i<row;i++){
for(int j = 0;j<5;j++){
ifs>>arr[i][j];
}
}
ifs.close();
}else{
cout<<" File Opening Error !!";
exit(-1);
}
}
void calculateAvarageAndDisplay(int arr[][5],int row){
double avarage[row];
for(int i = 0;i<row;i++){
avarage[i] = 0.0;
}
for(int i = 0;i<row;i++){
for(int j = 0;j<5;j++){
avarage[i] = avarage[i] + arr[i][j];
}
}
cout<<" Printing Avarage Score of students : -------------- ";
for(int i = 0;i<row;i++){
cout<<" "<<(i+1)<<". ";
for(int j = 0;j<5;j++){
cout<<" "<<arr[i][j];
}
cout<<" Avarage Score = "<<(avarage[i]/5.0);
}
}
int main(){
//here you can change the file name as your need
string s = "CSC.dat";
int row = readLine(s);
int arr[row][5];
readFile(s,arr,row);
calculateAvarageAndDisplay(arr,row);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.