Concept explainers
Using Files—Total and Average Rainfall
Write a
During the months of March–June, the total rainfall was 7.32 inches and the average monthly rainfall was 1.83 inches.
Data for the program can be found in the Rainfall. txt file located in the Chapter 5 programs folder on the book’s companion website.
Hint: After reading in the month names, you will need to read in rain amounts until the EOF is reached and count how many pieces of rain data you read in.
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Starting Out with C++: Early Objects (9th Edition)
Additional Engineering Textbook Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
Problem Solving with C++ (10th Edition)
Starting Out With Visual Basic (7th Edition)
Database Concepts (7th Edition)
Problem Solving with C++ (9th Edition)
Starting Out with Python (3rd Edition)
- The manager of a football stadium wants you to write a program that calculates the total ticket sales after each game. There are four types of tickets—box, sideline, premium, and general admission. After each game, data is stored in a file in the following form: ticketPrice numberOfTicketsSold … Sample data are shown below: 250.75 5750 100.50 28000 50.25 35750 25.00 18750 The first value indicates that the ticket price is Php 250.75 and that 5750 tickets were sold at that price. Output the total number of tickets sold and the total sale amount using c++ compiler. Format your output with two decimal places.arrow_forwardwrite a program in python Write a program that will allow a student to enter their name and then ask them to solve 10 mathematical equations. The program should display two random numbers that are to be added, such as: 247 + 129 The program should allow the student to enter the answer. The program should then display whether their answer was right or wrong, and accumulate the right values. After the 10 questions are asked, calculate the average that was correct. Then display the student name, the number correct, and the average correct in both decimal and percentage format. In addition to any system functions you may use, you might consider the following functions: A function that allows the student to enter their name. A function that gets two random numbers, anywhere from 1 to 500. A function that displays the equation and asks the user to enter their answer. A function that checks to see if the answer is correct and accumulates the number correct. A function that calculates the…arrow_forwardJava Your program must read a file called personin.txt. Each line of the file will be a person's name, the time they arrived at the professor's office, and the amount of time they want to meet with the professor. These entries will be sorted by the time the person arrived. Your program must then print out a schedule for the day, printing each person's arrival, and printing when each person goes in to meet with the professor. You need to print the events in order of the time they happen. In other words, your output will be sorted by the arrival times and the times the person goes into the professor's office. In your output you need to print out a schedule. In the schedule, new students go to the end of the line. Whenever the professor is free, the professor will either meet with the first person in line, or meet with the first person in line if nobody is waiting. Assume no two people arrive at the same time. You should solve this problem using a stack and a queue. You can only…arrow_forward
- A file concordance tracks the unique words in a file and their frequencies. Write a program that displays a concordance for a file. The program should output the unique words and their frequencies in alphabetical order. Variations are to track sequences of two words and their frequencies, or n words and their frequencies. Below is an example file along with the program input and output: example.txt I AM SAM I AM SAM SAM I AMarrow_forwardMust be written in Python.arrow_forwardWrite a program that produces a bar chart showing the population growth of Prairieville, a small town in the Midwest, at 20 year intervals during the past 100 years. The program should read in the population figures (rounded to the nearest 1000 people) for 1910, 1930, 1950, 1970, 1990, and 2010 from a file. For each year it should display the date and a bar consisting of one asterisk for each 1000 people.arrow_forward
- By use python languagearrow_forwardFor this assignment, you will write a Python program that uses a file named scores.txt to store sets of bowling scores for different dates. scores.txt should store the data so that each line has a month, day, and the scores the user earned on that date. As an example, scores.txt might look something like this: January 15 200 300 126 200 250April 20 125 100 May 17 300 100 215 The very first time your program starts, scores.txt should not exist (i.e. create it with Python code the first time the program runs). In your main function, continuously give the user the following five options: Quit the program. View all Scores. If the user selects this option, call a function named view_scores. This function should print the scores in a nicely formatted manner. For example: "On January 15, you scored 200, 300, and 126", etc.. Add a Score. If the user selects this option, call a function named add_score. This function should ask the user for a month, day, and as many scores as they want to…arrow_forwardComputer Science use putty Write a program that includes a function that calculates the equation F= xn sin x. Write the values n, x, and F on the screen and in a file 'data_f.data'. Repeat the program for positive n. Write a program that includes a function that calculates the equation F= x" sin x. Write the values n, x, and F on the screen and in a file data f.data'. Repeat the program for positive n.arrow_forward
- Assignment Write a program that moves a forester unit and a desert corps unit to a given target location and prints the number of hours it took for each unit to reach the target. First, the user will give the starting X and Y positions of the forester unit as well as its base speed (all ints). Then, the starting X and Y positions of the desert corps unit as well as its base speed (all ints). Finally, the target X and Y positions (both ints) and the terrain type (std::string). Speeds are given as distance traveled in one full day (i.e., 24 hours) and is affected by the terrain type using a multiplier over the base speed. Also, after 1 full day, each unit rests for a certain number of hours. Speed multiplier and rest amount of each type of unit depending on the terrain type are as below. Speed Multiplier Rest Duration After 1 day Terrain type Forester Desert Corps Forester Desert Corps Forest 1.3 0.6 4 12 Desert 0.4 1.2 15 6 Hills 0.7 0.8 6 8 Others 1.0 0.8 8 6 After getting all this…arrow_forwardUse loop to solve this python program and use Error handling:IOError (File not found)arrow_forwardTransient PopulationPopulations are affected by the birth and death rate, as well as the number of people who move in and out each year. The birth rate is the percentage increase of the population due to births and the death rate is the percentage decrease of the population due to deaths. Write a program that displays the size of a population for any number of years. The program should ask for the following data: The starting size of a population P The annual birth rate (as a percentage of the population expressed as a fraction in decimal form)B The annual death rate (as a percentage of the population expressed as a fraction in decimal form)D The average annual number of people who have arrived A The average annual number of people who have moved away M The number of years to display nYears Write a function that calculates the size of the population after a year. To calculate the new population after one year, this function should use the formulaN = P + BP - DP + A - Mwhere N is the…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning