Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

CS10-8L: Computer Programming Laboratory

Exercise #3: Variables, Scripts and Visualizations

Name: TORRES, Yhancie Mae R. Score:

Section: A4 Date: 06/20/20

ANSWERS
1.
a. area.m
Perimeter: 80 ft
Volume: 2062.5 ft3
Underground Surface Area: 815 ft2

Script:
length=input('Enter length= ');
width=input('Enter width= ');
average_depth=input('Enter average depth= ');
Perimeter=2*(length+width)
Volume=length*width*average_depth
Underground_surface_area=2*(length+width)*average_depth+le
ngth*width
Command:
>> area
Enter length= 25
Enter width= 15
Enter average depth= 5.5

Perimeter =

80

Volume =

2.0625e+03

Underground_surface_area =

815

b. fruits.m
Cost of Banana: $0.05
Cost of Apple: $0.29
Cost of Cantaloupe: $0.89

Script:
lna=input('Number of apples Liz bought= ');
lnb=input('Number of bananas Liz bought= ');
lnc=input('Number of cantaloupes Liz bought= ');

Prepared by: Engr. Cheryl Mari M. Isip


Prepared date: March 2019
CS10-8L: Computer Programming Laboratory
Exercise #3: Variables, Scripts and Visualizations

ltc=input('Total cost that Liz paid= ');


bna=input('Number of apples Bob bought= ');
bnb=input('Number of bananas Bob bought= ');
bnc=input('Number of cantaloupes Bob bought= ');
btc=input('Total cost that Bob paid= ');
cna=input('Number of apples Carol bought= ');
cnb=input('Number of bananas Carol bought= ');
cnc=input('Number of cantaloupes Carol bought= ');
ctc=input('Total cost that Carol paid= ');
a=[lna lnb lnc;bna bnb bnc;cna cnb cnc];
b=[ltc;btc;ctc];
ans=a\b;
Cost_of_Banana=ans(2)
Cost_of_Apple=ans(1)
Cost_of_Cantaloupe=ans(3)
Command:
>> fruits
Number of apples Liz bought= 3
Number of bananas Liz bought= 12
Number of cantaloupes Liz bought= 1
Total cost that Liz paid= 2.36
Number of apples Bob bought= 12
Number of bananas Bob bought= 0
Number of cantaloupes Bob bought= 2
Total cost that Bob paid= 5.26
Number of apples Carol bought= 0
Number of bananas Carol bought= 2
Number of cantaloupes Carol bought= 3
Total cost that Carol paid= 2.77

Cost_of_Banana =

0.0500

Cost_of_Apple =

0.2900

Cost_of_Cantaloupe =

0.8900

c. temperature.m

Prepared by: Engr. Cheryl Mari M. Isip


Prepared date: March 2019
CS10-8L: Computer Programming Laboratory
Exercise #3: Variables, Scripts and Visualizations

Temperature in Fahrenheit: 98.6°F

Script:
Temperature_in_Celsius=input('Enter temperature in
Celsius= ');
Temperature_in_Fahrenheit=Temperature_in_Celsius*(9/5)+32
Command:
>> temperature
Enter temperature in Celsius= 37

Temperature_in_Fahrenheit =

98.6000

Prepared by: Engr. Cheryl Mari M. Isip


Prepared date: March 2019

You might also like