4
PT1420: Introduction to Programming p. 1 of 1 Unit 3 Assignment 1: Homework Last Modified: Friday, January 9, 2015, 2:45 PM UNIT 3 ASSIGNMENT 1: HOMEWORK Learning Objectives and Outcomes Describe the use of variables (declaration, naming, assignment, and initialization) in program designs. Use the correct data type for variables in program designs. Describe the usefulness of properly commenting code. Assignment Requirements These pages are attached to this assignment. Short Answer 5 and 6 on page 71 Algorithm Workbench Review Questions 3-10, starting on page 71 Programming Exercise Questions 6 and 8 on page 73 Required Resources Textbook Submission Requirements Submit your written response in email to [email protected] by the beginning of Unit 4 (January 17, 2015).

Assignment Requirements Required Resources …richmath.org/2014-PT1420/Unit 3 Assignment 1 - Homework.pdf · PT1420: Introduction to Programming p. 1 of 1 Unit 3 Assignment 1: Homework

  • Upload
    lynhan

  • View
    253

  • Download
    5

Embed Size (px)

Citation preview

Page 1: Assignment Requirements Required Resources …richmath.org/2014-PT1420/Unit 3 Assignment 1 - Homework.pdf · PT1420: Introduction to Programming p. 1 of 1 Unit 3 Assignment 1: Homework

PT1420: Introduction to Programming p. 1 of 1 Unit 3 Assignment 1: Homework

Last Modified: Friday, January 9, 2015, 2:45 PM

UNIT 3 ASSIGNMENT 1: HOMEWORK

Learning Objectives and Outcomes

Describe the use of variables (declaration, naming, assignment, and

initialization) in program designs.

Use the correct data type for variables in program designs.

Describe the usefulness of properly commenting code.

Assignment Requirements

These pages are attached to this assignment.

Short Answer 5 and 6 on page 71

Algorithm Workbench Review Questions 3-10, starting on page 71

Programming Exercise Questions 6 and 8 on page 73

Required Resources

Textbook

Submission Requirements

Submit your written response in email to [email protected] by the beginning

of Unit 4 (January 17, 2015).

Page 2: Assignment Requirements Required Resources …richmath.org/2014-PT1420/Unit 3 Assignment 1 - Homework.pdf · PT1420: Introduction to Programming p. 1 of 1 Unit 3 Assignment 1: Homework

.......... --- - -----_. __ .. ---

Review Questions 71

True or False

1. Programmers must be careful not to make syntax errors when writing pseudocode programs.

2. In a math expression, multiplication and division takes place before addition and subtraction.

3. Variable names can have spaces in them.

4 . In most languages, the first character of a variable name cannot be a number.

5. The name gross_pay is written in the cameiCase convention.

6. In languages that require variable declarations, a variable's declaration must appear before any other statements that use the variable.

7. Uninitialized variables are a common cause of errors.

8. The value of a named constant cannot be changed during the program's execution.

9. Hand tracing is the process of translating a pseudocode program into machine language by hand.

10. Internal documentation refers to books and manuals that document a program, and are iritended for use within a company's programming department.

Short Answer

1. What does a professional programmer usually do first to gain an understanding of a problem?

2. What is pseudocode?

3. Computer programs typically perform what three steps?

4. What does the term "user-friendly" mean?

5. What two things must you normally specify in a variable declaration?

6. What value is stored in uninitialized variables?

Algorithm Workbench

1. Design an algorithm that prompts the user to enter his or her height and stores the user's input in a variable named height.

2. Design an algorithm that prompts the user to enter his or her favorite color and stores the user's input in a variable named color.

3. Write assignment statements that perform the following operations with the variables a, b, and c.

a. Adds 2 to a and stores the result in b

b. Multiplies b times 4 and stores the result in a c. Divides a by 3.14 and stores the result in b

d. Subtracts 8 from b and stores the result in a

