1. Write a program named program61.py
This program will have three functions, the main() create() and retrieve().
main() will call: create() and main() then calls retrieve()
create() will prompt the user to enter any number of course name | grade values. The course name ,AND calculated class GPA ( not the class grade ) are the written one value per line to a file named grades.txt ( review example of grades.txt below! ). Pressing Enter with no input value on the course name will exit the loop, close the file, print "File was created and closed" and return the bool value True to the main(). See Simple GPA Tip below.
retrieve() will open and read grades.txt. The function then will print the course names and Class GPA as shown below. The average of all class GPA values should be calculated and displayed to two decimal places and then return variable used for the GPA average to the main() . See sample run below in which 2 course names were entered, but note that more or fewer courses could have been entered. Also shown is what the contents of the grades.txt file would look like.
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images
- Write a function named repeat_words that takes two string parameters: 1. in_file: the name of an input file that exists before repeat_words is called 2. out_file: the name of an output file that repeat_words creates Assume that the input file is in the current working directory and write the output file to that directory. For each line of the input file, the function repeat_words should write to the output file all of the words that appear more than once on that line. Each word should be lower cased and stripped of leading and trailing punctuation. Each repeated word on a line should be written to the corresponding line of the output file only once, regardless of the number of times the word is repeated. For example, if the following is the content of the file catInTheHat.txt: Too wet to go out and too cold to play ball. So we sat in the house. We did nothing at all. So all we could do was to Sit! Sit! Sit! Sit! The following function call: inF = 'catInTheHat.txt' outF =…arrow_forwardChapter 4. PC #6. File Letter Counter (page 264) Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Class name: FileLetterCounter Hints: Hint 1. To read a single character from the keyboard, you need to read a full line and then take the first character in position 0. Hint 2. To count the occurrences of a given characters in a file you need to read the file line-by-line using a while loop, then for each line check all characters in all positions and increment the character counter for each occurrence. This will require to have a for-loop nested inside the while-loop.arrow_forwardWrite the code segments based on the given descriptions: Declare a file pointer called input. Open a file called location.txt for reading using this pointer. If the file is not available, display “File does not exist.”. The content of the text file location.txt is as shown below. It includes the location, latitude and longitude values. FILE location.txt CONTENTS <Location> <Latitude> <Longitude> UTM 1.5523763 103.63322 KLCC 3.153889 101.71333 UM 3.1185 101.665 UMS 6.0367 116.1186 UNIMAS 1.465174 110.4270601 Ask the user to enter a location. Check if the user’s location can be found in the text file. If found, display the location, latitude and longitude as shown below. SAMPLE OUTPUT Enter a location: UM Location : UM Latitude : 3.1185 Longitude : 101.6650 Otherwise display “Sorry, location could not be found”. SAMPLE OUTPUT Enter a location : MMU Sorry, location could not be foundarrow_forward
- Two of the menu options (#2 and #3) are unfinished, and you need to complete the code necessary to write to and read from a binary file. You will need to read through the code to find the functions that are called by these options, and then supply the missing code. Please help me get menu 2 and 3 to display properly.the .cpp and .h have the information:.cpp file: // Corporate Sales Data Outputusing namespace std; #include <iostream>#include <fstream>#include <stdlib.h>#include "HeaderClassActivity1.h" int main() { Sales qtrSales[NUM_QTRS]; while (true) { cout << "Select an option: " << endl; cout << "1. Input data" << endl; cout << "2. Write data to file" << endl; cout << "3. Read data from file" << endl; cout << "4. Display sales" << endl; cout << "99. End program" << endl; int menuItem; cin >> menuItem; if (menuItem ==…arrow_forwardChapter 4. Homework Assignment (read instructions carefully) Write a program that asks the user for the name of a file. The program should read all the numbers from the given file and display the total and average of all numbers in the following format (three decimal digits): Total: nnnnn.nnn Average: nnnnn.nnn Class name: FileTotalAndAverage est Case 1 Please enter the file name or type QUIT to exit:\ninput1.txtENTERTotal: 11.800\nAverage: 2.950\n Test Case 2 Please enter the file name or type QUIT to exit:\ninput2.txtENTERTotal: 17.300\nAverage: 3.460\n Test Case 3 Please enter the file name or type QUIT to exit:\ninput3.txtENTERTotal: 1.124\nAverage: 1.124\n Test Case 4 Please enter the file name or type QUIT to exit:\ninput4.txtENTERFile input4.txt is empty.\n Test Case 5 Please enter the file name or type QUIT to exit:\ninput5.txtENTERFile: input5.txt does not exist.\nPlease enter the file name again or type QUIT to…arrow_forwardThis part of the quiz will contain 4 parts. A function called grade, a function called pgrade, a prototype file called grade.h and a main function. In this part you will create the main function which will do the following: main This main function will use the functions grade and pgrade to produce the grades for the following students and display the appropriate grade with the appropriate message. The semester grade will be based on the fact that the quiz average is 25% of the grade, the final is 20% of the grade, assignments is 20% of the grade and programs are 35% of the grade. The student grades are as follows: Student Name Assignments Programs Quiz Ave Final Tom 63 Francis Maria Jan 75 90 95 85 sample of output Harry Grade B Good 85 75 95 90 93 92 71 69 87 91 73 Aarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education