Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab 3 Instructions Drill: Write a letter

Similar presentations


Presentation on theme: "Lab 3 Instructions Drill: Write a letter"— Presentation transcript:

1 Lab 3 Instructions Drill: Write a letter
If you have a text book, you can go to drill at pp at the end of chapter 3, Or you can read following slides of the drill instructions. You can use g++ on build server, visual studio on local machine or your preferred C++ IDE. Important Note: For your grade, please show me the result after you finish all the tasks. When you finish, you can think about to separate prompt and letter output or help others.

2 Drill After each step of this drill, run your program to make sure it is really doing what you expect it to. Keep a list of what mistakes you make so that you can try to avoid those in the future. 1. This drill is to write a program that produces a simple form letter based on user input. Begin by typing the code from Section 3.1 prompting a user to enter his or her first name and writing “Hello, first_name” where first_name is the name entered by user.

3 Drill Then modify your code as follows: change the prompt to “Enter the name of the person your want to write to” and change the output to “Dear first_name,” Don’t forget the comma. Code Snippet in Section 3.1 //read and write a first name #include "std_lib_facilities_4.h"   int main(){ cout << “Please enter your first name (followed by ‘enter’):\n”; String first_name; cin >> first_name; cout << “Hello, ” << first_name <<“!\n”; }

4 Drill 2. Add an introductory line or two, like “How are you? I am fine. I miss you.” Be sure to indent the first line. Add a few more lines of your choosing – it’s your letter. 3. Now prompt the user for the name of another friend, and store it in friend_name. Add a line to your letter: “Have you seen friend_name lately?”

5 Drill 4. Declare a char variable called friend_sex and initialize its value to 0. Prompt the user to enter an m if the friend is male and an f if the fiend is female. Assign the value entered to the variable friend_sex. Then use two if-statements to write the following: If the friend is male, write “If you see friend_name please ask him to call me.” If the friend is female, write “If you see friend_name please ask her to call me.”

6 Drill 5. Prompt the user to enter the age of the recipient and assign it to an int variable age. Have your program write “I hear you just had a birthday and your are age years old.” if age is 0 or less or 110 or more, call simple_error(“your’re kidding!”) using simple_error() from std_lib_facilities_4.h.

7 Drill 6. Add this to your letter:
If your friend is under 12, write “Next year you will be age+1.” If your friend is 17, write “Next year you will be able to vote.” If your friend is over 70, write “I hope you are enjoying retirement.” Check your program to make sure it responds appropriately to each kind of value. 7. Add “Yours sincerely,” followed by two blank lines for a signature, followed by your name.

8 Example Result


Download ppt "Lab 3 Instructions Drill: Write a letter"

Similar presentations


Ads by Google