Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PROGRAMMING EXERCISES P3.1 Write a program that reads an integer and prints whether it is negative, zero, or positive. Write a program that reads a

image text in transcribed
PROGRAMMING EXERCISES P3.1 Write a program that reads an integer and prints whether it is negative, zero, or positive. Write a program that reads a floating-point number and prints "zero" if the number is zero. Otherwise, print "positive" or "negative". Add "small" if the absolute value of the number is less than 1, or "large" if it exceeds 1,000,000. .P3.2 Write a program that reads an integer and prints how many digits the number has, by check- ing whether the number is 2 10, z 100, and so on. (Assume that all integers are less than ten billion.) If the number is negative, first multiply it by-1 P3.3 Write a program that reads three numbers and prints "all the same" if they are all the same, all different" if they are all different, and "neither" otherwise. P3.4 Write a program that reads three numbers and prints "increasing" if they are in increasing or- der, "decreasing" if they are in decreasing order, and "neither" otherwise. Here, "increasing" means "strictly increasing", with each value larger than its predecessor. The sequence 3 44 P3,5 would not be considered increasing. P3.6 Repeat Excrciss .P3.5, but before reading the numbers, ask the user whether increasing/de- creasing should be "strict" or "lenient". In lenient mode, the sequence 3 4 4 is increasing and the sequence 4 4 4 is both increasing and decreasing. .. P3.7 Write a program that reads in three integers and prints "in order" if they are sorted in ascend- ing or descending order, or "not in order" otherwise. For example. 1 2 5 in order 1 5 2 not in order 5 21 in order 1 22 in order Write a program that reads four integers and prints "two pairs" if the input consists of two matching pairs (in some order) and "not two pairs" otherwise. For example P3.8 1 221 two pairs 1 2 2 3 not two pairs 222 2 two pairs Write a program that reads a temperature value and heit. Print whether water is liquid, solid, or gaseous at the given temperature at sea level. P3.9 the letter C for Celsius or F for Fahren- The boiling point of water drops by about one degree Celsius for every 300 meters (or 1,000 feet) of altitude. Improve the program of Exercise P39 to allow the user to supply P3.10 the alti- tude in meters or feet. Add error handling to Exercise P3.10 If the user provides an invalid unit for the altitude, print an error message and end the program. " P3.1 Write a program that translates a letter grade into a number grade. Letter grades are A, B, C D, and F, possibly followed by + or- Their numeric values are 4, 3, 2, 1, and 0. There is no value 4.0 F+ or F A+ increases the numeric value by 0.3, a-decreases it by 0.3. However, an A+ l P3.12 Enter a letter grade: B- The numeric value is 2.7 Write a program that translates a number between 0 and 4 into the closest letter grade. For ample, the number 2.8 (which might have been the average of several grades) would be co verted to B- Break ties in favor of the better grade; for example 2.85 should be a B P3.13 PROGRAMMING EXERCISES P3.1 Write a program that reads an integer and prints whether it is negative, zero, or positive. Write a program that reads a floating-point number and prints "zero" if the number is zero. Otherwise, print "positive" or "negative". Add "small" if the absolute value of the number is less than 1, or "large" if it exceeds 1,000,000. .P3.2 Write a program that reads an integer and prints how many digits the number has, by check- ing whether the number is 2 10, z 100, and so on. (Assume that all integers are less than ten billion.) If the number is negative, first multiply it by-1 P3.3 Write a program that reads three numbers and prints "all the same" if they are all the same, all different" if they are all different, and "neither" otherwise. P3.4 Write a program that reads three numbers and prints "increasing" if they are in increasing or- der, "decreasing" if they are in decreasing order, and "neither" otherwise. Here, "increasing" means "strictly increasing", with each value larger than its predecessor. The sequence 3 44 P3,5 would not be considered increasing. P3.6 Repeat Excrciss .P3.5, but before reading the numbers, ask the user whether increasing/de- creasing should be "strict" or "lenient". In lenient mode, the sequence 3 4 4 is increasing and the sequence 4 4 4 is both increasing and decreasing. .. P3.7 Write a program that reads in three integers and prints "in order" if they are sorted in ascend- ing or descending order, or "not in order" otherwise. For example. 1 2 5 in order 1 5 2 not in order 5 21 in order 1 22 in order Write a program that reads four integers and prints "two pairs" if the input consists of two matching pairs (in some order) and "not two pairs" otherwise. For example P3.8 1 221 two pairs 1 2 2 3 not two pairs 222 2 two pairs Write a program that reads a temperature value and heit. Print whether water is liquid, solid, or gaseous at the given temperature at sea level. P3.9 the letter C for Celsius or F for Fahren- The boiling point of water drops by about one degree Celsius for every 300 meters (or 1,000 feet) of altitude. Improve the program of Exercise P39 to allow the user to supply P3.10 the alti- tude in meters or feet. Add error handling to Exercise P3.10 If the user provides an invalid unit for the altitude, print an error message and end the program. " P3.1 Write a program that translates a letter grade into a number grade. Letter grades are A, B, C D, and F, possibly followed by + or- Their numeric values are 4, 3, 2, 1, and 0. There is no value 4.0 F+ or F A+ increases the numeric value by 0.3, a-decreases it by 0.3. However, an A+ l P3.12 Enter a letter grade: B- The numeric value is 2.7 Write a program that translates a number between 0 and 4 into the closest letter grade. For ample, the number 2.8 (which might have been the average of several grades) would be co verted to B- Break ties in favor of the better grade; for example 2.85 should be a B P3.13

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 1 Lnai 9284

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Carlos Soares ,Joao Gama ,Alipio Jorge

1st Edition

3319235273, 978-3319235271

More Books

Students also viewed these Databases questions

Question

Explain methods of metal extraction with examples.

Answered: 1 week ago