Assignment 7
Due Thursday, October 20 at 3:20pm

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)
                + motherName.substr(???, ???) + fatherName.substr(???, ???);

  • 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 Catalyst.

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: Is This a Leap Year? (10 pts)
  • Let's write a program to determine whether a year is a leap year or not.
  • What is a leap year
  • How can we determine whether the current year is a Leap Year?
  • We need to use the modulus operator (%).
  • If the year is divisible by 4, then it is a leap year.
  • Open up a new C++ file in CodeBlocks and name it leapyear.cpp
  • Declare a variable name year at the top of your program. What data type do you need?
  • Declare another variable named remainder to store the result of the modulus operation. What data type will you need?
  • Next, write a cout statement to welcome the user to your program and let them know that you will be calculating whether the year they entered is a leap year.
  • Write a prompt to the user, asking them for the year.
  • Store the user input as the year variable.
  • Now, you need to determine whether the year is evenly divisible by 4. Perform this operation by using modulus and store the result as the remainder variable.
  • Finally, write an if-else statement to output whether or not the year entered by the user is a leap year or not. 
  • When you are finished, upload to Catalyst.
  • Your program output should look identical to the following:



Alternately:



Assignment 7.3: 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 Catalyst.