Assignment 6

Due Tuesday, October 18 at 3:20pm on Catalyst


Assignment 6.1: Calculator Part 2 (10 pts)

  • We are going to create a calculator program using the math functions from the cmath library.
  • Open a new file in CodeBlocks and save it as math.cpp
  • You should prompt the user to input a number.
  • Your calculator is going to perform the following operations on that number:
    • Raise the number to the power of 2, 3, and 4 (square, cube, quartic)
    • Calculate the floor of the number
    • Calculate the ceiling of the number
    • Calculate the square root of the number
  • Your program should give output as shown below.
  • When you are finished, upload your math.cpp file to Catalyst.
Your output should look identical to the following (except user input will vary):

Enter a number: 2.5
The square of 2.5 is: 6.25
The cube of 2.5 is: 15.625
The quartic (fourth power) of 2.5 is: 39.0625
The ceiling of 2.5 is: 3
The floor of 2.5 is: 2
The square root of 2.5 is: 1.58114


Assignment 6.2: Madlibs (10 pts)

  • Write a program that plays the game of Mad Libs.
  • Your program must prompt the user to enter the following information as strings in this order:
    1. Your first name
    2. Your instructor's last name
    3. A food
    4. A number between 100 and 120
    5. An adjective
    6. A color
    7. An animal
  • After the strings are entered, substitute the strings into the following story and output the story to the console:

    Dear Instructor [Instructor Name] :

    I am sorry that I am unable to turn in my homework today. First I ate a rotten [food], which made me turn [color] and very sick. I came down with a fever of [number]. Next, my [adjective] pet [animal] must have smelled the remains of the [food] on my homework, because my pet ate my homework. 

    I knew I should not have ordered that [animal] on eBay! 

    I know you do not accept late homework but I am hoping you will make an exception in my case. 

    Sincerely, 
    [Your name]

    Note that you will need to decide where to insert newline characters into the output to make the text look like the above output.

  • The name of your file must be madlibs.cpp and your code must be in this file.

    Be careful of the spelling, including capitalization, as you will lose points for a misspelled name.

  • Also be careful not to change the formatting of the above letter in any way! You will want to preserve the original spacing and punctuation.
  • Upload your file to Catalyst when you are finished.
  • Your output should look identical to the following, except user input will vary:


Welcome to Madlibs!

Please enter your first name: Jennifer
Please enter your instructor's last name: Parrish
Please enter a food: broccoli
Please enter a number between 100 and 120: 105
Please enter an adjective: amazing
Please enter a color: red
Please enter an animal: tiger


Dear Instructor Parrish :

I am sorry that I am unable to turn in my homework today. First I ate a rotten broccoli, which made me turn red and very sick. I came down with a fever of 105. Next, my amazing pet tiger must have smelled the remains of the broccoli on my homework, because my pet ate my homework. 

I knew I should not have ordered that tiger on eBay! 

I know you do not accept late homework but I am hoping you will make an exception in my case. 

Sincerely, 
Jennifer