You are on page 1of 2

COMP 1900 Fall 2017

Lab 5: Loops
Number of People: Individual

Due: By the time your lab would normally meet next week. But you are strongly encouraged to complete this lab before Exam 1!

Submission: Zip your project folder into a single file and upload it to the proper eLearn dropbox at https://elearn.memphis.edu.

Grader: Tyler Moore: tgmoore@memphis.edu; Laqin Fan : lfan1@memphis.edu; Sambriddhi Mainali: smainali@memphis.edu.
Rojina Maharjan: rmharjan@memphis.edu; Keli Cheng: kcheng@memphis.edu; Saurab Dulal : sdulal@memphis.edu ; Questions
about grading? Please contact him/her first!


Lab Homework
0. In Eclipse, please create a project with a project name of the form hw5LastFirst substituting your last name for
Last and your first name for First. For example, someone named John Smith would name his project
hw5SmithJohn.

1. (6 pts) Write a program that computes the overall numeric grade for each student in a class. The program should
begin by asking the user several questions about the class as a whole as follows. First, the program should prompt
the user to enter the number of tests that were given in the class. If the user specifies that fewer than two tests
were given in the class, the program should display an error message and continue prompting (and if necessary,
printing error messages) until a valid input is given. Next, the program should ask the user whether the lowest
test score should be dropped when computing each students overall numeric grade. Then the program should
prompt the user to enter the maximum test score considered valid.

Next, the program should prompt the user to enter the name of the current student or Q or q to quit. The program
should then prompt the user to enter each test score for the current student (referring to the current student by
name). If a negative value or a value exceeding the maximum valid test score is entered, the program should
display an error message and continue prompting (and if necessary, printing error messages) until a valid input is
given. Once the user has entered the specified number of valid test scores for the current student, the program
should report the current students overall numeric grade as the average of the students test scores (rounded to
two decimal places) after dropping the current students lowest test score if the user specified this procedure for
the class. The program should then continue by once again prompting the user to enter the name of the current
student or Q or q to quit, etc.
(7 pts) A prime number is a positive integer divisible only by itself and 1. A number which is not prime is
composite. For example, 2, 3, and 5 are prime, but 4 and 6 are composite.

A perfect number, p, is a positive integer that equals the sum of its divisors, excluding p itself. For example, 6 is a
perfect number because the divisors of 6 (1, 2, and 3) add up to 6.

Write a program which looks for primes and perfect numbers as follows. Prompt the user to enter the minimum
value to check, and ensure that the user enters an integer greater than 1. Next, prompt the user to enter the
maximum value to check, and ensure that the user enters an integer greater than the minimum value he/she just
entered.

For each integer x between the minimum and maximum values to check (inclusive), print a list of all the divisors
of x starting from 1 up to x-1. Then print whether x is prime or composite. Next, print whether x is perfect or not
perfect.

Finally, print a count of the number of primes found and a count of the number of perfect numbers found.

Here is the output from an example run of the program:

Let's search for prime numbers and perfect numbers!

Enter minimum value to check (an integer greater than 1): 0


That entry was not valid. Please be sure to enter an integer greater than 1.

Enter minimum value to check (an integer greater than 1): 1


That entry was not valid. Please be sure to enter an integer greater than 1.

Enter minimum value to check (an integer greater than 1): 2

Enter maximum value to check (an integer greater than the minimum value to check): 1
That entry was not valid. Please be sure to enter an integer greater than the minimum value
to check.

Enter maximum value to check (an integer greater than the minimum value to check): 2
That entry was not valid. Please be sure to enter an integer greater than the minimum value
to check.

Enter maximum value to check (an integer greater than the minimum value to check): 6

2 is divisible by: 1
2 is prime.
2 is not perfect.

3 is divisible by: 1
3 is prime.
3 is not perfect.

4 is divisible by: 1 2
4 is composite.
4 is not perfect.

5 is divisible by: 1
5 is prime.
5 is not perfect.

6 is divisible by: 1 2 3
6 is composite.
6 is perfect.

Primes found: 3
Perfect numbers found: 1

You might also like