Home
Courses
Web Animation
Web A. Assignments
Web Publishing
Publishing Letter
Web P. Assignments
Cisco Networking
LAN Assignments
WAN Assignments
Intro Programming
Intro P. Assignments
AP Computer
AP. Assignments

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


Introduction to Programming Language

Vocabulary

Chapter 1

Chapter 2

Day 1 (September 5) (C)

* Introduce youself to others
* Syllabus
* Textbook: Start Out with C++,
* Rules of computer use
* Teacher's Expectations
* Set up FirstClass Conference
* Programming Rubric

Assignment 1:Activitie 1:
Write a paragraph about yourself with minimum of 200 words. The content will cover but not limited to the following topics:
1. your first name
2. favorite color, subject, pet
3. the most interesting thing you did during the summer vacation
4. Why do you take this class?
5. What is your background knowledge?
6. What are your expectations?
Choose a partner you don't know very well. Read the paragraph he/she has written. Then introduce your partner to the class.
Activity 2: Study, discuss and modify the rules we are going to use for the semester.

Day 2 (September 9) (C)

Chapter I: Introduction to Computers and Programming
Vocabulary:
hardware, CPU, memory, secondary mamory, input, output, fetch, decode, execute, bit, byte, binary, switch, address, software, single tasking, multitasking, single user, multiuser, computer program, algorithm, logical errors, run-time errors, programming language, source code, source file, compiler, object code, object file, executable code, executable file, programmer-defined identifiers, operators, punctuations, variables, validate, procedural programming and object-oriented programming.
(C) Read from Chapter 1, Pages 1 - 15 and answer the following questions.
Part I
1.Why is the computer used by so many different people and in so many different professions?
2. Why is computer programming both an art and a science?
3. List the five major hardware components of a computer system.
4. Internally, what two units does the CPU consist of ?
5. What is a memory address? What is its purpose?
6. Explain why computers have both main memory and secondary storage.
7. What are the two general categories of software?
8. What is the difference between a single tasking system and a multitasking system?
Part II
1.What is a program?
2.What is an algorithm?
3.What is the difference between a high-level language and a low-level languge?
4.What is source code?
5.What is object code?
6.What is the executable code?
Part III
1.What is a program made of?
2.What are the differences between key words and programmer-defined identifiers?
3. What are the differences between operators and punctuations?
4.What are the differences between lines and statements?
5.What are variables?
Part IV
(C) Program Challenge
1. Create a flowchart for the program.
2. Write a program that displays the following message in three lines:
"I have great fun with C++."
"I wrote my first program with C++."
"The program works."

Assignment #3 (September 11)

(C) Write a program that contains variables, integer literals and string literals.
The program will display the following output:
I have made 160 dollars in the past week. Because I spent 200 dollars, my checking account balance is -40 dollars. What can I do for the rest of the week?
(See example: Program 2-10. Page 18

(C) 1. Write a program that contains integer variable and floating-point variable. Include comments.
The program will display the following output:
Ann earned $105 this week.
Frank earned $200.50 this week.
(See example: Program 2-15, P. 27 eText)

Assignment 4 (September 23)

Review the vocabulary and take a quiz.
(C) Chapter 2
Read from Page 1 to 4.
What does // mean?
What does # mean and why # is important in the programming language?
What does #include directive cause the preprocessor to do?
What is iostream and what does iostream allow a C++ program to do?
What is the iostream file called?
Why does C++ use namespace to do?
What does int main () mean?
Is C++ a case-sensitive language and what does case-sensitive mean?
What do { and }mean?
What is a string literal or string constant?
What does ; do in C++ language?
Take a look at Table 2-1 Special characters.

(C) Page 5 – 13
1. What is a console?
2. What is the cout object referred to?
3. What is symbol of an escape sequence?
4. What is the newline escape sequence?
5. Take a look at Table 2-2 common Escape Sequences on Page 9.
6. What does \t do?
7. What is a variable?
8. What is a literal?
9. What is an identifier?
10 What are legal identifiers?
11. What does char stand for?
12. What data type is char strictly speaking?
13. What are the differences between character literals and string literals?
14. What are floating-point data types used for?
15. What are the three data types that can represent floating-point numbers?
16. What are Boolean variables?

Part II

(C) Write a program that calculates hourly wages, including overtime. Include comments.
Base pay rate: 20.50
Hours worked less overtime: 40.0
Overtime pay rate: 25.50
Overtime hours worked: 15
The program will display the following output:
The total earning this week is $#.
(See example: Program 2-20, P. 35 eText)

(B) 2. Wirte a program to show me the the size of char, short, double, fload.
The result will be:
The size of char is ____bytes.
The size of short is ___ bytes.
The size of double is _____ bytes.
The size of float is ______ bytes.
The candy can be eaten in ____ bytes.
(See example: Program 2-27, P. 30 eText)

Chapter 2 Reading 2

Assignment #5 (September 16)
(C) Quiz. Do Quiz Part I in Moodle.
(C) Quiz Part II.
C) Miles Per Gallon
1 A car holds 12 gallons of gasoline and can travel 350 miles before refueling. Write a program that calculates the number of miles per gallon the car gets. Display the result on the screen.
Hint: Use the following formula to calculate miles-per-gallon (MPG):
MPG = Miles Driven / Gallons of Gas Used

September 30

