Write a program that reads a file of floating-point numbers

Assignment Help C/C++ Programming
Reference no: EM132677782

Practical - Files

Greater-Than Counter

Write a program that reads a file of floating-point numbers, and counts how many of those numbers are larger than a user-specified lower limit.
Example file:
Copy this text into a new file called recentrain.txt,
or download it here.
12.4
10.0
10.1
0
8.4
13.9
19.1
141.0
33.5
1.2
Example output:
Filename: recentrain.txt
Threshold: 10
Processing...
6 out of 10 (60.0%) of values are greater than 10.0.
BMI File
File: bmi_files.py
Write a program that writes to and reads from bmis.txt (not at the same time).
Reuse your code from Prac 7 where you calculated a person's BMI based on height and weight.
Prac 7 :Write a new main program with a loop that runs through a number of weights for a 1.75m person, as below.
value = 3.1415926535
print(f"{value:.1f}") # prints 3.1
The : separates the variable name (value) from the "format specifier".
In this case, .1f means to produce only 1 decimal place for our float.
Another common format specifier is just a number, like:
value = 17
print(f"!{value:4}!") # prints ! 17! (that is, 17 takes up 4 spaces)
OK, let's do this:
Height 1.75m, Weight 50kg = BMI 16.3, considered underweight
Height 1.75m, Weight 52kg = BMI 17.0, considered underweight
Height 1.75m, Weight 54kg = BMI 17.6, considered underweight
Height 1.75m, Weight 56kg = BMI 18.3, considered underweight
Height 1.75m, Weight 58kg = BMI 18.9, considered normal
Height 1.75m, Weight 60kg = BMI 19.6, considered normal
Height 1.75m, Weight 62kg = BMI 20.2, considered normal
Height 1.75m, Weight 64kg = BMI 20.9, considered normal
Height 1.75m, Weight 66kg = BMI 21.6, considered normal
Height 1.75m, Weight 68kg = BMI 22.2, considered normal
Height 1.75m, Weight 70kg = BMI 22.9, considered normal
Height 1.75m, Weight 72kg = BMI 23.5, considered normal
Height 1.75m, Weight 74kg = BMI 24.2, considered normal
Height 1.75m, Weight 76kg = BMI 24.8, considered normal
Height 1.75m, Weight 78kg = BMI 25.5, considered overweight
Height 1.75m, Weight 80kg = BMI 26.1, considered overweight
Height 1.75m, Weight 82kg = BMI 26.8, considered overweight
Height 1.75m, Weight 84kg = BMI 27.4, considered overweight
Height 1.75m, Weight 86kg = BMI 28.1, considered overweight
Height 1.75m, Weight 88kg = BMI 28.7, considered overweight
Height 1.75m, Weight 90kg = BMI 29.4, considered overweight
Height 1.75m, Weight 92kg = BMI 30.0, considered obese
Height 1.75m, Weight 94kg = BMI 30.7, considered obese
Height 1.75m, Weight 96kg = BMI 31.3, considered obese
Height 1.75m, Weight 98kg = BMI 32.0, considered obese
Height 1.75m, Weight 100kg = BMI 32.7, considered obese
Got it? Good. Now, let's try it with varying heights as well as weights, like:
Hint: 1.5m is 150cm; useful to know since range only works with integers.
Notice also that the values line up nicely. You don't have to do this, but see if you can.
Height 1.5m, Weight 50kg = BMI 22.2, considered normal
Height 1.5m, Weight 60kg = BMI 26.7, considered overweight
Height 1.5m, Weight 70kg = BMI 31.1, considered obese
Height 1.5m, Weight 80kg = BMI 35.6, considered obese
Height 1.5m, Weight 90kg = BMI 40.0, considered obese
Height 1.5m, Weight 100kg = BMI 44.4, considered obese
Height 1.6m, Weight 50kg = BMI 19.5, considered normal
Height 1.6m, Weight 60kg = BMI 23.4, considered normal
Height 1.6m, Weight 70kg = BMI 27.3, considered overweight
Height 1.6m, Weight 80kg = BMI 31.2, considered obese
Height 1.6m, Weight 90kg = BMI 35.2, considered obese
Height 1.6m, Weight 100kg = BMI 39.1, considered obese
Height 1.7m, Weight 50kg = BMI 17.3, considered underweight
Height 1.7m, Weight 60kg = BMI 20.8, considered normal
Height 1.7m, Weight 70kg = BMI 24.2, considered normal
Height 1.7m, Weight 80kg = BMI 27.7, considered overweight
Height 1.7m, Weight 90kg = BMI 31.1, considered obese
Height 1.7m, Weight 100kg = BMI 34.6, considered obese
Height 1.8m, Weight 50kg = BMI 15.4, considered underweight
Height 1.8m, Weight 60kg = BMI 18.5, considered normal
Height 1.8m, Weight 70kg = BMI 21.6, considered normal
Height 1.8m, Weight 80kg = BMI 24.7, considered normal
Height 1.8m, Weight 90kg = BMI 27.8, considered overweight
Height 1.8m, Weight 100kg = BMI 30.9, considered obese
Height 1.9m, Weight 50kg = BMI 13.9, considered underweight
Height 1.9m, Weight 60kg = BMI 16.6, considered underweight
Height 1.9m, Weight 70kg = BMI 19.4, considered normal
Height 1.9m, Weight 80kg = BMI 22.2, considered normal
Height 1.9m, Weight 90kg = BMI 24.9, considered normal
Height 1.9m, Weight 100kg = BMI 27.7, considered overweight

The first part of your program should ask the user for a number of people, then repeatedly ask for the details for that many people. (You did just think of what kind of loop to use, didn't you?)
For each person, calculate their BMI, but don't print it to the screen... write it to the file "bmis.txt".
Don't forget to close the file when you have finished.
Test this and confirm it works as you expect.
Then, write the second part, which should read the file and display the BMI and weight category similar to how we've done it before:
BMI 23.5, considered normal
BMI 25.5, considered overweight
BMI 24.2, considered normal
BMI 16.3, considered underweight
BMI 32.0, considered obese
File Filter
File: file_filter.py
Write a program that reads a file and "filters" it, writing only certain lines to another file.
In the lecture, we wrote a program that read letter.txt and printed every line that started with a capital.
For this program, write a program that asks the user for three things:
• input file name
• output file name
• a search string to look for lines that start with
Read the input file, and then for each line that starts with the search string, write those to the output file.

Attachment:- Practical 10.rar

Reference no: EM132677782

Questions Cloud

Policy requirements of government and health care sector : Discuss the differences in policy requirements of the government and health care sectors.
Prepare a single combined journal entry to record issuance : The company also incurred $1,710 of costs associated with issuing the shares. Prepare a single combined journal entry to record the issuance
Explain the differences between static and dynamic models : Explain the differences between static and dynamic models. How can one evolve into the other? What is the difference between an optimistic approach.
How the governmental accounting standards board summaries : How the Governmental Accounting Standards Board (GASB) "Summaries of Statement No. 34: Basic Financial Statements - and Management's Discussion
Write a program that reads a file of floating-point numbers : Write a program that reads a file of floating-point numbers, and counts how many of those numbers are larger than a user-specified lower limit
Find what would be the expected share price : The underwriting spread is 5% and other direct financing expenses are $200,000. Based on this new information, what would be the expected share price?
Find the balance in the cash account at the end of March : They pay payroll costs of $5,000; and they pay other operating expenses of $7,000. Find the balance in the cash account at the end of March
Geographically dispersed teams : How do geographically dispersed teams collaborate effectively?
Positive impacts management information system : Explain some of the positive impacts management information system have on an organization.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd