Related questions
Concept explainers
Description
Write a program to compute average grades for a course. The course records are in a single file and are organized according to the following format: each line contains a student's first name, then one space, then the student's last name, then one space, then some number of quiz scores that, if they exist, are separated by one space. Each student will have zero to ten scores, and each score is an integer not greater than 100. Your program will read data from this file and write its output to a second file. The date in the output file will be nearly the same as the data in the input file except that you will print the names as last-name, first-name; each quiz score, and there will be one additional number at the end of each line:
the average of the student's ten quiz scores.
Both files are parameters. You can access the name of the input file with argv[1]. and the name of the output file with argv[2].
The output file must be formatted as described below:
1. First and last names appear togeter in a left-justified column that is 20 characters wide where the last name comes first and a space and then the first name. Read each name separately and then put them together into a larger correctly formatted string before
trying to output them (you can use the concatenate two strings example in class as a reference).
2. Each quiz score should be listed in a right-justified column that is 4 characters wide. Note that if a student has fewer than 10 scores (they have missed one or more of the quizzes), your program will need to display the missing score(s) using 0 for each one.
3. The average should appear in its own column that is 10 characters wide. Note that if a student has fewer than 10 scores, the average is still the sum of the quiz scores divided by 10.
4. The average should be computed with an accuracy of two decimal places.
You should use at least two functions that include FILE handles in their parameter lists.(These functions may have other parameters as well.) Suggestion: One very useful strategy is to write a function that, given a FILE pointer, will extract out exactly one person's name and write it to the out put file. Write another function that, given a FILE pointer will extract out one person's quiz scores and list them in the output file along with the average score. Then use these two functions in a loop that will keep doing this until there is no more data in the input file. The feof function may be helpful for determining if you have reached the end of the input file
You may not use %s together with scanf (or fscanf) or gets, which are not safe as we mentioned in class. Don't use any library functions related to c-strings, e.g. strcpy, strlen, atoi,itoa, for the purpose of practice. You don't need to and should not use any non-string arrays.
Some test cases you may want to consider are the following:
• What if the input file is empty?
• What if a student does not have any quiz grades at all?
• What if multiple students in a row don't have any quiz grades?
• What if the last record in the file does not have a new line after it but rather ends with end of file?
• What if there are extra new lines at the end of the file?
When you run the program, because the output is written to a file, don't be surprised to see nothing in the output dialog. In order to see your results, you may use the technique that we learned in class to assign stout to your output file pointer temporarily so that you can check the result. After you finish debugging, change your code back.
A sample file, quiz_test. txt is available for download. The input file is shown below for your reference. This is NOT the file that will test your program. Don't assume that the input file will be exactly like this. Your program should be able to handle arbitrary numbers of records and you should consider all of the test cases listed above (or more).
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 2 images
- C++ Visual Studio 2019 Write a program that opens a specified text file then displays a list of all the unique words found in the file. Addition to the text book specifications, print the total of unique words in the file. Hint: Store each word as an element of a set. Note: Save text below as the file to use and name it forChap12.txt file for this assignment. Text: No one is unaware of the name of that famous English shipowner, Cunard. In 1840 this shrewd industrialist founded a postal service between Liverpool and Halifax, featuring three wooden ships with 400-horsepower paddle wheels and a burden of 1,162 metric tons. Eight years later, the company's assets were increased by four 650-horsepower ships at 1,820 metric tons, and in two more years, by two other vessels of still greater power and tonnage. In 1853 the Cunard Co., whose mail-carrying charter had just been renewed, successively added to its assets the Arabia, the Persia, the China, the Scotia, the Java, and the Russia,...arrow_forward*Coding language is Python Write a program that opens the productsales.txt file and reads the sales into a list. The program should output the following information, in this order: The total of all sales in the list The average of all sales in the list The lowest sale in the list The highest sale in the list NOTE: Your program should include at least one user-defined function, in addition to the main function. 4147 1594 2235 8433 10000 129 5555 7030 9764 7465 1111 4444 8954 2243 2895 1436 4978 5486 1436 9846 4789 8456 2497 2280 6375arrow_forwardJAVA PROGRAM Homework #2. Chapter 7. PC #13. Name Search (page 492) Read these instructions for additional requirements carefully. Write a program that reads the contents of the two files into two separate arrays. The user should be able to enter a name the application will display messages indicating whether the names were among the most popular. 1. GirlNames.txt and BoyNames.txt contain a list of the 200 most popular names given to girls/boys born in the United States for the years 2000 through 2009. 2. Your application should use an array to hold the names. 3. The program should continue interacting with the user indefinitely unless the user chooses to quit by entering "QUIT" (should be case insensitive). 4. The user should enter a single name and the program will search the name in both lists. The user SHOULD NOT specify whether the search is for girls name or boys name. The program is responsible for finding either or both and telling the user where it found it. 5....arrow_forward
- Computer Science csv file "/dsa/data/all_datasets/texas.csv" Task 6: Write a function "county_locator" that allows a user to enter in a name of a spatial data frame and a county name and have a map generated that shows the location of that county with respect to other counties (by using different colors and/or symbols). Hint: function(); $county ==; plot(); add=TRUE.arrow_forwardDrill 1 Exercise 1. Write a program that will declare a Student structure datatype (shown below). The program will ask the user for 10 records of type Student. The program will have the following Menu Items that the user can execute: *******MENU 1. SEARCH 2. EDIT a Record 3. SORT the Array of Record 4. QUIT CHOICE: *** Search Menu Item: This will ask the user for a Surname of a student, and output the record of student/s that equals to the query surname Edit a Record Menu Item: This will also ask for Student Number (Unique Identifier), if the Student Number is present in the array of records, the user will be ask to edit all the information about that particular record. Sort the Array of Record Menu Item: This will Sort the Array of Records based on the Surname. This will also trigger the program to output all the records and information for each record. OUIT Menu Item: This will Exit the Program. NOTE: For this program exercise, use dynamic memory allocation in declaring the array of...arrow_forward5. Charge Account Validation If you have downloaded the source code from the Computer Science Portal you will find a file named charge_accounts.txt in the Chapter 07 folder. This file has a list of a com- pany's valid charge account numbers. Each account number is a seven-digit number, such as 5658845. Programming Exercises 403 program Write a program that reads the contents of the file into a list. The program should then ask the user to enter a charge account number. The program should determine whether the number is valid by searching for it in the list. If the number is in the list, the should display a message indicating the number is valid. If the number is not in the list, the program should display a message indicating the number is invalid. (You can access thearrow_forward
- Using C# in Microsoft Visual Studio create an application that grades the written portion of the driver’s license exam. The exam has 20 multiple-choice questions. (The correct answers are provided in the screenshot.) the program should store these correct answers in an array. The program should read the student’s answers for each of the 20 questions from a text file and store the answers in another array. (Create your own text file to test the application.) After the student’s answers have been read from the file, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question numbers of the incorrectly answered questions.arrow_forwardSuppose a teacher has five students who have taken four tests. The teacher uses the following grading scales to assign a letter grade to a student, based on the average of his or her four test scores. Test Score Letter Grade 90-100 80-89 70-79 60-69 0-59 A B C D F Create an application that uses an array of strings to hold the five student names, an array of five strings to hold each student's letter grades, and five arrays of four single precision numbers to hold each student's set of test scores.arrow_forwardGame of Hunt in C++ language Create the 'Game of Hunt'. The computer ‘hides’ the treasure at a random location in a 10x10 matrix. The user guesses the location by entering a row and column values. The game ends when the user locates the treasure or the treasure value is less than or equal to zero. Guesses in the wrong location will provide clues such as a compass direction or number of squares horizontally or vertically to the treasure. Using the random number generator, display one of the following in the board where the player made their guess: U# Treasure is up ‘#’ on the vertical axis (where # represents an integer number). D# Treasure is down ‘#’ on the vertical axis (where # represents an integer number) || Treasure is in this row, not up or down from the guess location. -> Treasure is to the right. <- Treasure is to the left. -- Treasure is in the same column, not left or right. +$ Adds 50ドル to treasure and no 50ドル turn loss. -$ Subtracts...arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education