Chapter 3
(C) Read Page 1 to 7 and answer the following questions.
The cin Object
What is cin and where does it read input from?
Answer the following questions based on Program 3-1
Give an example of a prompt from this program.
Where can the values of the length and width be obtained?
What is a prompt?
What is the importance of a prompt?
What is >> symbol and what is it used for?
What is the two-step process of gathering input fro the user?
Entering Multiple Values
Answer the following 3 questions based on Program 3-2.
Give an example of getting multiple values from users.
How can cin know where each number begins and ends if there are two or more values are entered?
Can cin also read multiple values of different data types?
What is the keyboard buffer?
Is it important that the user enters multiple values in the correct order?
Reading Strings
What are character arrays?
What is an array?
Give an example of a character array definition?
What does the number inside the brackets indicate?
If a programmer define an array like this: char name [10], how many characters can this array hold? Why?

(C) Programming Challenges
1. Write a program that demonstrates how cin read a string into a character array.
The output will show the following:
"What are your first name and your last name?"
"My name is Sun, Yuhong."
Suggestion: define two variables.
Study Program 3-4 on Page 4.

October 2.

2. Word Game
Write a program that plays a word game with the user. The program should ask the
user to enter the following:

* His or her name
* His or her age
* The name of a city
* The name of a college
* A profession
* A type of animal
* A petís name

After the user has entered these items, the program should display the following story,
inserting the userís input into the appropriate locations:

There once was a person named NAME who lived in CITY. At the age of
AGE, NAME went to college at COLLEGE. NAME graduated and went to work
as a PROFESSION. Then, NAME adopted a(n) ANIMAL named PETNAME. They
both lived happily ever after!

(B) Rewrite Word Game using cin.getline() and constant for the array size.
See Program 3-21 Page 44
Program 3-22 Page 45

Answer the following questions: (page 45 and 24)
What is the purpose of useing cin.getline()?
What is the command for using cin.getline() function?
What is a constant?
Give an example to use it.

Assignment #6 (September 18)

(C) 3. Write a program that calculates the area of a round table top. The user enter the diameter. The formula for the area is Pi times the radius squared . . Pi is 3.14159.
The output will be:
The area of the round table top is _____.
Program 3-7, Page 15.

(C) 1. Write a program that uses a type cast to avoid integer division. Ask the user how many //days he works last weak and how much he got paid.
static_cast<double>(books).

The output will be:
How many days did you work last week?
How much did you get paid one hour?
I earned (e.g. $9.87) last week.
Chapter 3 Program 3-10, Page 21.

Oct. 7

Assignment 7 (10/6/09)
(C) Part I: Chapter 3 Reading Page 33 to 37)
1. What is formatting and why it is important?
2. Study Program 3-15.
What does the output look like?
3. What is setw?
4. Look at the code.
Value = 25;
Cout <<setw(5) <<value
From the above code, what will the output look like?
a. (25 )
b. ( 25)
5. Compare Program 3-15 and 3-16 and what are the differences?
6. Look at the following code.
Value = 18397;
Cout <<setw(2) << value;
What would be the output and why?
a. 18397
b. 18
7. Study Program 3-17 and answer the following questions.
The field width of a floating-point number include a position for the decimal point?

* True
* False

The field width of a string includes all characters in the string but not including spaces.

* True
* False

8. What is the default of the values printed in the field?
9. What is precision?
10 What manipulator can you use to control the number of significant digits?
11. Study Program 3-18 and answer the following questions.
What is the floating-point value by default?
If the value of a number is expressed in fewer digits of precision than specified by
setprecision, what will the manipulator do? Give an example.

Oct. 9

(P1) Part I: Programming Challenge:
Average of Values
To get the average of a series of values, you add the values up and then divide the sum by the number of values. Write a program that asks the user to enter the following values in five different variables: 28, 32, 37, 24, and 33. The program should calculate the average of the numbers and display it on the screen. The number dispayed should be formatted in fixed-point notation, with one decimal point of precision.


(P2) Write a program that displays the following pattern with cout:
(B) Write a program that displays the following pattern with setw(x):
*
***
*****
*******
******
*****
***
*

See example 3-16 on Page 34 (114).

(P3.) Rewrite the World Game with constant and cin.getline. See Example 3-22 on page 45(125).

1.Create a flowchart
2.Write the program
(eTextbook P. 47, Starting Out with C++)

Part II

Assignment #8 (September 19)
Vocabulary
cin
prompt
mathematical expression
mathematical operators
order of operations
expression
iostream
algebraic expressions
associativity
keyboard buffer
type conversion
type coercion
coercion rules
array
c-string
arguments
cin
c++ library
hierarchy of types
type coercion
Quiz:
1. Chapter 3 Vocabulary1
Program Challenge:
Choose one of the following program challenge to solve.

(C)2. This program is to calculate the volume of the classroom. Ask the user to enter the following data:
Length
Width
Height
The output should display the following:
The classroom is # cube feet.
The number dispayed should be formatted in fixed-point notation, with one decimal point of precision.
(Program 3-2, P. 4 eTextbook)

(C)3. This program is to read strings into character arrays. Ask the user to enter the full neam.
Use cin.getline( )
First name
Last name
School name
The output should display the something like this:
Thank you. Yuhong Sun goes to ...HIgh School.
(Program 3-22, P. 45, eTextbook)

(C)4 Currency
Write a program that will convert U.S. dollar amounts to Japanese Yen and to Euros.
The conversion factors to use are:
1 Dollar = 134.33 Yen
1 Dollar = 1.1644 Euros
Format your currency amounts in fxed-point notation, with two decimal places of
precision, and be sure the decimal point is always displayed.

Assignments # 9 (September 23)

1. Take Chapter3_Quiz1 on Moodle.

