1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Genrish500 [490]
2 years ago
10

Write a program that reads the student information from a tab separated values (tsv) file. The program then creates a text file

that records the course grades of the students. Each row of the tsv file contains the Last Name, First Name, Midterm1 score, Midterm2 score, and the Final score of a student. A sample of the student information is provided in StudentInfo.tsv. Assume the number of students is at least 1 and at most 20.
The program performs the following tasks:
Read the file name of the tsv file from the user.
Open the tsv file and read the student information.
Compute the average exam score of each student.
Assign a letter grade to each student based on the average exam score in the following scale:
A: 90= B: 80=< X < 90
C: 70=< X < 80
D: 60=< X < 70
E: X < 60
Compute the average of each exam.
• Output the last names, first names, exam scores, and letter grades of the students into a text file named report.txt.
• Output one student per row and separate the values with a tab character.
• Output the average of each exam, with two digits after the decimal point at the end of report.txt. Hint: Use the setprecision manipulator to format the output.
Ex: If the input of the program is:
StudentInfo.tsv
and the contents of Studentinfo tsv are:
Barrett Edan 70 45 59
Bradshaw Reagan 96 97 88
Charlton Caius 73 94 80
Mayo Tyrese 88 61 36
Stern Brenda 90 86 45
the file report.txt should contain:
Barrett Edan 70 45 59 F
Bradshaw Reagan 96 97 88 A
Charlton Caius 73 94 80 B
Mayo Tyrese 88 61 36 D
Stern Brenda 90 86 45 C
Averages: midtermi 83.40, midterm2 76.60, final 61.60
Computers and Technology
1 answer:
kvasek [131]2 years ago
3 0
#include
#include
#include
#include
#include
#include


using namespace std;

// Class student required to store the data
class Student{
public:
string lname;
string fname;
int marks[3];
char grade;

// Function which generates the grade for student
void calculate_grade(){
double sum = 0;
for(int i=0;i<3;i++){
sum+= marks[i];
}
double average = sum/3;
if(average>=90 && average<100)
this->grade = 'A';
else if(average>=80)
this->grade = 'B';
else if(average>=70)
this->grade = 'C';
else if(average>=60)
this->grade= 'D';
else this->grade = 'F';
}
};

// This function reads the file , and creates a vector of Students data
vector read_file(string fileName){

// Opening the file
fstream fin;
fin.open(fileName);


// Temp variables
vector list;
vector row ;
string line, word, temp;

// Read the data into vector
while(getline(fin,line)){
row.clear();
stringstream s(line);

while(getline(s,word,'\t')){

row.push_back(word);

}
Student st;
st.fname = row[0];
st.lname = row[1];
st.marks[0] = stoi(row[2]);
st.marks[1] = stoi(row[3]);
st.marks[2] = stoi(row[4]);
st.calculate_grade();
list.push_back(st);
}
fin.close();
return list;
}

// This function takes filname to be output as input, and list of student
void writeFile(string filename, vector list){

// Opening the new file
ofstream fin(filename);
for(int i=0;i string line = list[i].fname+"\t"+list[i].lname+"\t"+to_string(list[i].marks[0])+"\t"
+to_string(list[i].marks[1])+"\t"+to_string(list[i].marks[2])+"\t"+list[i].grade+"\n";
fin<
}


// Find the stats required
double average1 =0,average2 =0 ,average3 = 0;
for(int i=0;i average1+=list[i].marks[0];
average2+=list[i].marks[1];
average3+=list[i].marks[2];
}
average1/=list.size();
average2/=list.size();
average3/=list.size();

// Writting the stats
fin<<"\n"<<"Average: "<<"mid_term1 "<
// Closing the file
fin.close();
}
int main(){

// Taking the input
cout<<"Enter the filename: ";
string filename;
cin>>filename;
vector list;

// Reading and Writting to the file
list = read_file(filename);
writeFile("report.txt",list);


}
You might be interested in
Which of the following is true for an API?
navik [9.2K]

Answer:

c

Explanation:

4 0
3 years ago
An audit trail is a record of how a transaction was handled from input through processing and output
Nostrana [21]

The answer is : True.  An audit trail is a record of how a transaction was handled from input through processing and output.  An audit trail is the evidence, such as purchase orders and invoices, that a financial transaction actually occurred.

6 0
3 years ago
¿Cuales son las empresas mas exitosas que aún usan hoja de cálculo? porfa es urgentee
dem82 [27]

Answer:excel

Explanation:

6 0
2 years ago
What are some things that games were historically used for?
madreJ [45]

Answer:

D) All of the above

Explanation:

All of these options are true.

Hope it helps and is correct!

5 0
2 years ago
Write six causes of data lost
just olya [345]
<span>1. Deleting files accidentally
</span>

2. Viruses and damaging malware

3. Mechanical damages of hard drive

4. Power failures

5. Theft of computer

6. Spilling coffee, and other water damages

7. Fire accidents and explosions

<span>Hope this helps.</span>
3 0
3 years ago
Other questions:
  • Do transformers have life insurance or car insurance? If you chose life insurance, are they even alive?
    7·1 answer
  • An example of an email client is:<br> A.)Yahoo<br> B.)Gmail<br> C.)Outlook<br> D.)All of the Above
    9·1 answer
  • Designing, producing, exhibiting, performing, writing, and publishing multimedia content including visual and performing arts an
    6·1 answer
  • In this exercise, you are given a word or phrase and you need to return that word or phrase with the word ‘like’ in front of it.
    5·1 answer
  • In order to plan George’s birthday, his father gave him a list of people who attended his birthday for the last five years. What
    8·1 answer
  • Which of these is the largest?<br> terabyte<br> exabyte<br> gigabyte<br> kilobyte<br> PLEASE HELP
    5·1 answer
  • How can netiquette help you communicate when texting or instant messaging?
    6·1 answer
  • Write a Java program that generates a new string by concatenating the reversed substrings of even indexes and odd indexes separa
    5·1 answer
  • For this activity, you will practice being both proactive and reactive to bugs. Both are necessary to get rid of errors in code.
    5·1 answer
  • Can anyone figure this out???? I need help ASAP!
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!