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]
3 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]3 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
Electronic type is often considered to be the latest step in the evolution of the written ______________.
Allisa [31]
It isn’t people but im really confused. I think its A but dont come at me if its wrong
4 0
3 years ago
The methods of the Character class that begin with ____ return a character that has been converted to the stated format.
Pavel [41]

Answer:

most probably the answer is 'to'

6 0
3 years ago
Ten(10) examples of wearables or wearable technologies?​
Semmy [17]

Answer:read

Explanation:

airpods

headphones

earbuds

AirPods  pro

watch

fitbit (type of watch that counts your miles) &you can say workout watch&

VR set

technology bracelet

smart glasses

Smart ring

7 0
3 years ago
8.9 Lesson Practice edhesive
lapo4ka [179]
Is what it is so it can’t be what it isn’t
6 0
3 years ago
Read 2 more answers
The most common type of database is a __________ database. question content area bottom part 1 a. relational b. normalized c. sa
sashaice [31]

The most common type of database is a <u>relational  </u>database.

<h3>What is relational database?</h3>

A relational database is seen as a set up of information that is known to be put together data in a way that is predefined in its relationships and it is one where data is saved in one or more tables.

Note that it is one that do makes it easy to see and know how different data structures links to each other. Hence, The most common type of database is a <u>relational  </u>database.

Learn more about database from

brainly.com/question/518894

#SPJ1

7 0
2 years ago
Other questions:
  • The set of specific, sequential steps that describe exactly what a computer program must do to complete the work is called a(n)
    10·2 answers
  • For Adults/Adolescents, you should call/activate EMS: Before providing CPR. After providing CPR for 2 minutes. After an AED has
    13·1 answer
  • Memory chips are used in ____ storage devices to read and write data
    9·1 answer
  • Below is a sequence of 32-bit memory address references observed during the execution of an application, and given as word addre
    7·1 answer
  • A jeweler designing a pin has decided to use five stones chosen from diamonds, rubies, and emeralds. In how many ways can the st
    9·1 answer
  • How can using Prezi software for a presentation allow the presenter to better respond to audience needs?
    10·1 answer
  • Who first demonstrated the computer mouse ?
    11·1 answer
  • 2. Define a function squareArea that computes the area of a square given side length
    14·1 answer
  • Please help please help
    10·1 answer
  • How many pixels are in a picture that is 640 pixels wide and 480 pixels high?.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!