Help with Homework Please Please use Microsoft Visual Studio
.Help with Homework Please
Please use Microsoft Visual Studios using the win32 console application and c++ file.
-Use a loop to read in data line by line from the file.
-Calculate and display the average with 2 decimal places.
-Added another famous computer Scientist to input file.
-Count and display number of students.
-Write the same results to a file.
-Output looks like assignment. Spaced correctly
-Extra credit. Famous CS people info.
ouac c Review the Chapter 5 Using Files slides on Canvas and Section 5.12 in your textbook. Download the text file called scores.txt. Save it inside your Project folder. It contains the following data on famous computer scientists their name and 5 exam scores. Grace Hopper 81.5 90.0 65.5 79.9 93.2 Alan Kay 75.5 81.5 70 90 98.2 John Backus 99.0 74 100 87.7 99.9 Sergey Brin 62 100 88.5 79.7 97.3 Brian K Create a new program called FamousCS.cpp. (Our Files Activities will be helpful). The basic structure is: include statements - there will be several using namespace std; int main) //declare variables needed //define file stream object //open the file scores.txt if (successfully opened file) // using a while loop read in and display the data // close the data file else cout \"Error opening file.\" endl ; /lend of else return 0Solution
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <iomanip> // for rounding decimal points to 2 places
using namespace std;
int main()
{
//fstream infile for opening scores.txt in read mode
fstream infile(\"scores.txt\",ios::in);
if(!infile){cerr<<\"file could not be found!\";exit(1);}
//fstream outfile for opening csexamreport in write //mode
fstream outfile(\"csexamreport.txt\",ios::out);
if(!outfile){cerr<<\"file could not be created!\";exit(1);}
char fname[20];
char lname[20];
int grades;
char c;
int lines=1;//for storing no: of lines on each file
double avg=0;//for storing average
//change below array with claim to fame of each //scientist in order
char fame[]={\'amd\',\'ati\',\'apple\',\'sony\',\'windows\',\'kali\',\'ubuntu\'};
while(infile.get(c))
{if(c==\'\ \') lines++;} //this loop is to find max number of lines in score.txt
infile.seekg(0); //to replace the file buffer back to initial //position
for(int k=0;k<lines;k++)
{
infile>>fname; //reading in first name
infile>>lname; //reading in last name
outfile<<fname<<\" \"<<lname<<\" \"<<\"has an exam average of\"<<\" \";
int sum=0;
for(int i=0;i<4;i++) // this loop for calculating sum of //marks
{
if(infile>>grades)
{sum+=grades;
outfile<<grades<<\" \";}
}
avg=sum/5;
outfile<<setprecision(2) << fixed <<avg<<endl; //to //round the avg value decimal point to 2 places
}
outfile<<\"Lawrence Page has an exam average of 88.8\"<<endl;// my favourite scientist
lines=lines+1;
outfile<<\"There were\";
outfile<<\" \"<<lines<<\" \"<<\"student records in this file.\"<<endl; // printing total number of records
outfile.close();
infile.close();
//this is for getting the content from csexamreport and //writing to scores file
fstream infile(\"csexamreport.txt\",ios::in);
if(!infile){cerr<<\"file could not be found!\";exit(1);}
fstream outfile(\"scores.txt\",ios::out);
if(!outfile){cerr<<\"file could not be created!\";exit(1);}
while(infile.eof()==0)
{ infile>>fname;
outfile<<fname;
}
//at the end od scores file below text is included
outfile<<endl<<\"All the files are closed and report is written...Goodbye..\";
infile.close();
outfile.close();
//output on screen
fstream infile(\"csexamreport.txt\",ios::in);
if(!infile){cerr<<\"file could not be found!\";exit(1);}
while(infile.eof()==0)
{ infile>>fname;
cout<<fname;
}
infile.close();
// output on the screen second part with claim to fame near //every scientist
//for entering correct claim to fame check the fame array //declaration
fstream infile(\"csexamreport.txt\",ios::in);
if(!infile){cerr<<\"file could not be found!\";exit(1);}
while(infile.get(c))
{if(c==\'\ \') lines++;}
infile.seekg(0);
for(int k=0;k<lines-1;k++)
{
infile>>fname;
infile>>lname;
cout<<fname<<\" \"<<lname<<\":\"<<\" \";
for(int i=0;i<5;i++)
{
infile>>grades;
}
cout<<fame[k]<<endl;
}
cout<<\"All the files are closed and report is written...Goodbye\"<<endl;
infile.close();
return 0;
}


