For Review

See pages 44-51 for review on functions

See pages 86-98 for review on calculations with numbers

Strings

You have been introduced to the variable types int (integers) and float (floating point or decimal numbers). There are variations on these types which you will see later. These types, however, all store numbers. If you want to store characters (letters, words etc.) you must use the type char. This type is capable of storing one character (letter, number, punctuation). For example, your program can contain lines like:

char lettergrade;

lettergrade="a";

If you want to store more than one letter in a given variable (for example your name) you must use an array of characters. For now, you can think of an array of characters as a bunch of characters strung together that can be addressed with one common name. The only difference between the variable holding a single letter versus several letters is that when you declare the variable you must tell the computer how many letters is the maximum that will be stored in the variable. For example if I wanted to declare a variable called name that could hold up to 25 letters I would do it as follows:

char name[25];

I could then use this to store a name and print it out as shown here:

cout<<"Enter your name: ";

cin>>name;

cout<<"Hello "<<name;

The book uses a type called "string" for this same purpose that we will not use just yet. String is not built into C++, and is simply a shorthand way of doing what I have outline here.

Assignment 1

Your first assignment is to write a program that is a birthday party planner. This program will need to calculate the amount of supplies needed for the party based on the following information.

  1. You will need one bottle of soda for every 4 people. Each bottle costs 99 cents.
  2. You will need 12 square inches of cake for each person. Cakes are always 9 inches wide. Cakes cost 10 dollars per square foot.
  3. You will need 30 square inches of pizza for each person. You should let the planner choose the radius of the pizza pies. Pizza costs 5 dollars per square foot.

Click Here for HintsBS00047A.gif (1937 bytes)

Click Here to Download a DOS Version of the Program comptr9.gif (546 bytes)

You will ask the user for the number of people attending the party. Based on this it will need to calculate the number of sodas, the number of pizzas, the size of the cake, and the cost per person. You should use floating point numbers when making calculations and print out fractional amounts of pizza ,cake and bottles of soda if necessary (i.e. it is ok to tell the person to purchase 1.8 pizzas, and a cake that is 15.4 inches long).

Finally, you will need to enter the names of three people and assign them the roles of purchasing these three items (by printing their names and items out). You should tell them how much money they will need to bring for their items based on the previous calculations.

This program should have comments on almost every line explaining what the program is doing. Additionally, while you may write the program in pairs, each person must explain in their own words how this program works. This explanation should be at least a couple of paragraphs.

This program will be graded on the following factors:

  1. How well it works.
  2. How well you used functions. The "main" function should do nothing but call other functions, and each other function should have a simple task (e.g. calculating the cost of soda or printing out things that need to be brought).
  3. How easy your program is to follow. This will included things like comments and variables that have meaningful names.
  4. How well you understand your program based on the explanation that you write.
  5. How creative your were in your approach to solving the problem.

This assignment will be due Friday. Instructions on how to get me a copy of the program will follow.

Back to Home Page House3.wmf (25540 bytes)