Assignment 10

Due Wednesday, February 14 at 9:20am on Canvas



Assignment 10.1: Buying More Pastries (10 pts)

Image of a bakery display case
Open your pastries.cpp from Assignment 5.

Let's alter it to also print a receipt at the bottom of the order.

Each pastry will also now need a price displayed to the user.

Assume each pastry is priced according to the following table:

 Pastry Price
 Eclair $4.50
 Bear Claw
 $3.95
 Croissant $2.95
 Cupcakes $3.50


  • Your program should also print out a subtotal for each type of pastry purchased, as well as the final total at the end.
  • Note that each price must be displayed to exactly two decimal places.
  • Below is an example run of the program (note that user input will vary):


  • When your program works identically to the example above, please upload it to Canvas.

Assignment 10.2: Weight in Space (10 pts)

  • Remember our class activity where we calculated a user's weight on the moon?
  • Let's see if we can expand it to provide more options for the user.
  • Instead, we will calculate how the user's weight changes on different planets.
  • Open Eclipse and create a project called Planet with a file name planet.cpp.
  • Your program should prompt the user to enter his or her weight, as well as the name of a planet.
  • Note that the user should be allowed to enter both lower and upper case names of planets.
  • Next, you will need a series of if-else if-else statements, like the following:
if (//test for planet name) {
    weight = weight * MERCURY_MULT;
} else if (//test for a second planet name) {
    //statement goes here
}
//rest of else ifs go here
} else {
    //ERROR CHECKING!   
}

  • To calculate the user's weight on the planet of his or her choice, you will need to know the conversion rate for each of the planets. The conversion is as follows:
Image depicting the planets in our solar system relative to the sun
 PlanetMultiplier
 Mercury 0.38
 Venus 0.91
 Mars 0.38
 Jupiter 2.54
 Saturn 1.08
 Uranus 0.91
 Neptune 1.19
 Pluto 0.06

  • Note that to avoid magic numbers, you will need to declare a const variable for each of the multipliers aboveYour const variables should look like this:
const double MERCURY_MULT = 0.38;
  • At the end of the program, you should display the message "You weigh X.X pounds on <Insert Planet Name Here>." (See sample output below)
  • Important: The output for the weight should only have one number after the decimal point.
  • Finally, take a moment to make sure your indentation is correct. Your indentation should look like the following

#include <iostream>
#include <iomanip>
using namespace std;

int main() {
     if (test condition) {
         //statements

     } else if {
         //statements

     } else if {
         //statements

     } else {
         //statements

     }
}
  • Your program should work identically to the following (except user input may vary):
Welcome!
What do you weigh on other planets?
Enter your weight in pounds: 123
Now, select from one of the following planets:
    Mercury
    Venus
    Mars
    Jupiter
    Saturn
    Uranus
    Neptune
    Pluto
Please enter the planet: mercury
You weigh 46.7 lbs on Mercury
  • Another example (upper case planet name input):
Welcome!
What do you weigh on other planets?
Enter your weight in pounds: 189
Now, select from one of the following planets:
    Mercury
    Venus
    Mars
    Jupiter
    Saturn
    Uranus
    Neptune
    Pluto
Please enter the planet: Neptune
You weigh 224.9 lbs on Neptune
  • Alternately, your program should output the following if the user provides an invalid entry:

Welcome!
What do you weigh on other planets?
Enter your weight in pounds: 147
Now, select from one of the following planets:
    Mercury
    Venus
    Mars
    Jupiter
    Saturn
    Uranus
    Neptune
    Pluto
Please enter the planet: Marz
You entered an invalid planet name.
Please rerun the program to try again.