Sale!

COP3223C Small Program 4 Solved 

Original price was: $35.00.Current price is: $30.00.

Download Details:

  • Name: smallprogram4-spzeus.zip
  • Type: zip
  • Size: 314.28 KB

Category:

Description

5/5 - (1 vote)

Problem 1

Write a user-defined function definition called perfectSquare that prints a nice hollow square
made out of * characters. The function has no parameters and does not return any values. Inside
Figure 3: Sample out for problem 1. Make sure your output matches this for the script!

the function definition, you will prompt the user for a number that will be used in generating the
square. If the user inputs an invalid number (0 or negative), then an error message should
display informing the user and to try again. See figure 3 for a sample output of the problem.
Small Program 4 Page 4

Problem 2

Write a user defined function definition called elevator that simulates a menu of an elevator
with options the user can select. The function takes no arguments and does not return anything.
The user defined function will ask the user which floor they would like to go to.

The user will
select one of the twelve options and the program will display the floor selected. See figure 4
for the message that is displayed for each respective floor number. If the user selects any valid
Figure 4: Output based on the floor selected.

option 1-12, the program will ask the user to enter another option. If the user selects option 5,
the program will not loop again and display the message “Elevator door is now open. Please exit
now.” If the user selects an invalid option, the message “That is not a valid option.” is displayed.
Figure 5 shows a sample run on the terminal.

Figure 5: Sample output for problem 2. Make sure the output matches for the script to test.
Small Program 4 Page 5

Problem 3

Write a user-defined function definition called pyramid that prints the following following pattern.
The function has no parameters and does not return any values. Inside the function definition,
Figure 6: Sample out for problem 3. Make sure your output matches this for the script!

you will prompt the user for a number that will be used in generating the pattern of ‘-’. If the user
inputs an invalid number (0 or negative), then an error message should display informing the
user and to try again. See figure 6 for a sample output of the problem.
Small Program 4 Page 6

Problem 4

You have been asked by the legendary Ms. Valerie Frizzle to calculate the average of a recent
test from a magic school bus field trip in space. Write a user defined function called classAvg.
The function has one parameter that represents the number of the students in the class.

That
value is collected in the main function (you also have to assume that an invalid number 0 or a
negative number could be entered). If an invalid number is entered, then the user should be
asked to enter another value.

Once the proper value for the number of students is entered, the
function is then going to prompt the user to enter the test score of each student. The scores can
range from 0 ≤ score ≤ 100 (there can even be decimal values).

The function must also handle
if the user enters an invalid score that is not in the provided range. If the user enters an invalid
score, the program will the user again to input the proper value. Once all scores are entered, the
average is computed and sent back to the main function to be displayed.

The value of average
is of type double. The resulting average is displayed as a percentage up to four decimal places.
The following figure shows a sample run with class size of 4.

For this problem, you cannot use
arrays (we have not covered them yet)! If arrays are used, then No Credit will be given for this
problem.
Small Program 4 Page 7