Assignment 7
Due Thursday, May 3 at 9:20am on Canvas

Assignment 7.1: What's Your Dragon Name (10pts)

Green Dragon v2 by sandara

image source

  • Create a new C++ file called dragon.cpp
  • The purpose of this program will be to give the user a "dragon name."
  • A person's dragon name can be generated using the following algorithm:
The first two letters of your last name
+ last two letters of your first name
+ the first two letters of your mother's name
+ the last letter of your father's name
  • At the top your program, declare 5 string variables:
string firstName;
//declare a string variable for the last name called lastName
string motherName;
//declare a string variable for the father's name called fatherName
string dragonName;
  • Let's greet the user by printing the following message to the console:

cout << "Want to learn your \"dragon name?\"\n";

  • Note the use of the escape sequence above to allow the " to display as part of the message.
  • Next, prompt the user for this information
Please enter your first and last name:
  • Let's follow the prompt with two cin statements. One to input the first name and one to input the last name.
  • Alternately, you could write the above with a single cin statement that stores the input in the two separate firstName and lastName variables.
  • Next, prompt the user for his or her mother's name, read the name in using a cin statement, and store the input as the motherName variable:

Please enter your mother's first name:

  • Follow the same pattern for the father's name.

Please enter your father's first name:

  • Finally, you will want to calculate the user's dragon name and display it to the user using the above formula:
dragonName = lastName.substr(0, 2) + firstName.substr(firstName.length()-2, 2)
                + <You fill in the rest>;
  • Hint: You will need to use the string length() function to find the index of the last letter of the father's name.
    • Will you need fatherName.length() or fatherName.length() - 1 as the starting index?
  • Finally: Display the result to the user with the following output:

Your "dragon name" is: "<dragon name>"

  • Note the use of the " above. How can you get them to display when you print this message to the console?
  • When you are finished, submit your dragon.cpp program to Canvas.

The output of your program should look like this (except user input will vary):

Want to learn your "dragon name?"
Please enter your first and last name: Jennifer Parrish
Please enter your mother's first name: Cassandra
Please enter your father's first name: Stewart
    Your "dragon name" is: "PaerCat"

Assignment 7.2: The Longest Word (10 pts)
  • According to the Oxford English Dictionary, the longest word in the English language is pseudopseudohypoparathyroidism
  • We are going to write a program that prints out some statistics about this word.
  • Open up a new C++ file called longestWord.cpp
  • Then store pseudopseudohypoparathyroidism as a string variable called longest_word.
  • Write a program to print out the length of longest_word with a message like:
The length of pseudopseudohypoparathyroidism is <number of letters> letters.
  • Note that you should use the length() function here.
  • Next, using the substr(index, numChars) function, print out at least 4 words you find contained inside of the pseudopseudohypoparathyroidism
  • For example, you could write a cout statement like this:

    cout << longest_word.substr(20,7) << endl; //should print the word thyroid to the console

  • Add at least 3 statements like the one above that each print a different word contained within the longest word.
  • When you are finished, upload longestWord.cpp to Canvas