Lab 11 - Practice III: Sample Input/Output
Lab 11 - Practice III: Sample Input/Output
1. Write a MATLAB script that takes the number of classes (the algorithm should check
that it is a positive number and prompts the user to reenter if wrong) as input and
prompts the user to enter the marks of students for each class and counts the number
of students who got A, B, C, D, and F and the lowest and highest grade students. The
algorithm should stop for each class if the user entered a mark out of the range
(0:100). At the end, the program will ask the user if he/she wants to continue and if
the answer is yes the program will be repeated.
A: 90-100, B: 80-89, C: 70-79, D: 60-69, F: <60.
Sample Input/Output:
Enter No. of Classes:-2
Error, Enter No. of Classes:2
Class No. 1
Student 1- Enter grade: 71
Student 2- Enter grade: 81
Student 3- Enter grade: 94
Student 4- Enter grade: 61
Student 5- Enter grade: 92
Student 6- Enter grade: -1
We got 2 A, 1 B, 1 C, 1 D, 0 F.
Student 4 got the lowest grade: 61
Student 3 got the highest grade: 94
Class No. 2
Student 1- Enter grade: 71
Student 2- Enter grade: 93
Student 3- Enter grade: 81
Student 4- Enter grade: 101
We got 1 A, 1 B, 1 C, 0 D, 0 F.
Student 1 got the lowest grade: 71
Student 2 got the highest grade: 93
End of Classes
Do you want to continue?? (y for Yes and n for No): n
Page 1
CHS – Spring 2016 Faculty of Engineering
Computers For Engineers Cairo University
(GENN004) Page 2 of 3
2. Write a MATLAB script that prompts the user for two inputs, the first is a 1 D array
that represents the height of a group of cylinders and the second array is 2D array
containing the perimeter and area of the base of the same group of cylinders (the
program should check that the input arrays contain no negative numbers and if they
contain it must prompts the user to reenter again). The script should calculate the
surface area and volume of each cylinder and print the output as in the shown
example. Also it should calculate the average surface area and the number of
cylinders that have areas larger than average area and the same for the volume. At the
end, the program will ask the user if he/she wants to continue and if the answer is yes
the program will be repeated.
Sample Input/Output:
Page 2
CHS – Spring 2016 Faculty of Engineering
Computers For Engineers Cairo University
(GENN004) Page 3 of 3
3. Using Vectorized code, write a program that reads customers IDs and waiting time
from a 2D array. The program first calculates the average waiting time. Then it prints
the following data on the screen
a. The average waiting time
b. Customer ID and waiting time for customers who waits for a time longer than
the average waiting time.
Example:
Input 2D array: [34 15; 12 2; 21 24; 35 32; 78 13; 18 8]
Output: Average Waiting Time = 15.7
Customers who waited longer:
ID Waiting
21 24
35 32
4. Write a program that reads from the user two limits, the first limit is the low grade
while the second limit is the high grade. Then, the program reads the grades array
from the user. The program check all grades in the grades array to make sure it is
between 0 and 100 otherwise, it asks the user to renter the grades array. The program
should print out to the user at the end the following: number of entered grades
between the low and high grade, and the maximum entered grade between the low
and high grade. The input and output of the program should look like the shown
examples.
Example 1
Please enter the low grade:70
Please enter the high grade:80
Enter Grades Array:[100 77 73 79 88 99 0 75]
Number of entered grades between 70 and 80 = 4
Maximum entered grade between 70 and 80 = 79
*** End of Program ***
Example 2
Please enter the low grade:60
Please enter the high grade:75
Enter Grades Array:[0 55 200 ]
Error Enter Grades Array:[0 55 -200 ]
Error Enter Grades Array:[0 55]
No grades entered between 60 and 75
*** End of Program ***
Page 3