Related questions with answers

In a course, a teacher gives the following tests and assignments: - A lab activity that is observed by the teacher and assigned a numeric score. - A pass/fail exam that has 10 questions. The minimum passing score is 70. - An essay that is assigned a numeric score. - A final exam that has 50 questions. Write a class named CourseGrades. The class should have a member named grades that is an array of GradedActivity pointers. The grades array should have four elements, one for each of the assignments previously described. The class should have the following member functions: setLab: This function should accept the address of a GradedActivity object as its argument. This object should already hold the student’s score for the lab activity. Element 0 of the grades array should reference this object. setPassFailExam: This function should accept the address of a PassFailExam object as its argument. This object should already hold the student’s score for the pass/fail exam. Element 1 of the grades array should reference this object. setEssay: This function should accept the address of an Essay object as its argument. (See Programming Challenge 6 for the Essay class. If you have not completed Programming Challenge 6, use a GradedActivity object instead.) This object should already hold the student’s score for the essay. Element 2 of the grades array should reference this object. setPassFailExam: This function should accept the address of a FinalExam object as its argument. This object should already hold the student’s score for the final exam. Element 3 of the grades array should reference this object. print: This function should display the numeric scores and grades for each element in the grades array. Demonstrate the class in a program.

Question

Write a program that reads in two floating-point numbers and tests whether they are the same up to two decimal places. Here are two sample runs. Enter a floating-point number: 2.0 Enter a floating-point number: 1.99998 They are the same up to two decimal places. Enter a floating-point number: 2.0 Enter a floating-point number: 1.98999 They are different.

Solution

Verified
Answered 7 months ago
Answered 7 months ago
Step 1
1 of 2
# convert inputs to float
num1 = float(input("Enter a first floating-point number: "))
num2 = float(input("Enter a second floating-point number: "))

# round(num1, 2) returns 
# num1 round to two decimal places
num1 = round(num1, 2)
num2 = round(num2, 2)

# if they are equal after the rounding
# they are the same up to 2 decimal places
if num1 == num2:
    print("They are the same up to two decimal places.")
# otherwise, they are different
else:
    print("They are different.")

Create an account to view solutions

Create an account to view solutions

Recommended textbook solutions

Computer Organization and Design MIPS Edition: The Hardware/Software Interface 5th Edition by David A. Patterson, John L. Hennessy

Computer Organization and Design MIPS Edition: The Hardware/Software Interface

5th EditionISBN: 9780124077263 (4 more)David A. Patterson, John L. Hennessy
220 solutions
Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionISBN: 9780133970777 (3 more)Ramez Elmasri, Shamkant B. Navathe
687 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionISBN: 9780262033848 (3 more)Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
726 solutions
Python for Everyone 2nd Edition by Cay S. Horstmann, Rance D. Necaise

Python for Everyone

2nd EditionISBN: 9781119056553 (1 more)Cay S. Horstmann, Rance D. Necaise
730 solutions

More related questions

1/4

1/7