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

Matlab

This document contains the answers and code for three programming exercises: 1. An area and volume calculation script that takes length, width, and depth as input and outputs perimeter, volume, and underground surface area. 2. A fruits price calculation script that takes the number of different fruits purchased and total costs paid as input to calculate the individual prices of bananas, apples, and cantaloupe. 3. A temperature conversion script that takes a temperature in Celsius as input and outputs the equivalent in Fahrenheit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views3 pages

Matlab

This document contains the answers and code for three programming exercises: 1. An area and volume calculation script that takes length, width, and depth as input and outputs perimeter, volume, and underground surface area. 2. A fruits price calculation script that takes the number of different fruits purchased and total costs paid as input to calculate the individual prices of bananas, apples, and cantaloupe. 3. A temperature conversion script that takes a temperature in Celsius as input and outputs the equivalent in Fahrenheit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy