Sweepstakes

The file sweeps.cpp, is a program to print information about a sweepstake winner.

Modifications

  1. In the Sweeps function, add two more string parameters, one called first to represent a first name and one called last to represent a last name. Replace the word "Amanda" everywhere with the first name parameter, and the word "Harris" everywhere with the last name parameter.

    In the main function, change the call to Sweeps to include two more parameters, your first and last name, and change the city to be the city you are from.

    Compile and run the program. The output should be the same as before, except with your name and city.

     

  2. In the main function after the call to Sweeps, print a blank line, and then add a second call to Sweeps with your partners first and last name, and city they are from.

    Compile and run the program.

     

  3. In the main function, modify one of the calls to Sweeps to have just one argument, the name. Do not modify the function Sweeps (which has 3 parameters). Compile the program and observe the error message. You called a function with the wrong number of arguments. Then fix the program back the way it was.

     

  4. In the main function, modify one of the calls to Sweeps to have three arguments that are not in the right order. Send the city in place of the first name, and the first name in place of the city. Send the last name in the right place. Compile the program and discuss what happens. Why is there no error message? What happens when you run the program? Fix the program back the way it was. Compile and run just to make sure it is now correct.

     

  5. At the top of the main function body, declare a string variable called fname.
         string fname;

    Then immediately before the first call to Sweeps, (using a cout statement) ask the user to type in their first name (must be one word). Read in their first name with a cin statement and store the value in the variable fname . Then send this value to the Sweeps function.

    Compile and run your program. You will have to type in a name when it is run. The name must be one word (no blanks).

     

  6. Add two more additional string variables to main, one for the last name and one for the city. Add a cout statement to ask for the users last name, a cin statement to read in this value, a cout statement to ask for the city, and a cin statement to read in this value.

    Modify the call to the Sweeps function to include these two new values entered by the user. Compile and run your program. The program should ask you to type in three words.

     

  7. Modify the main function once more to ask for the users first name, last name and city again, right before the second call to Sweeps. Then modify the second call to use these values.

    Note: You do not need to declare anymore variables for this part. Just reuse the same ones from last time (such as fname).

    Compile and run your program. This time it should ask you for three words, print the resulting sweepstake output using that info, then ask you for three more words, and print the resulting sweepstake output using that info.

Part 2: More Functions and Parameters

In this part we will make the sweeps program more modular.

 

  1. Change the body of sweeps to the following (save the old body somewhere temporarily, you will need it).
    announce(first, last);
    ticket(first);
    prize(prize, town);
  2. Create a function called announce to print the first line of the output.
  3. Create a function called ticket to print the second and third lines of the output.
  4. Create a function called prize to print the fourth and fifth lines of the output.
  5. Compile and run the program.