Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ coding FILES that should have output at txt file supposedly it read input.txt file The coding have no error however the output is not

C++ coding FILES

that should have output at txt file

supposedly it read input.txt file

The coding have no error however the output is not shown at the output.txt file, it should show these output:

out <<"Number of students: "<< i <

outfile << "Grade : " << grade[i] <

outfile << "The highest Marks is " << highest << endl;

the coding is also in the gDrive with input.txt and output.txt LINK IN THE COMMENTS

THE CODING:

#include

#include

using namespace std;

struct studentInfo

{

string name;

int age;

string course;

int testMark[2];

};

void grading (studentInfo [], double [] , char [], int);

void output(studentInfo [], ofstream &, char [] , int );

void highestMarks(studentInfo [] , ofstream &, double[], int );

int main (){

studentInfo student[3];

double average [3];

char gradeTest[3];

ifstream in; // input file

in.open("input.txt");

ofstream out;

out.open("output.txt");

int i=0;

while(!in.eof())

{

getline(in,student[i].name ,';'); // masukkan input kt file

in>> student[i].age;

in.ignore();

getline(in,student[i].course);

for(int j=0;j<2;i++)

{

in >> student[i].testMark[j];

}

i++;

}

grading (student,average, gradeTest , 3);

output( student, out, gradeTest,3);

highestMarks(student , out , average , 3);

out <<"Number of students: "<< i <

in.close();

out.close() ; // tutup outfile punya file

}

void grading (studentInfo stud[], double avg[] , char grade [], int size)

{

int sum=0;

for(int i=0; i

{

for(int j=0;j<2;j++)

{

sum+=stud[i].testMark[j];

}

avg[i]= sum/2;

if(avg[i] >=80)

grade[i]='A';

else if (avg[i] >=70)

grade[i] = 'B';

else if (avg[i] >=50)

grade[i] = 'C';

else

grade[i] = 'D';

}

}

void output(studentInfo stud[], ofstream &outfile, char grade[], int size)

{

for (int i=0;i

{

outfile<< stud[i].name <

outfile<< stud[i].age<

outfile<< stud[i].course <

for (int j =0;j<2 ;j++)

{

outfile << stud[i].testMark[j]<

}

outfile << "Grade : " << grade[i] <

}

}

void highestMarks(studentInfo stud[] , ofstream &outfile, double avg [], int size)

{

int highest = avg[0];

for (int i=0;i

{

if( highest < avg [i]);

highest = avg[i];

}

outfile << "The highest Marks is " << highest << endl;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

The planning process

Answered: 1 week ago

Question

1 complete the C++ instructions column in the figure \f

Answered: 1 week ago