Assignment 6

Due Tuesday, May 1 at 9:20am on Canvas


Assignment 6.2: Suggesting Blog Titles (10 pts)

  • A blog is a website for commentary, discussion or information that is more or less regularly updated. To attract attention, blog entries often have sensational or provocative headlines.
  • For this assignment, we will write a program to produce suggested blog titles on a topic selected by the user.
  • The name of the source code file for this program must be blogtitles.java and all your code must be in this file.
  • Write a program that produces the following five (5) blog titles based on user input of a topic and number:
    • [number] Secrets That Experts Of [topic] Want You To Know!
    • [number] Reasons [topic] Will Change The Way You Think About Everything!
    • You Will Never Believe This Awesome Truth Behind [topic]
    • Here's What No One Tells You About [topic]
    • [number] Ways [topic] Can Help You Live To 100!
  • Ask the user for the following inputs (and no other input) in this order, as shown in the Sample Output below:
    1. Single word topic
    2. Integer number between 3 and 20
  • The words [topic] and [number] (shown in square brackets above for emphasis) must be replaced by the user input.
  • Sample Output: The input prompts and outputs of the program must look like the following for full credit, including the same order of input and wording of the output. For the input shown you must get the same output. However, the output must change correctly if the inputs are different.
    Enter a single-word topic: Java
    Enter an integer number between 3 and 20: 10
    
    Suggested blog titles:
    10 Secrets That Experts Of Java Want You To Know!
    10 Reasons Java Will Change The Way You Think About Everything!
    You Will Never Believe This Awesome Truth Behind Java
    Here's What No One Tells You About Java
    10 Ways Java Can Help You Live To 100!
    

    In the above invocation of the program, the user entered "Java" (without the quotes) as the topic and "10" (without the quotes) as the number.

  • Note the the user should be able to enter any topic of their choice and any number of their choice and the program should adapt the output accordingly.
  • Hint: You will need to use the Scanner class and create a new Scanner to read user input in your program
  • You may add additional blog title suggestions after the above 5, but must print the above 5 blog titles at a minimum.

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 C++ project in Eclipse called Math with a file named 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
    • Calculate the natural log of the number (hint: use the log function)
  • Your program should give output as shown below.
  • When you are finished, upload your math.cpp file to Canvas.
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
The natural log of 2.5 is: 0.916291


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. A man's name
    2. A woman's name
    3. An adjective
    4. A second adjective
    5. A color
    6. A noun
    7. An animal
    8. A body part
    9. A holiday


  • After the strings are entered, substitute the strings into the following story and output the story to the console:

    The Haunted Tower

    One afternoon <man name> and <woman name> were walking down a(n) <adjective1> trail, looking for kindling for their campfire. The trees were <adjective2> and <color>, and there were colorful wildflowers all around. <man name> and <woman name> began to pick the wildflowers, and after a while, they went so far that they had wandered away from the trail.

    It started to get dark. <man name> began to get worried, but <woman name> seemed excited to have an adventure. 'Look!' <woman name> said. 'Do you see that tower? It looks like a <noun>!'

    'We're saved!' cried <man name>, who was relieved.

    Once they got closer, <man name> felt very uneasy again. It didn't look like the cozy little cottage <man name> had been imagining, but rather a big, spooky tower! It was about 14 feet tall, and it was covered with green ivy and moss. It was the creepiest thing <man name> had ever seen!

    <man name> said, '<woman name>, let's keep walking! There's no way I'm going into that tower! It looks haunted!'

    'Don't be such a(n) <animal>! We're going in. I think it looks safe to me!' said <woman name>.

    <man name> was so scared. He felt his <body part> chatter as <woman name> opened the door. All of a sudden, <man name> felt that he was not alone. He opened his eyes, prepared to see the worst. But instead, he saw all his friends and family inside the haunted tower! 'Surprise! Happy <holiday>, <man name>!' they all cried.

    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, and spacing
  • Note: Please use the single quote around the lines of dialogue (as shown above) rather than the double quote.
  • Also be careful not to change the formatting of the above story in any way! You will want to preserve the original spacing and punctuation.
  • Upload your file to Canvas when you are finished.
  • Your output should look identical to the following, except user input will vary:


Welcome to Madlibs!

Enter a man's name: Larry
Enter a woman's name: Noreen
Enter an adjective: funny
Enter another adjective: amazing
Enter a color: red
Enter a noun: book
Enter an animal: duck
Enter a body part: leg
Enter a holiday: Valentine's

The Haunted Tower

One afternoon Larry and Noreen were walking down a(n) funny trail, looking for kindling for their campfire. The trees were amazing and red, and there were colorful wildflowers all around. Larry and Noreen began to pick the wildflowers, and after a while, they went so far that they had wandered away from the trail.

It started to get dark. Larry began to get worried, but Noreen seemed excited to have an adventure. 'Look!' Noreen said. 'Do you see that tower? It looks like a book!'

'We're saved!' cried Larry, who was relieved.

Once they got closer, Larry felt very uneasy again. It didn't look like the cozy little cottage Larry had been imagining, but rather a big, spooky tower! It was about 14 feet tall, and it was covered with green ivy and moss. It was the creepiest thing Larry had ever seen!

Larry said, 'Noreen, let's keep walking! There's no way I'm going into that tower! It looks haunted!'

'Don't be such a(n) duck! We're going in. I think it looks safe to me!' said Noreen.

Larry was so scared. He felt his leg chatter as Noreen opened the door. All of a sudden, Larry felt that he was not alone. He opened his eyes, prepared to see the worst. But instead, he saw all his friends and family inside the haunted tower! 'Surprise! Happy Valentine's, Larry!' they all cried.