Part 2 of C++ Workshop

(Draft Still Under Construction)

PROGRAM. Hello You! – A personalized program

Objective. To learn about input variables and data types. And a tiny bit of arithmetic.

What to do. Write a program that (1) asks the user for his/her name (no spaces) and age (2) Outputs a personalized message to the user. For example, say the user’s name is Dave. Your console window will look something like this (user responses are underlined):

What is your name? Dave

Hello, Dave! Glad to meet you!

How old are you? 20

That’s funny, you don’t look a day older than 19.

Bye!

What you will need. In addition to the headers you have already used, you will probably need

#include <string>

so that you can learn about declaring Name as a string variable. Your program should use at least two variables: Name, a string object, and Age, an int (integer) object.

Digression – Let’s learn about input, output and arithmetic

PROGRAM. The Four Fours - A Brainteaser

Objective. To learn about simple arithmetic operations and output.

Four fours is a mathematical puzzle. The goal of four fours is to find the simplest mathematical expression for every whole number from 0 to some maximum, using only common mathematical symbols and the digit four (no other digit is allowed).

For example the number 7 may be computed as 4+ sqrt (4) + (4/4)

What to do. Write a C++ program that outputs expressions for all the digits from 1 to 50 (or as many as you can do). Notice we’re not using our programs to compute the FourFours expression, just to output it to the console window.

What you will need. In addition to the headers you have already used, you will probably need

#include <math>

in order to be able to use some mathematical functions, like the sqrt() function above.

Source: Wikipedia

PROGRAM. Mad Libs

Objective. To learn about input and output and variables

What to do. Create a program to output a wacky Mad Libs story based on user input, like the one below. You've already played this sort of game offline. Free to use your own imagination and creativity. Oh, and you’ll need the <string> header file again for your variables.

PROGRAM. Personalized Text Adventure

Objective. To learn about input, output, and data (variables and types)

What to do. Write a C++ program that personalizes the following adventure tale. Have the program request the personalized input information from the user. Required user inputs are in red in the example below:

A brave group of number adventurers set out on a quest in search of the lost treasure of the Ancient Folks. The group was led by that legendary rogue, leader. Along the way, a band of marauding ogres ambushed the party. All fought bravely under the command of leader, and the ogres were defeated, but at a cost. Of the adventurers, killed were vanquished, leaving just survivors in the group. The party was about to give up all hope. But while laying the deceased to rest, they stumbled upon the buried fortune. So the adventurers split GOLD_PIECES gold pieces. [Optional: leader held on to the extra XX pieces to keep things fair, of course.]

Source: M. Dawson, Beginning C++ Through Game Programming

PROGRAM. Personalized Text Adventure – The Sequel!

Objective. To learn about input, output, and data (variables and types)

What to do. Write a C++ program just like the above, but this time make up your own adventure story! Be creative! Be crazy!

PROGRAM. Compute your GPA

Objective. To learn about input and computing

What to do. Write a program that computes the user’s GPA based on grades and credit values input during the run. For example,