(C) 2. Programming Challenges
1. Miles per Gallon
Write a program that calculates a car's gas mileage. The program should ask the user to enter the number of gallons of gas the car can hold, and the number of miles it can be driven on a full tank. It should then display the number of miles that may be driven per gallon of gas.
(P. 74, eTextbook, Starting Out with C++)

(B) 3. Programming Challenges
18. Pizza Pi

Joe's Pizza Palace needs a program to calculate the number of slices a pizza of any size can be divided into. The program should perform the following steps:
a) Ask the user for the diameter of the pizza in inches.
b) Calculate the number of slices that may be taken from a pizza of that size.
c) Display a message telling the number of slices.

To calcalate the number of slices that may be taken from the pizza, you must know the following faces:
Each slice should have an area of 14.125 inches.
To calculate the number of slices, simply divide the area of the pizza by 14.125.
The area of pizza is calculated with this formula:

Area = PI* rsq.
(P. 78 eTextbook, Starting out with C++)

P. 78 eTextbook.
25. re-do Word Game.
Flow Chart and Program.

Assignment 10 (3/18/2010)
Re-take Chapter 3 Quiz1 if you don't pass it.
Save as Ch3_FixManipulatorRead_Oct16 &
Save as Cha3_FixManipulatorP_Oct16

(C) Reading Page 36 -39
Setprecision manipulaotr
What is the significance of setprecision manipulator?
Is the value rounded to a number of setprecision?
Please match the numbers with the formats according to Program 3-18.
1. cout << setprecision(5) << quotient << endl;
2. cout << setprecision(4) << quotient << endl;
3. cout << setprecision(3) << quotient << endl;
4. cout << setprecision(2) << quotient << endl;
5. cout << setprecision(1) << quotient << endl;

* 4.9188
* 4.919
* 5
* 4.9
* 4.92

What header file should be included?

Fixed manipulator
When the precision of a number is set to a lower value, in what notation do the numbers tend to be printed?
What is the use of fixed manipulator?
Take a look at Program 3-20.
When the fixed manipulator is used, what happen to the floating point numbers?
When the fixed and setprecision manipulators are used together, what happens to the number specified by the setprecision manipulator?
Give an example.

The showpoint Manipulator
By default, what are floating-point numbers displayed regarding trailing zeroes?
If we want the numbers padded with trailing zeroes, what manipulator should we use?

Program Challenge
(C) How Much Insurance?
8. Many fnancial experts advise that property owners should insure their homes or build-
ings for at least 80 percent of the amount it would cost to replace the structure. Write a
program that asks the user to enter the replacement cost of a building and then displays
the minimum amount of insurance he or she should buy for the property.

(B)
19. How Many Pizzas?
Modify the program you wrote in Programming Challenge 18 (Pizza Pi) so that it
reports the number of pizzas you need to buy for a party if each person attending is
expected to eat an average of 4 slices. The program should ask the user for the num-
ber of people who will be at the party and for the diameter of the pizzas to be ordered.
It should then calculate and display the number of pizzas to purchase.

Assignment 11 (September 25)
1. Take Chapter 3_Voc3 and Chapter 3 Quiz1.
2. Reading: Page 58 – 62
Introduction to File Input and Output
Why do the programs you have written so far require you to re-enter data each time the program runs?
What are the three steps that must be taken when a file is used by a program?
Setting Up a Program for File Input/ Output
What file should be included in order to use file input or file output?
What are file stream objects?
What does the fistream header file define?
What is ofstream?
What is ifstream?
What is fstream?
Give an example statements that define ofstream and ifstream objects.
Opening a File
Give an example to use inputFile to open a file named customer.dat.
Closing a File
Give an example to call the file stream object's close member function to close a File.
Writing Data to a File
Assuming outputFile is a file stream object, what is the statement demonstrating using the << operator to write a string to a file?

3. Program Challenge
Re-write Pizza I program or Pizza II program by writing the output into a file.
See Program 3-28 on Page 62.

Assignment 12 3/ 24/2010
Save as Mar24_Ch4_ifP
Save as Mar24_Ch4_ifR

Chapter 4:
(C) Page 1 – 9
What are relational operators?
What does each relational operator do?
Give an example of how a relational operator determines a specific relationship.
What do >=, ==, and != mean?
The Value of a Relationship
What are Boolean expressions?
Give an example of Boolean expression.
T or F:
Assuming x is 5, y is 6 and z is 8, indicate by circling the T or F if each of the following relational expressions is true or false:
X == 5 T F
7 <= (x + 2) T F
z < 4 T F
(2 + x) != y T F
x >= 9 T F
x <= (y * 2) T F
The if Statement
What is if statement?
Give an example in real life using if statement.
Study Program 4-2

(C) Programming Challenge:
Write a program to ask the user to enter 5 test scores. If the average is equal or bigger than 75, the user gets the message: " Coagulations, You pass it. If the average is less than 75, the user gets the message: "You failed it. Please work harder."
See Program 4-7.

Assignment 12(B), September 30
Save as Mar26_Ch4_if/else_R
Save as Mar26_Ch4_if/else_R
Chapter 4
(C) Page 14 –23
Part I: Reading and answering the questions.
Flag
What is a flag?
When the flag variable is set to false, what does it indicate?
When the flag variable is set to true, what does it mean?
What is integer flag?
Expanding the if Statement
What do you do if an "if statement" conditionally execute a group of statements?
Study Program 4-6
The if/else Statement
What is if/else statement?
What does the else part at the end of the if statement specify?
Study Program 4-9
The if/else if Statement
What is the if/else if statement?
What is the code for if/else if statement?
(C) Part II: Program Challenge
Write a program based on Program 4-10. The program has variables to home five test scores. The program should ask the user to enter five test scores and then assign the values entered to variables. If the user's grade is below 60, he got F and the message "You failed and need to work harder." If the user's grade is equal to or above 90, he got A and a message "Congratulations." If the user's grade is above 60 and below 90, he only got a grade.

10/2/

(B) 12. Monthly Sales Tax
A retail company must file a monthly sales tax report listing the sales for the month and the amount of sales tax collected. Write a program that asks for the month, the year, and the total amount collected at the sash register (that is, sales plus sales tax). Assume the state sales tax is 4 percent and the county sales tax is 2 percent.

If the total amount collected is known and the total sales tax is 6 percent, the amount of product sales may be calculated as:

s = T / 1.06

S is the product sales and T is the total income (product sales plus sales tax).
The program should display a report similar to

Month: October
---------------------------------

Total Collected:

$ 26572.89
Sales:

$ 25069.76
County Sales Tax:

$ 501.38
State Sales Tax:

$ 1002.75
Total Sales Tax:

$ 1504.13

1. Create a flowcharting
2. Write a program

(P. 76 eTextbook, Starting out with C++)

Assignment 13 (October 4)
Part I:
Save as Mar30_Geometry_P

Chapter 4
(C) Programming Challenge
17. Geometry Calculator
Write a program that display the following menu:

Geometry Calculator
1. Calculate the Area of a Circle
2. Calculate the Area of a Rectangle
3. Calculate the Area of a Triangle

Enter your choice (1-4)
If the user enters 1, the program should ask for the radius of the circle and then display its area. Use the following formula:

area = PI * r Sq.

Use 3.14159 for PI and the radius of the circle for r. If the user enters 2, the program should ask for the length and width of the rectangle and then display the rectangle's area. Use the following formula.

area = length * width

If the user enters 3 the program should ask for the length of the triangle's base and its height, and then display its area. Use the following formula:

area = base * height * .5

If the user enters 4, the program should end.
Input Validation: Display an error message if the user enters a number outside the range of 1 through 4 when selecting an etem from the menu. Do not accept negative values for the circle's radius, the rectangles length or width, or the trangle's base or height.
(See example Program 4-32, P 65, Chapter 4)
(P. 78 eTextbook, Starting out with C++)

(B) Page 59 -68

What is the switch Statement?

What is the format of the switch statement?

What is the optional default section in switch statement?

Program Challenge

(B) Rewrite the program Geometry Calculator Oct. 26 by using switch Statement. Validate the user input.

Assignment 14 April 5 (October )
Part I
Save as April5_LogicalOperator_P

Chapter 4 logical Operators
(C) Part I: Read Page 36 – 43
The && Operator
What is a logical operator?
Recognize the following symbols and tell what it is:
&& -
|| -
! –
What is && operator and in what situation can it be used?
Give an example in C++ code.
Decide the following value of expression. If it is true, use T. If it is false, use F.
true && false _______
false && true _______
false && false ________
true && true ________
Study Program 4_16
The || Operator
What is || operator and when can it be used?
Give an example in C++ code.
Decide the following value of expression. If it is true, use T. If it is false, use F.
true || false ________
false || true ________
false || false ________
true || true _________
The || operator performs short circuit evaluation. What does short circuit evaluation mean?
Study Program 4-17.
The ! Operator
What is ! operator and when is it used?
Give an example in C++ code.
Decide the following value of expression. If is true, use T. If it is false, use F.
!true _______
!false _______
Study Program 4-18
Precedence and Associability of Logical Operators
Which one has the highest precedence among !, && and ||?
Checking Numeric Ranges with Logical Operators
When determining whether a number is inside a numeric range, which operator is best to use? Give an example.
When determining whether a number is outside a range, which operator is best to use?

Part II Program Language
Save as April5_LogicalOperator_P
(C) 5. Test Scores and Grade
Write a program that has variables to hold three test scores. The program should ask the user to enter three test scores and then assign the values entered to the variables. The program should use the grading scheme in the following table.
The output should display the grading scale, the average of the test scores and the letter grade that is assigned for the test score average. If the user's grade is A, he/she should get a congratulation message. If the user's grade is below 60, he should get a warning message. See the example.
Note: Validate the user's data input. Don't accept negative number.

Picture 3.png

