Write a complete program in C to get data from file name DAT
Write a complete program in C to get data from file name DATA.TXT one line at a time until there is no more data in that file. The following is one sample line in DATA.TXT ( have as many record as you wish in DATA.TXT) Name SSN quiz mid assignments participation final LISA 111-11-1111 100 100 100 100 100 Jack 222-22-2222 80 80 100 90 100 Note that the first line is no in DATA.txt. Your program should create a file name RESULT.txt that reports Name, SSN and a letter grade according to the following rules: Total= %15 quiz + %15 mid +%40assignments + %10 Participation+ %final If total >= 90 then A else if total>=80 then B…. You can print same output to screen as well as RESULT.txt. Thank you!
Solution
#include<iostream>
#include<string>
#include <fstream>
using namespace std;
main() {
string name;
string ssn;
int quiz,mid,assn,part,final;
float total;
char grade;
char filename[100]=\"data.txt\";
ofstream outfile;
outfile.open(\"result.txt\");
outfile <<\"Name\\t\\t\"<< \"SSN\\t\\t\"<< \"Grade\ \";
if (std::ifstream(filename))
{
ifstream infile(filename);
std::getline(infile, name);
while(infile >> name >> ssn >> quiz >> assn >> part >>final)
{
total= .15*quiz + .15*mid + .4*assn+.1*part+ final;
cout << final;
if(total>=90) grade=\'A\';
else if(grade >=80 && grade <90) grade =\'B\';
outfile <<name<<\" \\t\\t\"<<ssn<<\" \\t\\t\"<<grade<<\"\ \";
infile>>name;
}
}
}//MAIN
