Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In c++, Part 1. Count the number of lines in a file. Write a function int CountLines(string filename) that takes in the filename as a

In c++,

Part 1. Count the number of lines in a file.

Write a function

int CountLines(string filename) 

that takes in the filename as a parameter and returns the number of lines in the file. Lines are separated the newline character .

Part 2. Parse a file and store the values in a variable.

For this task youll be given a file, containing a list of students and their scores in K subjects, where K is an arbitrary number. All of these values will be separated by commas. There will be one student record (Name + K scores) per line. The entire file will therefore be of this format

Name1, Score1, Score2, Score3 ... ScoreK Name2, Score1, Score2, Score3 ... ScoreK . .

. NameN, Score1, Score2, Score3 ... ScoreK

Your task will be to read the file, parse it into its individual components and populate two arrays with the names of each student and their average score respectively.

You will need to write the function-

int ReadScores(string filename, string names[], float avg_scores[], int array_size) 

Where filename is the name of the input file as specified above names[] is an initially empty array of student names avg_scores[] is an initially empty array of students average scores. array_size is the size of the arrays avg_score and names

Your function will return the number of lines read.

Task Details

Youll first need to initialize every element in the name array with the empty string . Similarly every element in the avg_score array will be initialized with -1.

You will need to read each line in the file and parse the line of data to obtain all the values. Place the name into the names array and process all the scores to calculate an average to be placed into the corresponding position of the avg_scores array.

Part 3. Writing back to a file.

Given an array of names and associated averages in the avg_score array (as read from file in part 2), sort the data into ascending order by name and write the sorted data to the given filename.

You will need to the write the function

void WriteGrades( string filename, string names[], float avg_scores[], int n_students) 

Where filename is the name of the file that you shall be writing to names[] i s the array containing student names. avg_scores[] is the array containing the average scores for each student. n_students is the number of students .

Task Details

For every name in the names array, compute the grade from the corresponding average score. Remember the average score for the student in names[i] is stored in avg_scores[i].

For each student write a single line into the file with format given below. The format describes a three fields separated by commas. The nomenclature means to place the name of the student in that location. Similarly, write the other two fields in place of the <..> in the format. (The < and > are not included in the output)

 Format: , ,  

Compute the grade using the following rubric:

For scores greater than and equal to 90 Grade is A

For scores greater than and equal to 80 and less than 90 Grades is B

For scores greater than and equal to 70 and less than 80 Grades is C

For scores greater than and equal to 60 and less than 70 Grades is D

For scores less than 60 Grades is F

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

Step: 3

blur-text-image

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

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions

Question

=+1 Is the decision fair to employees?

Answered: 1 week ago