(A) 14. Running the Race (Honor's Challenge)
Write a program that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and thrid place.
Input Validation: Be sure the names do not overflow the arrays. Only accept positive numbers for the times.
(P. 78 eTextbook, Starting Out with C++.)

April7, Assignment15
Save as April7_Speed_P or
Save as April7_Boiling_P
Save as April7_strcmp_P

Read Page 50 to 52 and answer the following questions.
1. What should you use to compare two strings?
2. What is wrong with Program 2-23?
3. What function should be used to compare two strings?
4. What is the function's general format?
5. If the two strings are identical, what does strcmp return?
6. f string1 < string2, what does strcmp return?
7. If string1 > string2, what does strcmp returns?
8. What is the format of an if/else statement using strcmp to determine fi two strings are wqual?

1. (C) Write a program to compare three names. One pair is the same and one pair is different.Study 4-24 on page 51 and 52.

Choose either The Speed of Sound or Freezing and Boiling Points program.

3. (C) The Speed of Sound
The following table shows the approximate speed of sound in air, water, and steel.

Medium

Speed
Air

1,100 feet per second
Water

Water 4,900 feet per second
Steel

16,400 feet per second
Write a program that displays a menu allowing the user to select air, water, or steel.
After the user has made a selection, he or she should be asked to enter the distance a
sound wave will travel in the selected medium. The program will then display the
amount of time it will take. (Round the answer to 4 decimal places.)

Input Validation: Check that the user has selected one of the available choices from
the menu. Do not accept distances less than 0.

Freezing and Boiling Points
The following table lists the freezing and boiling points of several substances. Write a program that asks the user to enter a temperature, and then shows all the substances that will freeze at that temperature and all that will boil at that temperature. For example, if the user enters -20 the program should report that water will freeze and oxygen will boil at that temperature.
------------------------------------------------------------------------------------------------------
Substance Freezing Point (F) Boiling Point
----------------------------------------------------------------------------------------

Ethyl alcohol

-173

172
Mercury

-38

676
Oxygen

-362

-306
Water

32

212
(P. 80. eTextbook, Starting Out with C++.)

3. (A) Honor's Option:
Shipping Charges
The Fast Freight Shipping Company charges the following rates:

Weight of Package (in Kilograms)

Rate per 500 Miles Shipped
2 Kg or less

$1.10
Over 2 Kg but not more than 6 Kg

$2.20
Over 6 Kg but not more than 10 Kg

$3.70
Over 10 Kg but not more than 20 Kg

$4.80

Write a program that asks for the weight of the package and the distance it is to be
shipped, and then displays the charges.
Input Validation: Do not accept values of 0 or less for the weight of the package. Do
not accept weights of more than 20 Kg (this is the maximum weight the company will
ship). Do not accept distances of less than 10 miles or more than 3,000 miles. These
are the companyís minimum and maximum shipping distances.

Assignment 16, October
save as April9_sorted_Names_P

Program challenge
(B) Sorted Names
Write a program that asks the user to enter three names, and then displays the names
sorted in ascending order. Assume that none of the names are the same. For example,
if the user entered ìCharlie,î ìLeslie,î and ìAndy,î the program would display:
Andy
Charlie
Leslie

Assignment 17,
(C) Chapter 4 Vocabulary (give definitions to the words or expressions), email me.

* relational operator
* validate
* binary
* operand
* variable
* if Statement
* sequence structure
* decision structure
* conditionally executed
* flags
* integer flags
* if/else Statement
* trailing else
* logical operators
* && operator
* || operator
* ! operator
* strcmp function
* nested if Statement
* shorthand method

1. (C) Internet Service Provider
An Internet service provider has three different subscription packages for its customers:
Package A: For $9.95 per month 10 hours of access are provided. Additional hours
are $2.00 per hour.
Package B: For $14.95 per month 20 hours of access are provided. Additional hours
are $1.00 per hour.
Package C: For $19.95 per month unlimited access is provided.

Write a program that calculates a customerís monthly bill. It should ask which pack-
age the customer has purchased and how many hours were used. It should then dis-
play the total amount due.
Input Validation: Be sure the user only selects package A, B, or C. Also, the number
of hours used in a month cannot exceed 744.

 

October Assignment18

1. (C) Take Ch4_Quiz1 in Moodle.
2. (C) Take Ch4_Voc_Q1 in Moodle.
3. (C) Programming Challenge

April26 Assignment19
This is a group project. You can choose your own leader. It can be a group of two, three, four but no more than five. Each group can submit one programming code with the output and with all of the names of the members.

1. (C) Internet Service Provider
An Internet service provider has three different subscription packages for its customers:
Package A: For $9.95 per month 10 hours of access are provided. Additional hours
are $2.00 per hour.
Package B: For $14.95 per month 20 hours of access are provided. Additional hours
are $1.00 per hour.
Package C: For $19.95 per month unlimited access is provided.

Write a program that calculates a customer's monthly bill. It should ask which package the customer has purchased and how many hours were used. It should then display the total amount due.
Input Validation: Be sure the user only selects package A, B, or C. Also, the number of hours used in a month cannot exceed 744.

2. (B) Internet Service Provider, Part 2
Modify the Program in Problem 15 so it also displays how much money Package A
customers would save if they purchased packages B or C, and how much money Pack-
age B customers would save if they purchased Package C. If there would be no sav-
ings, no message should be printed.

3. (A) Internet Service Provider, Part 3
Months with 30 days have 720 hours, and months with 31 days have 744 hours. Feb-
ruary, with 28 days, has 672 hours. Enhance the input validation of the Internet Ser-
vice Provider program by asking the user for the month (by name), and validating that
the number of hours entered is not more than the maximum for the entire month.
Here is a table of the months, their days, and number of hours in each.

Month

Days

Hours
January

31

744
February

28

672
March

31

744
April

30

720
May

31

744
June

30

720
July

31

744
August

31

744
September

30

720
October

31

744
November

30

720
December

31

744

Assignment20/October

Reflection:
(C) Part I:
List the strategies you used when writing this programs. For example: relational operators, if/else Statement, etc..
Why did you use these strategies?
What problems did you encounter in this program?
Which parts do you think you can improve and how?
Check the style based on the rubric.
Post your group's code and output in the Blog.
Part II:
Read at least two others' codes. Choose one program you like better and make a comment.
Why do you like this one?
What strategies do you use to make the program better?
Which parts do you think they should improve and how?
Say one nice thing about their program.
Assignment21 April 30, 2010
Save as April30_Ch5_Loop_R
Part I
Chapter 5 Looping
(C) Read Page 1 -6
The Increment and Decrement Operator
1. What is increment and what is decrement?
2. What is the increment operator and what is the decrement operator?
3. What is postfix mode and what is prefix mode?
4. Describe the difference between postfix and prefix modes. Give examples if necessary.
Study Program 5-2
Using ++ and – in Mathematical Expressions
5.
a = 3;
b = 4;
c = a * b ++;
cout << a <<" " <<b <<" " <<c;
What will cout statement display?
6.
If the statement were changed to read
c = a * ++ b;
What will cout statement display?
7.
a = 2;
b = 5;
c = ++(a * b);
cout <<c;
What will cout statement display?
8.
x = 10;
if (x++ > 10)
cout << "x is greater than 10.\n";
Will the cout statement execute and why?
9.
x = 10;
if (++x > 10)
cout << "x is greater than 10.\n";
Will the cout statement execute and why?

Assignment 22,

Part II
(C) Part I: Read Page 7 – 18 and answer the following questions:
Introduction to Loops: The while Loop
What is a loop?
How many looping control structures in C++?
What are the two important parts of the While loop?
What is the loop header?
How does the loop work?
What is the format of the while loop?
What is iteration?
What kind of loop is the while loop: pretest or posttest?
If you want to be sure that a while loop executes the first time, what must you do?
What is an infinite loop?
How does an infinite loop happen?
Where can the while loop be used?
What is a counter?
What is the do-while loop?
What kind of loop is the do-while loop?
What is the format of the do-while loop?

save as May4_Ch4_Sales_P

(C) Software Sales
A software company sells a package that retails for $99. Quantity discounts are given
according to the following table.
Write a program that asks for the number of units sold and computes the total cost of
the purchase.
Input Validation: Make sure the number of units is greater than 0.
Quantity Discount

Quantity

Discount
10 - 19

20%
20 - 49

30%
50 - 99

40%
100 or more 50%

50%

Assignment 23,

(C) Part II: Program Challenge: Geometry Calculator
Re-write the program to display a menu and ask the user to make a selection. A do-while loop repeats the program until the user selects item 4 from the menu.

The program displays the following menu:

Geometry Calculator
1. Calculate the Area of a Circle
2. Calculate the Area of a Rectangle
3. Calculate the Area of a Triangle

Enter your choice (1-4)
If the user enters 1, the program should ask for the radius of the circle and then display its area. Use the following formula:

area = PI * r Sq.

Use 3.14159 for PI and the radius of the circle for r.

If the user enters 2, the program should ask for the length and width of the rectangle and then display the rectangle's area. Use the following formula.

area = length * width

If the user enters 3 the program should ask for the length of the triangle's base and its height, and then display its area. Use the following formula:

area = base * height * .5

If the user enters 4, the program should end.
Input Validation: Display an error message if the user enters a number outside the range of 1 through 4 when selecting an item from the menu. Do not accept negative values for the circle's radius, the rectangles length or width, or the triangle's base or height.

Study: Program 5-7 (eTextbook, Page 18)

Chapter 5
Answer the following questions
WhileLoopQuestions.pdf

Assignment 24
Save as May10_forLoop_Read
Save as May10_forLoop_P

Chapter 5
(C) Read Page 19 to 29 and answer the following questions.
What is a for loop?
What are the two categories of loops?
What is a conditional loop? Give an example.
What is a count-controlled loop? Give an example.
What are the three elements that a count-controlled loop must possess?
What is the for loop specifically designed for?
What is the format of the for loop?
What is the loop header in the for loop?
What are the three expressions inside the parentheses after the key word?
What is the first expression called and what is it used to?
What is the second expression called and what is it used for?
What is the third expression called and what is it used for?
What kind of loop is for loop? Pretest or posttest?
In what situation should you use for loop instead of while or do-while?
Study Program 5-9 and answer the following questions.
Before the loop, what does this program ask the user to enter?
Where is this value stored?
What does the for loop's test expression use this maxValue for?
When will the loop terminate?
Keeping a Running Total
What is a running total?
Why is it called a running total?

Assignment 25,
Save as May13 _forLoop_sum_P
Save as May13 _forLoop_pay_P
Save as May13 _Pattern_P
(C) Programming Challenges
1. Write a program based on Program 5-10.
1. Sum of Numbers
Write a program that asks the user for a positive integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2, 3, 4, ... 50.
Input Validation: Do not accept a negative starting number.
(eTextbook, Starting Out with C++.)

1. Write a program to calculate the money you earned over a period of time and calculate the total. Validate the input from the user.
Based on Program 5-10. eTextbook Page 29.


2. Programming Challenges
(B) 20. Pattern Displays
Write a program that uses a loop to display Pattern A below, followed by another loop that displays Pattern B.
__________________________________________________
Pattern A
+
++
+++
++++
+++++
++++++
+++++++
++++++++
+++++++++
++++++++++

++++++++++
+++++++++
++++++++
+++++++
++++++
+++++
++++
+++
++
+
____________________________________________________
P. 51, eTextbook, Starting Out with C++
(See the example "Using break in a Nested Loop on P. 39 eTextbook.)

May17,

1. (C) Program Challenge
save as May17_Distance_P
Distance Traveled (6)
The distance a vehicle travels can be calculated as follows:
distance = speed * time
For example, if a train travels 40 miles per hour for 3 hours, the distance traveled is
120 miles.
Write a program that asks the user for the speed of a vehicle (in miles per hour) and
how many hours it has traveled. It should then use a loop to display the distance the
vehicle has traveled for each hour of that time period. Here is an example of the out-
put:
What is the speed of the vehicle in mph? 40
How many hours has it traveled? 3
Hour Distance Traveled
--------------------------------
1 40
2 80
3 120
Input Validation: Do not accept a negative number for speed and do not accept any
value less than 1 for time traveled.
Examples 5-9 (Page 26), 5-10 (Page 29)

(B) Pennies for Pay (Honor's Option)
Write a program that calculates how much a person would earn over a period of time
if his or her salary is one penny the first day, two pennies the second day, and contin-
ues to double each day. The program should ask the user for the number of days. Dis-
play a table showing how much the salary was for each day, and then show the total
pay at the end of the period. The output should be displayed in a dollar amount, not
the number of pennies.
Input Validation: Do not accept a number less than 1 for the number of days worked.

Assignment27
Part I
Chapter 5/ Leftovers /Reading
Page 30 -31
What is a sentinel?
What is the importance of having a sentinel?
In Program 5-11, what is the sentinel?

Page 35
Read the summary and answer the following questions.
When should while loop be used?
What is the ideal situation to use do-while loop?
When should for loop be used?

Nested Loops
Page 35 – 38
What is a nested loop?
Why are nested loops necessary?
Give an example of nested loops being used.
Take a look at the example of digital clock.
What are the three points that the simulated clock brings up about nested loops?
Study Program 5-14.

Page 38 -39
Breaking Out of a Loop
What is the break statement in a loop?
What should we be cautious to use break in a program?
In the following code, what does break statement affect the program?

int count = 0;
while (count++ < 10)
{
cout << count << endl;
if (count == 5)
break;
}
In program 5-15, what is the importance of using break statement?

Page 40
What is the continue statement?
Why should you be careful to use continue statement?
What is the significance of using the continue statement?

Part II
(C) Login to the Moddle and take Lesson5_Voc_Quiz
Take the Lesson 10 Concept_Quiz

Part III. Program Challenge
Save as may19_employee_P

2. (B) Assuming the ocean's level is currently rising at about 1.5 millimeters per year, write a program that displays a table showing the number of millimeters that the ocean will have risen each year for the next 25 years.

P. 47 eTextbook, Starting Out with C++

Assignment 28
Save as Dec15_function_Greeting_P
(C) Part I
Write a program that uses function Greeting. Greeting is going to be repeatedly called form a loop for 5 times. Greeting will display the message: Hello, Good morning. (See Program 6-2) (See Programming Rubric )

(C) Part II
Chapter 6 Functions
Read from Page 1 to 10, eTextbook, Starting Out with C++.
Answer the following questions:

What is a function?
Why is function important in programming?
What parts does a function definition have?
What is a return type?
What are the rules for the function name?
What is a parameter list?
What is a function body?
Analyze Figure 6-2 (Page 6, Chapter 6, eTextbook)
What value does the main function return?
What are void functions?
What is Calling a Function?
Analyze Program 6-1 (Page 4, Chapter 6, eTextbook)
What is the function header?
Which of the following is function header or function call?
Void displayMessage( )
displayMessage( );

Assignment 29
Part I: Play Jeopardy_Ch6_Functions (Login moodle)
Part II: Reading
Part III: Program Challenge

Save as May24_function2_R
Save as May24_function2_P

(C) Part I
Jeopardy
(C) Part II
Read from Page 11 to 22, eTextbook, Starting Out with C++.
Answer the following questions:
What is a function prototype?
What are arguments and give example?
What is a parameter and give example?
What does Passing data by value mean?
What does the return statement do?
How does a function return a value?
How do you define a value-returning function?
What data types does a value-returning function return?
Give example of the return type in a function?
(C) Part III
1. Write a program that consists of three functions: main, message1 and message2.
The main function contains the message: " I am the resource center."
Message1 contains the message: "I am supporting the resource center."
Message2 contains the message: "I am providing the information to the resource center."
(Example: Program 6-5, Page 12, Chapter 6, eTextbook.)

The following two programs are optional. Select one.
(C) I. Write a program that uses a function to return a value. One number is 15 and the other is 25. The program output will be "Number1 * Number2 is ? ."
(See the example: Program 6-12)

(C) II. Mark Up
Markup (optional)
Write a program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example:

* If an item's wholesale cost is 5.00 and its markup percentage is 100%, then the item's retail price is 10.00.
* If an item's wholesale cost is 5.00 and its markup percentage is 50%, then the item's retail price is 7.50.

The program should have a function named calculateRetail that receives the
wholesale cost and the markup percentage as arguments, and returns the retail price of the item.
Input Validation: Do not accept negative values for either the wholesale cost of the item or the percent markup.
P. 67 eTextbook, StartingOut with C++

Assignment 30
save as Jan4_average_function_P
(C) Write a program to ask the user to enter three test scores and calculate the average using function with prototype.
Study Program 6-8 on Page 16.

May 28 Assignment 31
save as Jan6_Value-returning_R
Chapter 6 Functions
(C) Read from Page 24 to 31
The return Statement
What is the return statement?
When the last statement in a void function has finished executing, what does the function do?
When the return statement is encountered, what does the function do?
Study Program 6 -11 and answer the following question.
In Program 6 -11, what does the function do, if arg2 is set to zero (Line 16 to 32)?
Returning a Value from a Function
What are value-returning functions?
How many values may be returned from a function if several arguments are passed into the function?
Is it possible to return multiple values from a function and how?
Defining a Value-Returning Function
When you are writing a value-returning function, what must you decide first and why?
What data types can be used in the header of a value-returning function?
Give an example of a function that returns an int value.
What are local variables?
What does return result; statement cause the function to do in the above example?
What statement must a value-returning function have and what is the general format?
What kind of expression can be returned as a value?
How is the value of the expression returned?
Calling a Value-Returning Function
In Program 6-12, what value will be returned to the function sum?
Study Program 6 -13 and answer the following questions.
How many prototypes and what are they?
List all the function calls.
List all the function headers.
List all the returning values.
What is the purpose of the getRadius function (Line 39 – 46)?
What kind of variable is rad?
Where is getRadius function called?
Where is the value that is returned from the function assigned?
What kind of expression is returned in square function?
Where is square function called?
Assuming the user has entered 10 as the radius, and this value is passed as an argument to the square function, what value will the square function return?

(C) Assignment 32 Group Work Jan_8

Assignment 33
Chapter 6 Functions
Save as function_2_R
(C) Read from 34 -38
Local and Global Variables
What is a local variable?
What is a global variable?
Can variables defined inside a function be accessible from other functions and why?
Can variables use the same names in different functions and why? Give example.
What is a local variable's lifetime?
Is it possible to use a parameter variable to initialize a local variable?
What is the scope of a global variable?
Can a global variable be accessed by all functions that are defined after the global variable is defined?
Can local and global variables use the same name?
Study Program 6-18 on Page 38.

Read from page 41 to 48/ Assignment 34
Static Local Variables
If a function is called more than once in a program, what will happen to the values stored in the local variables between function calls and why?
Study Program 6-20 and answer the following questions.
What value will be returned to showLocal(); in Line 11?
What value will be returned to showLocal(); in Line 12?
From Line 23 to 28, the initial value of localNum, which is 5, is displayed. The value of localNum is then changed to 99 before the function returns. Why do the program output show both 5?
What can be done to let a program "remember" what value is stored in a local variable between functions calls?
Study Program 6-21 and see how static local variables are used.
Default Arguments
What are default arguments?
Where are the default arguments usually listed?
When a default argument is passed to the parameter?
Give an example of the default arguments that are listed in the function prototype.
If a function does not have a prototype, where may default arguments be specified?
Give an example.
Part II
Study Program 6-22 on page 44.

Program Challenge
If you finis the first one, do the second one.
Save as mark-up_p
Save as Function_payRate_p
(B) 1. Markup
Write a program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example:

* If an item's wholesale cost is 5.00 and its markup percentage is 100%, then the item's retail price is 10.00.
* If an item's wholesale cost is 5.00 and its markup percentage is 50%, then the item's retail price is 7.50.

The program should have a function named calculateRetail that receives the
wholesale cost and the markup percentage as arguments, and returns the retail price of the item.
Input Validation: Do not accept negative values for either the wholesale cost of the item or the percent markup.

Assignment 35
(C) 2. Re-write the program that calculates hourly wages, including overtime. Use two functions: void and value-return. For example, double getBasePay(double); and double getOvertimePay (double). Include comments.
Base pay rate: 20.50
Hours worked less overtime: 40.0
Overtime pay rate: 25.50
Overtime hours worked: 15
The program will display the following output:
The total earning this week is $#.
(See example: Program 2-20, P. 35 eText)

(B) Write a program that calculates hourly wages, including overtime. Ask the user for the regular hours and the overtime hours he has worked. Use functions. For example, double getBasePay(double); double getOvertimePay (double), double calculateRegularWages (double, double), void function etc. Include comments.
Base pay rate: 20.50
Overtime pay rate: 25.50
The program will display the following output:
The total earning this week is $#.
(See example: Program 2-20, P. 35 eText)
If the user enters 4, the program should end.

Input Validation (A) : Display an error message if the user enters a number outside the range of 1 through 4 when selecting an item from the menu. Do not accept negative values for the circle's radius, the rectangles length or width, or the triangle's base or height.

Assignment 36

(C) Write a program that a static local variable is only initialized once. The output will be shown as follows:
staticVal is 10
staticVal is 11
staticVal is 12
staticVal is 13
staticVal is 14

Read 49 -52
(C) Part I
save as Jan_reference_variable_R
What is a reference variable?
What is special about reference variable?
How is a reference variable defined?
Where must the ampersand be used?
Study Program 6-24 and answer the following question.
The parameter refVar in Program 6-24 "points" to the value variable in function main. When a program works with a reference variable, what is it actually working with?
When function arguments are passed by value, what is passed into the parameter variable?
When a reference parameter is used, what is the argument passed by?

Part II
Program 6-25
(A ) Program Challenge
save as Jan_Lowest_score_drop_p
Lowest Score Drop
Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions:

• void getScore() should ask the user for a test score, store it in a reference
parameter variable, and validate it. This function should be called by main once for each of the five scores to be entered.
• void calcAverage() should calculate and display the average of the four highest scores. This function should be called just once by main, and should be passed
the five scores.
• int findLowest() should find and return the lowest of the five scores passed to it. It should be called by calcAverage, who uses the function to determine which of the five scores to drop.

Input Validation: Do not accept test scores lower than 0 or higher than 100.

Assignment 37: Review
(C) Group Work

(C) Function II

Program Challenge
(A) 4. Safest Driving Area
P.68

(C) Chapter 6 Review
Concepts
Function
Function call
Function header
Function definition
Return type
Name
Parameter list
Body
Void functions
Document your functions
Function prototypes
Arguments
Parameters
Passing data by value
Value-returning functions
Local variables
Global variables
Local variable lifetime
Global constants
Local and global variables with the same name
Static local variables
Default arguments

Programs
Functions

Final Exam

Continued