D2_espeidel03

pdf

School

Virginia Tech *

*We aren’t endorsed by this school

Course

1215

Subject

Computer Science

Date

Jun 21, 2024

Type

pdf

Pages

4

Uploaded by ProfessorGoldfinchMaster21

Report
Problem 1 User Input finalWaterLevel = input( 'Enter the final water level height (in cm): ' ); massOfCrown = input( 'Enter the mass of the crown (in g): ' ); Calculate the volume of water displaced (in cm^3) radiusOfBucket = 10; % cm originalWaterLevel = 30; % cm crossSectionalArea = pi * radiusOfBucket^2; % cm^2 volumeDisplaced = crossSectionalArea * (finalWaterLevel - originalWaterLevel); % cm^3 Calculate the density of the crown (in g/cm^3) densityOfCrown = massOfCrown / volumeDisplaced; Define the density of pure gold (in g/cm^3) densityOfGold = 19.320; % g/cm^3 Calculate the difference between the densities densityDifference = densityOfCrown - densityOfGold; Display the results with units and descriptions fprintf( 'Final water level height: %.4f cm\n' , finalWaterLevel); Final water level height: 30.1648 cm fprintf( 'Mass of the crown: %.0f g\n' , massOfCrown); Mass of the crown: 1000 g fprintf( 'Density difference with pure gold: %.4f g/cm^3\n' , densityDifference); Density difference with pure gold: -0.0051 g/cm^3 Problem 2 User Input numSides = input( 'Enter the number of sides of the polygon forming the tabletop: ' ); 1
sideLength = input( 'Enter the side length of the polygon forming the tabletop (in inches): ' ); Calculate the area of the regular polygon tabletop (excluding the center) % Formula for the area of a regular polygon: (n * s^2) / (4 * tan(pi / n)) tabletopArea = (numSides * sideLength^2) / (4 * tan(pi / numSides)); Calculate the surface area of the stem (cylinder) stemDiameter = 3.5; % inches stemHeight = 27; % inches stemSurfaceArea = 2 * pi * (stemDiameter / 2) * stemHeight; Calculate the surface area of the base (cylinder) baseDiameter = 36; % inches baseHeight = 2; % inches baseSurfaceArea = 2 * pi * (baseDiameter / 2) * baseHeight; Calculate the total exposed surface area that needs to be painted totalSurfaceAreaToPaint = tabletopArea + stemSurfaceArea + baseSurfaceArea; Display the results with units and descriptions fprintf( 'Number of sides of the tabletop polygon: %d\n' , numSides); Number of sides of the tabletop polygon: 6 fprintf( 'Side length of the tabletop polygon: %.2f inches\n' , sideLength); Side length of the tabletop polygon: 50.00 inches fprintf( 'Amount of surface area to be painted: %.2f square inches\n' , totalSurfaceAreaToPaint); Amount of surface area to be painted: 7018.27 square inches Problem 3 User Input 2
baseVector = input( 'Enter the base vector (5 elements, money spent without tax for each person): ' ); tipPercentVector = input( 'Enter the tip percentage vector (5 elements, in percentage, for each person): ' ); Calculate the tip vector (tip amount for each person) tipVector = (tipPercentVector / 100) .* baseVector; Define the tax rate taxRate = 0.10; % 10% Calculate the tax vector (tax amount for each person) taxVector = taxRate * baseVector; Calculate the final amount vector (total amount each person owes) finalAmountVector = baseVector + tipVector + taxVector; Display the results with units and descriptions fprintf( 'Base Vector (Money spent without tax):\n' ); Base Vector (Money spent without tax): disp(baseVector); 5 10 15 20 25 fprintf( 'Tip Percentage Vector (in percentage):\n' ); Tip Percentage Vector (in percentage): disp(tipPercentVector); 15 25 30 10 20 fprintf( 'Tip Vector (Tip amount for each person):\n' ); Tip Vector (Tip amount for each person): disp(tipVector); 0.7500 2.5000 4.5000 2.0000 5.0000 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
fprintf( 'Tax Vector (Tax amount for each person):\n' ); Tax Vector (Tax amount for each person): disp(taxVector); 0.5000 1.0000 1.5000 2.0000 2.5000 fprintf( 'Final Amount Vector (Total amount each person owes):\n' ); Final Amount Vector (Total amount each person owes): disp(finalAmountVector); 6.2500 13.5000 21.0000 24.0000 32.5000 4