Assignment 5 

Due Thursday, October 13 at 3:20pm on Catalyst


Assignment 5.1: Buying cookies (10 pts)

  • Open up CodeBlocks.
  • Create a new file called cookies.cpp
  • Add a block comment at the start of your program with your name and section information:
/*
* Jennifer Parrish
* M/W 9:30-11:20am
*/

  • Include the proper library and namespace
  • You just opened up a cookie shop : "Cookie Magic"
  • You want to create an online order form for customers to purchase cookies.
  • Write a program to collect a customer's order and then print the summary of their order to the screen.
  • Write four variables - 1 for each type of cookie
    • chocolate chip
    • chocolate mint
    • peanut butter
    • oatmeal raisin
  • Name each of your variables according to correct naming conventions
  • Write a cout statement welcoming the user to your store "Cookie Magic"
  • Write four cout statements asking them how much of each type of cookie they would like to buy
  • Each cout statement needs to be followed by a cin statement to collect the information about how many cookies to order. (four cin statements)
  • Finally, write a cout statement to print a summary of the customer's order to the screen.
  • Save your file as cookies.cpp and upload it to Catalyst.
  • Your output should look identical the following (except the user input will vary).
  • Notice the blank lines. These are important, so don't forget to include them!

Welcome to Cookie Magic, where every bite of cookie is magical!
Allow me to assist you with your order.

Please enter the number of chocolate chip cookies you would like to purchase: 3
Please enter the number of chocolate mint cookies you would like to purchase: 5
Please enter the number of peanut butter cookies you would like to purchase: 9
Please enter the number of oatmeal raisin cookies you would like to purchase: 0

You ordered the following:
3 chocolate chip cookies
5 chocolate mint cookies
9 peanut butter cookies
0 oatmeal raisin cookies


Assignment 5.2: Collecting Student Data (10 pts)

  • The goal of this program is to collect student data and print it to the screen.
  • The program should first print out the message "Collecting Student Data!" and then move down two lines.
  • Your program should prompt the user for the first letter of their last name.
  • It should then ask for the student ID number of the user.
  • It should ask the user how many years they have attended De Anza.
  • Notice how the user input and the prompt are on THE SAME LINE.
  • Finally, the program should print another blank line and then print the student information to the screen.
  • Think carefully about what type of variables you will use to store each piece of information.
  • Please include your name and section information in a block comment at the start of your program.
  • Save your file as student.cpp and upload it to Catalyst.
  • Your program output should look identical to the following (except for the user input which will vary):


Collecting Student Data!

Please enter the first letter of your last name: P
Please enter your student ID number: 100066
Please enter the number of years you have attended De Anza: 2.5

P is the first initial of your last name.
Your student ID number is 100066.
You have attended De Anza for 2.5 years.

Assignment 5.3: Body Mass Index Calculator (10 pts)
  • Remember our body mass index algorithm?
  • Let's write a program to implement out algorithm.
  • Open up CodeBlocks and create a new file called bmi.cpp
  • Add a block comment at the start of your program with your name and section information:
/*
* Name
* Section Information
*/

  • Include both libraries that we have used so far: iostream and cmath
  • Declare three variables at the top of the main function.
    • weight 
    • height
    • bmi
  • What are their data types?
  • Create a cout statement welcoming the user to your program and explaining its purpose.
  • Now, prompt the user to enter their weight. Specify that their weight needs to be in pounds.
Please enter your weight in pounds:
  • Following your prompt, write a cin statement to take in the data entered by the user and store it as the weight variable.
  • Now prompt the user to enter their height in inches.
Please enter your height in inches: 
  • Create a cin statement to take in the data entered by the user and store it as the height variable.
  • Next, calculate the Body Mass Index using the following formula and store your result as the variable bmi.


  • Make sure to use the pow() function from the cmath library to square the user height.
  • Finally, create a cout statement to share the results with the user.
Your BMI is: X.X
  • If there are no errors, submit your bmi.cpp program to Catalyst.

The Output of Your Program Should Be Identical to the Output Below (Except the User Input Will Vary):