0% found this document useful (0 votes)
61 views3 pages

Lab 11 - Practice III: Sample Input/Output

The document provides instructions for 4 MATLAB scripting exercises: 1. A script that takes student grades as input across multiple classes and calculates grade distributions. 2. A script that calculates surface areas and volumes of cylinders given their heights and base properties. It also calculates average surface areas and volumes. 3. A vectorized script that calculates average waiting times from a 2D array of customer data and identifies customers above the average. 4. A script that counts grades within a given range from a user-input array, checking that grades are between 0-100.

Uploaded by

Ali Mahmoud
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views3 pages

Lab 11 - Practice III: Sample Input/Output

The document provides instructions for 4 MATLAB scripting exercises: 1. A script that takes student grades as input across multiple classes and calculates grade distributions. 2. A script that calculates surface areas and volumes of cylinders given their heights and base properties. It also calculates average surface areas and volumes. 3. A vectorized script that calculates average waiting times from a 2D array of customer data and identifies customers above the average. 4. A script that counts grades within a given range from a user-input array, checking that grades are between 0-100.

Uploaded by

Ali Mahmoud
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CHS – Spring 2016 Faculty of Engineering

Computers For Engineers Cairo University


(GENN004) Page 1 of 3

Lab 11 – Practice III

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

Lab 11 – Practice III

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:

x=[1; -2; 3; 4];


Error, x=[1; 2; 3; 4];
y=[1 2; 3 4; -5 6; 7 8];
Error, y=[1 2; 3 4; 5 6; 7 8];

The area of Cylinder No. 1 is: 1


The area of Cylinder No. 2 is: 6
The area of Cylinder No. 3 is: 15
The area of Cylinder No. 4 is: 28
The volume of Cylinder No. 1 is: 2
The volume of Cylinder No. 2 is: 8
The volume of Cylinder No. 3 is: 18
The volume of Cylinder No. 4 is: 32

The average surface area is 12.50


We have 2 cylinders with area larger than the average.
Cylinder No. 1 has the smallest area 1
Cylinder No. 4 has the largest area 28
The average volume is 15
We have 2 cylinders with volume larger than the average.
Cylinder No. 1 has the smallest volume 2
Cylinder No. 4 has the largest area 32
Do you want to continue?? (y for Yes and n for No): n

Page 2
CHS – Spring 2016 Faculty of Engineering
Computers For Engineers Cairo University
(GENN004) Page 3 of 3

Lab 11 – Practice III

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

You might also like