Concept explainers
Given the scores . txt file described in
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Absolute C++, Student Value Edition, 6/e
Additional Engineering Textbook Solutions
Artificial Intelligence: A Modern Approach
Modern Database Management (12th Edition)
Problem Solving with C++ (10th Edition)
Starting Out with Java: Early Objects (6th Edition)
Starting Out with Programming Logic and Design (4th Edition)
Starting Out with C++: Early Objects
- Write a function that reads a single line of numbers from a file named "question1.txt", and returns the average of the numbers read. For example, if the file is as follows: ----- question1.txt ----- 1 3 5 -2 4 0 6 -2 -3 ------------------------- then the function must return 12/9 = 1.33333 """ def file_average(): return # Remove this line to answer this questionarrow_forwardCall the file: sinDrawline.cpp For this assignment, you will be creating two functions, alongside a main function: 1) toRadians: takes in degrees as input, and returns radians. Given a specified number of degrees, the radians is equal to degrees * PI/180. Important: Be sure to declare PI to be 3.14159. This is so that mimir always comes up with the same answers no matter which server is used. 2) Drawline: takes in two parameters: a character and numRepetitions and prints the character numRepetitions times, followed by a newline. In your main function, for every 5 degrees between 0 and 360, calculate and print out the value of sin(toRadians(degree)) like so: GIVEN 45 DEGREES: sin(45) = 0.70711 To use the sin function, make sure to include cmath in your program. Be sure to set decimal precision to 5 places! Every 90 degrees (including 0 and 360), print out a line of 30 dashes ('-') using drawline after your print out the value of sin. Inside main() For values between 0 and 360, in 5…arrow_forwardWrite a program vote.cc that allows to read from a file vote.in thelast names of the candidates in an election and the number of votes received by eachcandidate. The program should then output each candidate’s name, the number of votesreceived, and the percentage of the total votes received by the candidate. Your programshould also output the winner of the election. Your program should have at least the following functions:(a) Write a function openFile that prompts a user to enter a file name and opens it.(b) Write a function closeFile that closes an open file.(c) Write a function getData that reads from the file the candidate names and theirnumber of votes received and returns them in 2 separate arrays.(d) Write a function sumVote that takes as its parameter an array of number of votesand returns the total number of votes.(e) Write a function computePercentages that takes as its parameters an array ofnumber of votes and returns an array of percentages of votes. Your function shoulduse…arrow_forward
- (5) Write a function called copy_even_lines() that takes two strings (filenames) as input parameters and copies every other line from the first file into the second. That is, counting from 0, it copies the 0th line, the 2nd line, the 4th line, etc. from the first file to the second file. You may assume that both files exist. (6) Write a python program that asks the user for two filenames and calls your function copy_even_lines() from (5) using those two filenames. If one or more files do not exist, your program must handle the exception by repeating the prompts until valid filenames are entered.arrow_forwardWrite a program that reads a text and outputs the letters, together with their counts, as explained below in the function printResults. Your program should not have any global variables. All information should be accessed through the parameters of the functions. Your program should have the at least the following functions: • Function main – calls all the functions • Function openFile – opens the input and ouput files. This program has the file stream declare a refence parameter. An appropriate error message should be displayed if the file does not exist. The program must ask the user for the names of the input and output files. • Function countLetters – counts every of uppercase letters A – Z and lower-case letters from a – z in the text file opened in the function openFile. This information should be stored in an array of structures. Both the array and file identifiers must be passed as parameters. • Function printResults – prints the number of uppercase letters for every occurrence…arrow_forwardWrite a program that reads a text and outputs the letters, together with their counts, as explained below in the function printResults. Your program should not have any global variables. All information should be accessed through the parameters of the functions. Your program should have the at least the following functions: • Function main – calls all the functions • Function openFile – opens the input and ouput files. This program has the file stream declare a refence parameter. An appropriate error message should be displayed if the file does not exist. The program must ask the user for the names of the input and output files. • Function countLetters – counts every of uppercase letters A – Z and lower-case letters from a – z in the text file opened in the function openFile. This information should be stored in an array of structures. Both the array and file identifiers must be passed as parameters. • Function printResults – prints the number of uppercase letters for every occurrence…arrow_forward
- Write a program whose main function is merely a collection of variable declarations and function calls. This program reads a text and outputs the letters, together with their counts, as explained below in the function printResult. (There can be no global variables! All information must be passed in and out of the functions. Use a structure to store the information.) Your program must consist of at least the following functions: Function openFile: Opens the input and output files. You must pass the file streams as parameters (by reference, of course). If the file does not exist, the program should print an appropriate message ("The input file does not exist.") and exit. The program must ask the user for the names of the input and output files. Function count: Counts every occurrence of capital letters A-Z and small letters a-z in the text file opened in the function openFile. This information must go into an array of structures. The array must be passed as a parameter, and the file…arrow_forwardWrite a function called max_age(inFile, outFile, breed) for a (python program), that takes three strings as input parameters. The function reads all the data from the inFile (1st input parameter) and writes data to the outFile (2nd input parameter) as described below. Each line in the input file represents a pet record and has the following format. name, breed, age where name and breed are strings, and age is an integer value. Your function must find the oldest pet of a given breed (3rd input parameter) from the inFile and write the following information to the outFile. breed, total records of this breed name of the oldest pet, age of the oldest pet Note that outFile must only have these two lines of information. Suppose, inFile contains the following data: shadow, longhair, 3 poshi, bangal, 5 mikus, longhair, 4 tigger, calico, 9 If you call this function with breed = "longhair", then the following must be written in the outFile: longhair, 2 mikus, 4 Your…arrow_forwardWrite a program that receives a coded message file(Lab3ExtraCreditCT.txt) from your local espionage agent and decodes it into a file using standard English. The problem is your agent forgot to tell you the key used to decode the message. Fortunately, this is a simple substitution code consistently using 1 alphanumeric character to represent another, this is case sensitive. All other characters are not substituted, so a space will always be a space, a – will always be a –, a @ will always be a @, etcetera. You may use the following table to help you, it contains the most common letters used in the English language in descending order. E A R I O T N S L C U D P M H G B F Y W K V X Z J Q 0 5 3 2 4 6 8 1 9 7 Using the following key to convert plaintext to coded text: Plaintext = Now is the time for all good men to come to the aid of their country. Key = THEQUICKBROWNFXJMPSVLAZYDG The file your program outputs should look like this: Coded Text = Fxz bs vku vbnu ixp tww…arrow_forward
- For an e-Shop, there is a Customer whose data is stored in a file ‘Customers.txt’, where ID, Name, Phone, Address, Email and AmountBalance. When the customer buys a product and pays from his AmountBalance, the system checks his balance and deducts if enough amount is there. Otherwise the customer receives a message “You don’t have sufficient Balance in your wallet”. Write python code to create a ‘Customers.txt’ file with at least one customer’s record. Write a function pay(), that takes amount as an input, reads the file and gets AmountBalance, print “Successful Transaction” when payment can be made or a message “You don’t have sufficient Balance in your wallet”. Write a function checkBalance(), that reads the file and gets AmountBalance, prints “Amaount Balance” Write a function recharge(), that takes “Enter Amount you want to recharge”, reads the file and gets AmountBalance, adds the new amount in AmountBalance, update the file and prints “Success”arrow_forwardWrite a program email.cc that takes an email address in the following format: firstname.lastname@hotmail.com, such as jon.doe@hotmail.com, extracts from it the firstname and the lastname, and prints them in the following format: Lastname, Firstname. Your program should have and use at least the following functions:(a) getEmaillAddress that prompts a user to enter an email address as a string andreturns it.(b) extract that takes as its parameter an email address and returns the firstname andlastname.(c) capitalize that takes as its parameter a string and capitalize its first letter.(d) display that takes as its parameters 2 strings corresponding to the firstname andlastname, and displays them in the following format: Lastname, Firstname.Your program should repeatedly prompts the user to enter the email address in the previous format. The program should then output it as in the examples below. jon.doe@uleth.caDoe, JonTry again (Y/N) -- Ycarol.smith@uleth.caSmith, CarolTry again (Y/N)…arrow_forwardYou are given a file consisting of students’ names in the following form: lastName, firstName middleName. (Note that a student may not have a middle name.) Write a program that converts each name to the following form: firstName middleName lastName. Your program must read each student’s entire name in a variable and must consist of a function that takes as input a string, consists of a student’s name, and returns the string consisting of the altered name. Use the string function find to find the index of ,; the function length to find the length of the string; and the function substr to extract the firstName, middleName, and lastName.arrow_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