srich
Rectangle
srich
Rectangle
Page 3: Assignment Requirements Required Resources …richmath.org/2014-PT1420/Unit 3 Assignment 1 - Homework.pdf · PT1420: Introduction to Programming p. 1 of 1 Unit 3 Assignment 1: Homework

72 Chapter 2 Input, Processing, and Output

4. Assume the variables result, w, x, y, and z are all integers, and that w = 5, x = 4, y = 8, and z = 2. What value will be stored in result in each of the following

statements?

a. Set result x + y

b. Set result = z * 2

c. Set result y / x

d. Set result y - z

5. Write a pseudocode statement that declares the variable cost so it can hold real numbers.

6. Write a pseudocode statement that declares the variable total so it can hold integers. Initialize the variable with the value O.

7. Write a pseudocode statement that assigns the value 27 to the variable count.

8. Write a pseudocode statement that assigns the sum of 10 and 14 to the variable total.

9. Write a pseudocode statement that subtracts the variable downPayment from the variable total and assigns the result to the variable due.

10. Write a pseudocode statement that multiplies the variable subtotal by 0.15 and assigns the result to the variable totalfee .

11. If the following pseudocode were an actual program, what would it display?

Declare Integer a = 5 Declare Integer b = 2 Declare Integer c = 3 Declare Integer result

Set result = a + b * c Display result

12. If the following pseudocode were an actual program, what would it display?

Declare Integer num = 99 Set num = 5 Display num

Programming Exercises 1. Personal Information

Design a program that displays the following information:

• Your name • Your address, with city, state, and ZIP • Your telephone number • Your college major

2. Sales Prediction

A company has determined that its annual profit is typically 23 percent of total sales. Design a program that asks the user to enter the projected amount of total sales, and then displays the profit that will be made from that amount.

Hint: Use the value 0.23 to represent 23 percent.

srich
Rectangle
Page 4: Assignment Requirements Required Resources …richmath.org/2014-PT1420/Unit 3 Assignment 1 - Homework.pdf · PT1420: Introduction to Programming p. 1 of 1 Unit 3 Assignment 1: Homework

.....

VideoNote

The Tip, Tax, and Total Problem

Programming Exercises 73

3. Land Calculation

One acre of land is equivalent to 43,560 square feet. Design a program that asks the user to enter the total square feet in a tract of land and calculates the number of acres in the tract.

Hint: Divide the amount entered by 43,560 to get the number of acres.

4. Total Purchase

A customer in a store is purchasing five items. Design a program that asks for the price of each item, and then displays the subtotal of the sale, the amount of sales tax, and the total. Assume the sales tax is 6 percent.

S. Distance Traveled

Assuming there are no accidents or delays, the distance that a car travels down the interstate can be calculated with the following formula:

Distance = Speed x Time

A car is traveling at 60 miles per hour. Design a program that displays the following:

• The distance the car will travel in 5 hours • The distance the car will travel in 8 hours • The distance the car will travel in 12 hours

6. Sales Tax

Design a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume the state sales tax is 4 percent and the county sales tax is 2 percent. The program should dis­play the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of purchase plus the total sales tax).

Hint: Use the value 0.02 to represent 2 percent, and 0.04 to represent 4 percent.

7. Miles-per-Gallon

A car's miles-per-gallon (MPG) can be calculated with the following formula:

MPG = Miles driven / Gallons of gas used

Design a program that asks the user for the number of miles driven and the gallons of gas used. It should calculate the car's miles-per-gallon and display the result on the screen.

8. Tip, Tax, and Total

Design a program that calculates the total amount of a meal purchased at a restau­rant. The program should ask the user to enter the charge for the food, and then calculate the amount of a 15 percent tip and 7 percent sales tax. Display each of these amounts and the total.

9. Celsius to Fahrenheit Temperature Converter

Design a program that converts Celsius temperatures to Fahrenheit temperatures. The formula is as follows:

9 F=-C+32

5

srich
Rectangle
srich
Rectangle