Question

Lets consider a file with the following student information: John Smith 99.0 Sarah Johnson 85.0 Jim Robinson 70.0 Mary Ander

programming language is C++. Please also provide an explanation of how to create a file with the given information and how to use that file in the program
0 0
Add a comment Improve this question Transcribed image text
Answer #1

output(console)

Activities y Visual Studio Code Tue Mar 24, 01:21 test_scores.cpp - HomeworkLib - Visual Studio Code 99% - ox File Edit Selection V

output.txtActivities Visual Studio Code Tue Mar 24, 01:22 i ( + 99% - ox output.txt - HomeworkLib - Visual Studio Code File Edit Selection Vi

input file(scores.txt)

Activities y Visual Studio Code Tue Mar 24, 01:22 99% scores.txt - HomeworkLib - Visual Studio Code File Edit Selection View Go Run

CODE:

 #include<iostream> #include<fstream> #include<string> using namespace std; //calculates and displays average socre of students void avergae_score(string filename) { //sum initialized to 0 float score,sum=0.0; //n will be to track number of students int n=0; string firstname,lastname; //create an ifstream object ifstream f(filename); //until the end of the file while(f) { //read firstname,lastname and score //it is like cin>>firstname>>lastname>>score f>>firstname>>lastname>>score; //add score to sum sum+=score; //increment n n++; } //print the average cout<<"Average score of all students: "<<sum/n<<endl; } //puts the highest and lowest score students to output.txt void highest_lowest(string filename) { //intialize highest as least possible score and lowest as highest possible score float highest_score=-1,lowest_score=9999; //these variables will be helpful to write to output.txt string lowest_firstname,lowest_lastname,highest_firstname,highest_lastname; string firstname,lastname; float score; //open the file (to read) ifstream f(filename); //read until the end of the file while(f) { //read names and score f>>firstname>>lastname>>score; //if score is greater than higest score, highest score is score if(score>highest_score) { highest_score=score; highest_firstname=firstname; highest_lastname=lastname; } //if score is smaller than lowest score, lowest score is score if(score<lowest_score) { lowest_score=score; lowest_firstname=firstname; lowest_lastname=lastname; } } //open the file output.txt using ofstream ofstream out("output.txt"); //this is formatted text to be put in the file string s="Highest Score: "+highest_firstname+" "+highest_lastname+" "+to_string(highest_score)+"\n"; //similar to cout<<s out<<s; s="Lowest Score: "+lowest_firstname+" "+lowest_lastname+" "+to_string(lowest_score)+"\n"; out<<s; } int main() { string filename; cout<<"Enter the name of the file\n"; cin>>filename; avergae_score(filename); highest_lowest(filename); return 0; }
Add a comment
Know the answer?
Add Answer to:
programming language is C++. Please also provide an explanation of how to create a file with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C++. Please Provide 4 Test Cases. Test # Valid / Invalid Data Description of test...

    Using C++. Please Provide 4 Test Cases. Test # Valid / Invalid Data Description of test Input Value Actual Output Test Pass / Fail 1 Valid Pass 2 Valid Pass 3 Valid Pass 4 Valid Pass Question 2 Consider a file with the following student information: John Smith 99 Sarah Johnson 85 Jim Robinson 70 Mary Anderson 100 Michael Jackson 92 Each line in the file contains the first name, last name, and test score of a student. Write a...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • THIS IS FINAL COURSE ASSIGNMENT, PLEASE FOLLOW ALL REQUIREMENTS. Hello, please help write program in JAVA...

    THIS IS FINAL COURSE ASSIGNMENT, PLEASE FOLLOW ALL REQUIREMENTS. Hello, please help write program in JAVA that reads students’ names followed by their test scores from "data.txt" file. The program should output "out.txt" file where each student’s name is followed by the test scores and the relevant grade, also find and print the highest test score and the name of the students having the highest test score. Student data should be stored in an instance of class variable of type...

  • c++ Instructions Overview In this programming challenge you will create a program to handle student test...

    c++ Instructions Overview In this programming challenge you will create a program to handle student test scores.  You will have three tasks to complete in this challenge. Instructions Task 1 Write a program that allocates an array large enough to hold 5 student test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the...

  • Using C programming For this project, you have been tasked to read a text file with student grade...

    Using C programming For this project, you have been tasked to read a text file with student grades and perform several operations with them. First, you must read the file, loading the student records. Each record (line) contains the student’s identification number and then four of the student’s numerical test grades. Your application should find the average of the four grades and insert them into the same array as the id number and four grades. I suggest using a 5th...

  • please write a c++ file using these two invoices attached as well as 2 extra for...

    please write a c++ file using these two invoices attached as well as 2 extra for the output. please do not use any libraiers other then, #include <fstream> #include <iostream> #include <string> #include<iomanip> (for styling.) Do not use void either. The program should ask for LastName FirstName DaysofRental and BalanceDue and sort it by last name then save to a file. Preconditions: File always has 10 records. The specification is as follows: ⦁ Sort the input file by last name,...

  • C++ Student Test Scores

    Write a program in C++ that reads students' names followed by their test scores. The program should output each student's name folloewd by the test scores and therelevant grade. It should also find and print the highest test score and the name of the students having the highest test score. Suppose that the class has 20students. Use an array of 20 components of type studentType.Your program must output each student's name in this form:last name followed by a comma, followed...

  • CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes...

    CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes the user and displays the purpose of the program. It then prompts the user to enter the name of an input file (such as scores.txt). Assume the file contains the scores of the final exams; each score is preceded by a 5 characters student id. Create the input file: copy and paste the following data into a new text file named scores.txt DH232 89...

  • C++ Write a program that reads students’ names followed by their test scores from the given...

    C++ Write a program that reads students’ names followed by their test scores from the given input file. The program should output to a file, output.txt, each student’s name followed by the test scores and the relevant grade. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, testScore of type int and grade of type char. Suppose that the class has 20 students. Use an array of...

  • PYTHON PROGRAMMING LANGUAGE (NEEDED ASAP) Using a structured approach to writing the program: This section will...

    PYTHON PROGRAMMING LANGUAGE (NEEDED ASAP) Using a structured approach to writing the program: This section will guide you in starting the program in a methodical way. The program will display a window with GUI widgets that are associated with particular functions: Employee Payroll O X -- - - - - - - - - - - Show Payroll Find Employee by Name Highest Lowest Find Employee by Amount Write Output to Fie Cancel - -------- ------------- Notice that some of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT