I need help with my functions I am comfortable with the rest of the codes just m
ID: 3620097 • Letter: I
Question
I need help with my functionsI am comfortable with the rest of the codes just my functions needs help
I need a program that will read from an infile to a multi dimensional array
and then get the average.
This is the infile:
Appleton 92 88 72
Baker 63 73 57
Closer 89 0 92
Demsey 90 89 100
Eker 84 92 72
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
int get_Info (ifstream&);
void Prt_Grade (int test[][3], char name[], int test_avg[]);
int Make_Up (int test[][]);
int main ()
{
int test[5][3], test_avg[5], MakeUp;
string name[5];
ifstream infile;
infile.open("TestInfo.txt")
get_Info (infile)
int i=0, j=0;
int sum=0, k=0;
for (i=0;i<5;i++)
{
for (j=0;j<3;j++)
{
sum+=test[i][j];
}
test_avg[k]=sum/5;
k++;
}
Prt_Grade( int test, name, test_avg);
cout<<"There are "<<Make_Up(test)<<"make-ups(s) to arrange."<<endl;
cout<<
system("pause");
return 0;
}
void get_Info (ifstream&, int test[][], string name[])
{
int i, j;
while(infile&&i<5)
{
infile>>name[5];
}
for (i=0;i<5;i++)
{
for (j=0;j<3;j++)
{
infile>>test[i][j];
}
}
}
void Prt_Grade (int test[][], string name[], int test_avg[])
{
int i, j;
cout<<"Name"<<setw(5)<<"Test1"<<setw(5)<<"Test2"<<setw(5)<<"Test3"<<setw(5)<<"Average"<<endl;
for (i=0; i<5; i++)
{
j=0;
cout<<name[i]<<setw(5)<<test[i][j]<<setw(5)<<test[i][j+1]<<setw(5)<<test[i][j+2]<<setw(5)<<test_avg[i]
}
}
int Make_Up (int test[5][3])
{
int i, j, counter;
for (i=0;i<5;i++)
{
for (j=0;j<3;j++)
{
if(test[i][j]==0)
counter++
}
}
Explanation / Answer
please rate - thanks there are changes throughout. is the 0 supposed to be included in the average? because it is #include <iostream>#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
void get_Info (ifstream&,int[][3],string[]);
void Prt_Grade (int test[][3], string name[], double test_avg[]);
int Make_Up (int test[][3]);
int main ()
{
int test[5][3], MakeUp;
double test_avg[5];
string name[5];
ifstream infile;
infile.open("TestInfo.txt");
get_Info (infile,test,name);
int i=0, j=0;
int sum=0;
for (i=0;i<5;i++)
{sum=0;
for (j=0;j<3;j++)
{
sum+=test[i][j];
}
test_avg[i]=sum/3.;
}
Prt_Grade( test,name, test_avg);
cout<<"There are "<<Make_Up(test)<<" make-ups(s) to arrange."<<endl;
system("pause");
return 0;
}
void get_Info (ifstream& infile, int test[][3], string name[])
{
int i=0, j;
while(infile&&i<5)
{
infile>>name[i];
for (j=0;j<3;j++)
{
infile>>test[i][j];
}
i++;
}
}
void Prt_Grade (int test[][3], string name[], double test_avg[])
{
int i, j;
cout<<setw(10)<<"Name"<<setw(8)<<"Test1"<<setw(8)<<"Test2"<<setw(8)<<"Test3"
<<setw(8)<<"Average"<<endl;
for (i=0; i<5; i++)
{
j=0;
cout<<setw(10)<<left<<name[i]<<setw(8)<<test[i][j]<<setw(8)<<test[i][j+1];
cout<<setw(8)<<test[i][j+2]<<setw(8)<<setprecision(2)<<fixed<<test_avg[i]<<endl;;
}
}
int Make_Up (int test[5][3])
{
int i, j, counter=0;
for (i=0;i<5;i++)
{
for (j=0;j<3;j++)
{
if(test[i][j]==0)
counter++;
}
}
return counter;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.