You are on page 1of 80

Study Guide

Introduction to Programming
By

Lisa T. Cordeiro

About the Author


Lisa T. Cordeiro served in the Marines Corps in Okinawa, Japan, working in telecommunications. Following the Marine Corps, she graduated from the University of Massachusetts at Amherst with a bachelor of arts degree in comparative literature and psychology and from Harvard Universitys Extension School with a master of arts degree in English and American literature. Ms. Cordeiro has worked as a technical writer for several years with a number of distance education and health-care companies. She has written several study guides for Penn Foster on the Internet, HTML, and e-commerce. In addition, Ms. Cordeiro has published several articles and essays for book anthologies and Web sites. She has recently published her first book, Parris Island: A Womans Memoir of Marine Corps Boot Camp.

Contents Contents

INSTRUCTIONS TO STUDENTS LESSON ASSIGNMENTS LESSON 1: INTRODUCTION TO PROGRAMMING AND LOGIC GRADED PROJECTLESSON 1 LESSON 2: MAKING DECISIONS AND SPECIAL SITUATIONS GRADED PROJECTLESSON 2 LESSON 3: ADVANCED PROGRAMMING TECHNIQUES GRADED PROJECTLESSON 3 LESSON 4: MORE ADVANCED PROGRAMMING GRADED PROJECTLESSON 4 SELF-CHECK ANSWERS

1 5

7 19

23 37

41 51 53 69 73

iii

YOUR COURSE

Instructions Instructions

Welcome to your course on computer programming. In this course, youll learn the basics of computer programming and logic. You wont learn a specific programming language; rather, youll examine the basic logic common to all programming languages. Youll come away from this course with a solid knowledge of how to create your own programs. Youll also be given guidelines on how to incorporate good design into your programs. Youll walk away from this course with a solid understanding of programming concepts that you can use in your own designs. This course is designed for beginner programmers. You dont need any previous programming experience or an extensive math background; the text is written in nontechnical English, so even the beginner can follow the logic. You also dont need to focus on a specific programming language. This course focuses on basic guidelines and best practices for developing good programming skills.

OBJECTIVES
When you complete this course, youll be able to

Describe basic programming steps Describe the three basic programming structures Create modules and hierarchy charts Describe logical programming steps Use Boolean expressions Create loops Add control breaks Create arrays and advanced arrays Validate input and create menus Merge files

Incorporate system modeling with UML Create relational databases

YOUR TEXTBOOK
Your textbook for this course is Programming Logic and Design, Fifth Edition, by Joyce Farrell. The textbook contains the material on which youll be tested. You should become familiar with this text prior to beginning your studies. Youll want to begin by skimming the brief contents on page v. Here youll see a list of the chapter titles, which give you an overall idea of what youre going to be learning. The table of contents, which begins on page vii, provides a more detailed listing of the topics youll learn in each chapter. Read the preface on pages xixxxiv to explore how the text is organized. The main part of your textbook (pages 1663) is the study material for the course. Each chapter begins with a list of Learning Objectives, followed by the study material itself. At the end of each chapter is a chapter summary and a list of Key Terms. Use the Key Terms to check your understanding of the material youve read. Each chapter also includes Review Questions and Exercises as well as Detective Work and Find the Bugs sections to analyze program structures for errors and issues. Up for Discussion sections provide concepts to think about and discuss. Youll find the answers on your student web site. Log into the Student Area at www.pennfoster.edu. Go to My Courses, and look for the Solutions link associated with your course. Five appendices, A, B, C, D, and E are located at the end of the text. A glossary of key terms begins on page 699. Finally, an index begins on page 715. The index includes important topics covered in your textbook, along with page references where you can locate material relating to each term. Your text also includes a CD-ROM of Microsofts Visio Professional 2007. You can use this software to create flowcharts or work with the exercises presented in this course. The CD-ROM can be used for free for 60 days.

Instructions to Students

Note: Wait until youre ready to complete Lesson 1 graded project to install the software. Then you wont use up any valuable days in the free trial.

COURSE MATERIALS
This course includes the following materials: 1. This study guide, which contains an introduction to your course, plus

A lesson assignments page with a schedule of study assignments Assignment introductions emphasizing the main points in the textbook Self-checks and answers to help you assess your understanding of the material A graded project for each of the lessons in this course

2. Your course textbook, Programming Logic and Design, Fifth Edition, which contains the assigned reading material 3. A CD-ROM for Microsoft Visio Professional 2007 with a 60-day license

A STUDY PLAN
Think of this study guide as a blueprint for your course. You should read it carefully. Follow the steps below to receive the maximum benefit from your studies. 1. Note the pages for each assignment and read the introductory material in this study guide. 2. Study the assigned pages, paying attention to all details, especially the main concepts. 3. Read the Chapter Summary and Key Terms, and then complete the Review Questions and the Exercises at the end of the chapter.

Instructions to Students

4. Answer the questions and problems presented in the self-checks in the study guide. This will serve as a review of the material covered. 5. After answering the suggested questions, check your answers with those provided at the end of the study guide. If you miss any of the self-check questions, review the pages in the textbook that cover those questions. The self-checks are designed to reveal weak points that you need to review. Dont send the self-check answers to the school. Theyre for you to evaluate your understanding of the material. 6. After youve completed and checked the self-checks for each lesson, complete the graded project for that lesson. Follow the directions for submitting your projects. Follow this procedure for all lessons. You can e-mail your instructor for assistance at any time. Youre now ready to begin. Good luck!

Instructions to Students

Assignments Assignments

Lesson 1: Introduction to Programming and Logic


For: Assignment 1 Assignment 2 Assignment 3 Read in the study guide: Pages 810 Pages 1113 Pages 1418 Read in the textbook: Chapter 1, pages 142 Chapter 2, pages 4384 Chapter 3, pages 85134 Material in Lesson 1

Graded Project 41880000

Lesson 2: Making Decisions and Special Situations


For: Assignment 4 Assignment 5 Assignment 6 Assignment 7 Read in the study guide: Pages 2326 Pages 2729 Pages 3032 Pages 3335 Read in the textbook: Chapter 4, pages 135192 Chapter 5, pages 193236 Chapter 6, pages 237283 Chapter 7, pages 285337 Material in Lesson 2

Graded Project 41880100

Lesson 3: Advanced Programming Techniques


For: Assignment 8 Assignment 9 Assignment 10 Read in the study guide: Pages 4143 Pages 4447 Pages 4850 Read in the textbook: Chapter 8, pages 339384 Chapter 9, pages 385432 Chapter 10, pages 433484 Material in Lesson 3

Graded Project 41880200

Lesson 4: More Advanced Programming


For: Assignment 11 Assignment 12 Assignment 13 Assignment 14 Read in the study guide: Pages 5356 Pages 5760 Pages 6164 Pages 6567 Read in the textbook: Chapter 11, pages 485545 Chapter 12, pages 547587 Chapter 13, pages 589619 Chapter 14, pages 621663 Material in Lesson 4

Graded Project 41880300

Lesson Assignments

Introduction to Programming and Logic

Lesson 1 Lesson 1

If youre new to programming, you might be intimidated by code or flowcharts. You might wonder how youll ever understand them. In this lesson, well start with some basic ideas and programming examples that you can follow along with. Youll soon understand the logic behind software programs. In your first assignment, youll read an overview of how computers work and briefly read a description of logic. In the second assignment, youll learn about the importance of structure in creating efficient, readable programs. In the third assignment, youll learn about modules and best practices for creating a software program. When you complete this lesson, youll be able to

Describe basic programming concepts Describe the basic programming steps Discuss the importance of structure Describe three basic structures Create modules Create hierarchy charts Describe documentation types Describe the logical programming steps Declare variables

This study guide is designed to break the material into easyto-understand chunks so that you arent intimidated by the material. Follow the directions outlined in the assignments, read the assigned text, and complete the self-checks to get the most from this course. Youll soon understand the basics of programming.

ASSIGNMENT 1: AN OVERVIEW OF COMPUTERS AND LOGIC


Read this assignment and then read pages 142 in your textbook. When youre comfortable with the material presented in the text, take the self-check to gauge your progress. If there are any areas you dont feel comfortable with, reread those sections in the textbook before returning to the study guide. When you feel youve mastered the material in Chapter 1, move on to the next assignment.

The Six Steps of Program Creation

Understanding the Problem

Planning the Logic

A computer needs both hardware (computer devices) and software (programs) to perform its four major functions: input, processing, output, and storage. Programmers tell the computer what to do by using a programming language, such as Visual Basic or C#. The programming language must follow certain rules, called syntax, for it to be understood. The commands that tell the computer what to do also must follow a certain sequence, which is called logic, so the computer can process the request. A programmer performs the following six steps when creating a program (Figure 1): 1. Understand the problem.

Coding the Program

Translating the Program into Machine Language

2. Plan the logic. 3. Code the program. 4. Translate the program into machine language.

Testing the Program

5. Test the program. 6. Put the program into production.

Putting the Program into Production

FIGURE 1The Six Steps of Program Creation

Introduction to Programming

Information is stored on a computer in whats known as a data hierarchy: a database contains files, files contain records, and records contain fields. Data consists of characters, such as letters or numbers. When planning the logic of a program, programmers will often use flowcharts or pseudocode. A flowchart is a pictorial representation of the steps in a program. Pseudocode is an English-like representation of the steps. Programmers create variables that stand for different values. The name of a variable should be no more than one word. Programmers end programs by creating a decision, which is represented in a flowchart by a diamond. If the flowchart runs onto another page, they use a connector. When assigning values to variables, programmers often use the equal sign (=). Computers can handle two types of data: text and numeric. Each type is treated differently by the computer. Typically, text data values are enclosed in quotations, as in color, to distinguish them from numeric values. Finally, two techniques can be used to develop programs: procedural programming and object-oriented programming. Procedural programming focuses on procedures or actions, such as producing a paycheck. Object-oriented programming focuses on objects, such as the paychecks themselves. From now until Chapter 11, youll read about procedural programming. In Chapter 11, youll learn about object-oriented programming. Read the Chapter Summary on page 30 and then review the Key Terms on pages 3033. Answer the Review Questions on pages 3436 and work through Find the Bugs on page 36. Then complete Exercises 2, 4, and 13 presented on pages 3740, and find the answers to the Detective Work questions on page 41. When you feel youve mastered the material in this assignment, complete Self-Check 1. Answers to the self-check questions are provided at the end of this study guide. Answers to the Review Questions, Find the Bugs, Exercises, and Detective Work, are on the Web. Log into the Student Area at www.pennfoster.edu. Go to My Courses and look for the Solutions link associated with this course.

Lesson 1

Self-Check 1
At the end of each section of Introduction to Programming, youll be asked to pause and check your understanding of what youve just read by completing a Self-Check exercise. Answering these questions will help you review what youve studied so far. Please complete Self-Check 1 now. 14: Indicate whether the following statements are True or False. ______ 1. Software includes the input devices that you connect to your computer, such as the keyboard. ______ 2. When a program has no end, its working in an infinite loop. ______ 3. In a flowchart, decisions are depicted by a connector. ______ 4. Some programmers divide the programming process into eight steps, the final step being when the program is retired. 5. The smallest part in the data hierarchy is the _______. 6. Memory locations are known as _______. 7. A/an _______ is a pictorial representation of the logic for a programming problem. 8. Programming that revolves around actions is known as _______. Check your answers with those on page 73.

10

Introduction to Programming

ASSIGNMENT 2: UNDERSTANDING STRUCTURE


Read this assignment and then read pages 4384 in your textbook. When youre comfortable with the material presented in the text, take the self-check to gauge your progress. If there are any areas you dont feel comfortable with, reread those sections in the textbook before returning to the study guide. When you feel youve mastered the material in Chapter 2, move on to the next assignment.

Program code can become quite complicated. When a collection of program statements becomes difficult to read, its called spaghetti code, because its like following a noodle in a bowl of spaghetti. Therefore, its best to keep your code simple by using structures. The three basic programming structures are sequences (Figure 2), selections, and loops. You can stack structures on each other at entrance or exit points. Putting one structure within another is called nesting.

FIGURE 2A Sequence

Lesson 1

11

To make your program workable and structured, you may have to add an extra step, called a priming read or a priming input. You would add a step for getting the input number before beginning a structured loop. Looping involves asking a question, and if you perform an action based on the answer to that question, you then ask the question again. In a structured loop 1. You ask a question. 2. You perform a procedure, if the answer dictates it. 3. If you performed a procedure, you go back and ask the question again. You may be wondering why you have to structure your code. Its important to follow the rules for structuring your program for the following reasons:

It keeps the code clear. Its the way professional programmers write code. Its more efficient. Its easier to maintain. It can be broken down into modular pieces.

If you come across code that isnt structured, you can structure it. Again, think of a bowl of spaghetti. Your job is to follow a noodle through the bowl and disentangle it from the other noodles. Essentially, youre separating the noodles and rearranging them. Three special structures well discuss are case, do until, and do while. You might use a case structure if there are several possible values for a variable. For instance, a program fee might be based on a sliding scale according to income. In the do until loop, a procedure is performed at least once. This differs from the do while loop, where a question is asked and an action is performed only if a condition is met. (In a do until loop, a question is asked and an action is performed until a condition is met.) Read the Chapter Summary on page 74 and then review the Key Terms on pages 7475. Answer the Review Questions on pages 7578 and work through Find the Bugs on page 78. Then complete Exercises 1, 2, and 3 presented on pages 7982,

12

Introduction to Programming

and find the answers to the Detective Work questions on page 84. When you feel youve mastered the material in this assignment, complete Self-Check 2. Answers to the self-check questions are provided at the end of this study guide. Answers to the Review Questions, Find the Bugs, Exercises, and Detective Work are on the Web.

Self-Check 2
14: Indicate whether the following statements are True or False. ______ 1. Structured code is like a bowl of spaghetti. ______ 2. A priming read is an additional input step within a program to ensure that it functions correctly. ______ 3. A do-while loop continues to execute as long as the answer to the controlling question is no. ______ 4. In a structured program, structures cant be nested within other structures. 5. What are the three basic types of structures? __________________________________________________________________________ __________________________________________________________________________ __________________________________________________________________________ 6. Placing one structure within another one is called _______. 7. What type of structure requires that you ask a question, and if you perform an action, ask the question again? __________________________________________________________________________ __________________________________________________________________________ 8. What would you consider using when there are several possible values for a variable? __________________________________________________________________________ __________________________________________________________________________ Check your answers with those on page 73.

Lesson 1

13

ASSIGNMENT 3: MODULES, HIERARCHY CHARTS, AND DOCUMENTATION


Read this assignment and then read pages 85134 in your textbook. When youre comfortable with the material presented in the text, take the self-check to gauge your progress. If there are any areas you dont feel comfortable with, reread those sections in the textbook before returning to the study guide. When you feel youve mastered the material in Chapter 3, move on to the next assignment.

Two types of documentation are generated during the programming process. Internal program documentation includes program comments that identify the logic of the program. Output documentation consists of supporting documents that programmers use before they write a program; these include printer-spacing charts. In addition, the people who use your programs, the end users, will need documentation to know how to use your program. This type of documentation is called user documentation. Programmers usually break down a program into separate units called modules. Modularization, or breaking programs into modules, is beneficial because it

Provides abstraction Enables multiple programmers to work on a program Enables programmers to reuse code Makes it easier to identify structures

When naming a module, be sure to give it a one-word name that identifies it. Module names are often verbs, such as calculatePayment. A separate flowchart is created for each module. The module is called by placing the modules name in a rectangle with a bar across the top (Figure 3). Note that modules also can call other modules.

14

Introduction to Programming

A Module

FIGURE 3In a flowchart, modules are depicted by a rectangle with a bar across the top.

In most programs, variables must be declared before they can be used. This means that you must give a name to the memory location. Variable names are usually nouns, such as payRate. Local variables are declared within each module; global variables are declared once and then used in different modules of the program. To keep track of modules, you can create a hierarchy chart, which shows the relationship between modules, such as which modules call which other modules (Figure 4).
FIGURE 4A hierarchy chart shows the relationships between modules just as a companys organizational chart shows relationships within a company or department.

John Derek CEO

Henrietta LaRose Executive Assistant

Eric Cameron Development Manager

Louise Mulroney Software Developer

In the last chapter, you learned about procedural programs, programs where one procedure follows another (Figure 5). The basic logic for procedural programs includes the following three parts:

Lesson 1

15

start perform housekeeping() while not eof perform mainLoop() endwhile perform finishUp() stop

FIGURE 5A Pseudocode Example of a Procedural Program

Completing housekeeping tasks Executing the main loop Performing the end-of-job routine

Housekeeping tasks are those tasks that you must perform at the start of a program. Four major housekeeping tasks are 1. Declaring variables 2. Opening files 3. Performing one-time tasks, such as printing headings 4. Reading the first input record After housekeeping, the next step in writing a procedural program is writing the main loop. The main loop continues until you read the end-of-file (eof). The third and final step is completing end-of-job tasks, those tasks that occur after all input records have been processed. For example, an endof-job task might be printing data after totals were calculated in the main loop. When you create a program, you should develop a plan before you start so that you create a sound program design. One way to facilitate sound program design is to store your programming components in separate files so that you can easily find, read, or reuse segments. Another good practice is to choose suitable names for variables and modules. The following are some tips for naming variables and modules:

Use meaningful names. Use pronounceable names.

16

Introduction to Programming

Make sure abbreviations are understandable to others. Avoid using numbers. Use both upper- and lowercase letters (camel case), if possible, in multiword names (or use dashes or underscores). Use verbs in status names.

To create programs with good design, you should also divide your line breaks consistently. Also note that shorter lines are easier to read and follow. In addition, consider using temporary variables when you have a long statement so that you can organize multiple variables. Finally, its better to use constants rather than numbers in your programs. For example, suppose you have a value for an employees pay rate. Its preferable to store the value as payRate rather than 10 (for $10 an hour), because the employees pay rate might change if he or she receives a raise. Read the Chapter Summary on page 123 and then review the Key Terms on pages 123126. Answer the Review Questions on pages 127129 and work through Find the Bugs on pages 129130. Then complete Exercises 1, 2, and 4 presented on pages 130132, and find the answers to the Detective Work questions on page 134. When you feel youve mastered the material in this assignment, complete Self-Check 3. Answers to the self-check questions are provided at the end of this study guide. Answers to the Review Questions, Find the Bugs, Exercises, and Detective Work are on the Web.

Lesson 1

17

Self-Check 3
14: Indicate whether the following statements are True or False. ______ 1. Output documentation is the first type of documentation created during the programming process. ______ 2. Modules can call other modules. ______ 3. Calculate Average() is a valid name for a module. ______ 4. With modularization, only one programmer can work on a program at a time. 5. To indicate the relationship between modules, you can create a/an _______. 6. A method must include a/an _______, a/an _______, and a/an _______. 7. Steps performed at the beginning of a program are known as _______ tasks. 8. A/an _______ contains a list of all of the variables used in a program. Check your answers with those on page 73.

18

Introduction to Programming

Lesson 1 Introduction to Programming and Logic


PROJECT NUMBER:

G r a d e d P r o je c t G r a d e d P r o je ct

41880000
When you feel confident that you have mastered the material in this lesson, go to http://www.takeexamsonline.com and submit your answers online. Submit your answers for this graded project as soon as you complete it. Do not wait until another graded project is ready.

For this graded project, youll complete several tasks to test your knowledge of the material youve learned in this course so far. If youve read all of the material in each assignment and have completed the Exercises in the text, you shouldnt have any problems successfully completing the tasks. Youll need to use Microsoft Visio to complete each task. You received the software with your course materials, and it has a 60-day license. If youve already installed Visio, skip to the next section. If you havent already installed Visio, complete the following steps.

Installing Visio
Note: The system requirements for this Visio trial are Microsoft Windows XP with Service Pack 2, Windows server 2003 or higher. 1. Insert the Visio CD-ROM found at the back of your text into your CD drive. 2. When the Setup Wizard asks for your product key, enter the product key, which can be found on the CD-ROMs envelope, and click Next. 3. Follow the prompts in the Setup Wizard. 4. Open Visio from the Start menu. It may appear in the Microsoft Office menu. 5. Activate your trial version after you open Visio.

19

Note: If youve never worked with Visio before, you should visit the Beginners Guide pages at http://office.microsoft.com/enus/visio/HA102144941033.aspx?pid=CH100650391033 For this graded project, youll produce the following items:

A print chart A hierarchy chart A flowchart Pseudocode

Scenario
Mr. Simon, the owner of a local gift store, has asked you to create an inventory file for his store, called Inventory. He wants you to create a report that lists each item by stock number, description, and profit. The profit is the retail price minus the wholesale price. The file fields are stock number, description, wholesale price, and retail price. The following chart shows the data for the input file:
File name: FURNITURE FIELD DESCRIPTION Stock Number Description Wholesale Price Retail Price POSITIONS 14 529 3035 3641 DATA TYPE Numeric Character Numeric Numeric 2 2 DECIMALS 0

1. Create a print chart for this program using the data shown in the chart. Hint: You can insert a table or use an Excel spreadsheet to create this print chart. 2. Create a hierarchy chart for this program using the data shown in the chart. Hint: Use Visio or Microsoft Words Drawing toolbar. 3. Create a flowchart for this program using the data shown in the chart. Hint: Use Visio or Microsoft Words Drawing toolbar. 4. Create the pseudocode for this program using the data shown in the chart.

20

Graded Project, Lesson 1

When youre satisfied with your completed project, e-mail the project to your instructor for grading by going to http://www.takeexamsonline.com. Make sure you include the project number, 41880000, to identify the project. Your instructor will use the following grading guidelines to grade your project:
Created the print chart Created the hierarchy chart Created the flowchart Created the pseudocode Total 20 points _______ 20 points _______ 30 points _______ 30 points _______ 100 points _______

Graded Project, Lesson 1

21

NOTES

22

Graded Project, Lesson 1

Making Decisions and Special Situations

Lesson 2 Lesson 2

In this lesson, youll learn how to create and structure decisions in your programs. Youll learn when to use looptype structures in your programs and how to create loops. Youll learn about arrays, or lists of variables, and when theyre appropriate. Youll also learn about using methods. When you complete this lesson, youll be able to

Insert Boolean expressions for comparisons Use case structures and decision tables Use a while loop, a for loop, a do until loop, and nested loops Declare and initialize different types of arrays Using methods

ASSIGNMENT 4: MAKING DECISIONS


Read the assignment; then read pages 135192 in your textbook. When youre comfortable with the material presented in the text, take the self-check to gauge your progress. If there are any areas you dont feel comfortable with, reread those sections in the textbook before returning to the study guide. When you feel youve mastered the material in Chapter 4, move on to the next assignment.

You can design a computer program that makes decisions and then performs tasks accordingly. The way to program these decisions is with Boolean expressions. With Boolean expressions, two scenarios are possibleone true and one false, which are indicated by a 0 or a 1. For instance, for the expression Is this number greater than 10?, you may assign the number 0 to yes and 1 to no. Keep the following tips in mind when using Boolean expressions:

23

If there are two possible outcomes, use a dual-alternative (or binary) selection. This selection is also called an ifthen-else structure, because if one condition is true, the program does one thing; if it isnt true, then it does something else. If theres only one possible outcome, use a singlealternative (or unary) selection. This selection is also called an if-then structure, because the program does only one thing.

The following table (Table 1) lists some typical Boolean operators. Note that some programming languages vary in their use of Boolean operators.

Table 1 BOOLEAN OPERATORS Operator = > < The two values are equal. The first value is greater than the second value. The first value is less than the second value. The first value is greater than or equal to the second value. The first value is less than or equal to the second value. The first value is not equal to the second value. Description

An AND decision is a situation in which two conditions are true, such as a worker being both full-time AND having worked at the company for more than five years. AND decisions need a nested decision or a nested if, so you should ask one question before another. Generally, you first should ask the question less likely to be true to speed the processing of the program. AND decisions are usually represented by the AND operator. Similarly, you can use an OR decision when you want to execute an action if one or another condition is true. For instance, a worker is full-time OR the worker has worked at the company for more than five years. However, in this case, you first ask the question more likely to be true.

24

Introduction to Programming

In a range check, you can designate a range of values over which you would like to compare your values, such as looking at a group of people over 65. To perform a range check, you would compare your input data with either the lowest or highest number in the range. Most programming languages allow you to combine AND and OR statements in expressions. In such expressions, AND statements have precedence because theyre executed first. An alternative structure you may like to use in some situations is a case structure. A case structure is an alternative to using a series of decisions based on a value for one variable. Finally, you can stay organized by using decision tables when multiple decisions must be made. A decision table contains the following four parts:

Conditions Possible combinations of Boolean values for the conditions Possible actions based on the conditions Specific actions that correspond to Boolean values for each condition

Read the Chapter Summary on page 179 and then review the Key Terms on pages 179180. Answer the Review Questions on pages 180185 and work through Find the Bugs on pages 185186. Then complete Exercises 1 and 5 presented on pages 187188, and find the answers to the Detective Work questions on page 192. When you feel youve mastered the material in this assignment, complete Self-Check 4. Answers to the self-check questions are provided at the end of this study guide. Answers to the Review Questions, Find the Bugs, Exercises, and Detective Work are on the Web.

Lesson 2

25

Self-Check 4
14: Indicate whether the following statements are True or False. ______ 1. In all programming languages, a single equal sign (=) means that the first value is equal to the second. ______ 2. Boolean statements are a series of alternative structures you can use in certain situations. ______ 3. A common error in range checks is asking too many questions. ______ 4. Binary selections are also called if-then-else statements. 5. _______ operators have precedence over _______ operators. 6. A problem-analysis tool having four partsconditions, possible combinations, specific actions, or possible actionsis a/an _______. 7. A/an _______ selection requires a nested decision or a nested if. 8. When you program, what symbol would you use to represent that one value is not equal to another value? __________________________________________________________________________ Check your answers with those on page 74.

26

Introduction to Programming

ASSIGNMENT 5: LOOPING
Read the assignment and then read pages 193236 in your textbook. When youre comfortable with the material presented in the text, take the self-check to gauge your progress. If there are any areas you dont feel comfortable with, reread those sections in the textbook before returning to the study guide. When you feel youve mastered the material in Chapter 5, move on to the next assignment.

Looping is a key feature of computer programming. It enables you to create instructions for working with multiple sets of data. For example, you can create a program for a payroll program. By including a loop, you can run through your instructions on how to determine pay, overtime, tax withholding, Social Security deductions, and so on for one employee after another (Figure 6).
FIGURE 6Basic Loop Structure

Decision

Process

Loop control variables determine whether the program should continue using the loop or not. You stop a loop by comparing a loop control value with a sentinel value. Another way to control looping is to use a counter. You can use a counter to keep track of how many times an event has occurred. You can increment, or add to, the variable. Likewise, you can decrement, or subtract from, the variable. You can also control looping with a variable sentinel value, which means that the value youre using in your loop can change.

Lesson 2

27

Two specific types of loops are the for loop and the do until/do while loop. Characteristics of these loops are listed below.

The for loop automatically initializes, evaluates, and increments by using a loop control variable. You can use for loops only if you know in advance how many times the loop will repeat. The do until/do while loop ensures that the loop runs at least once.

In structured loops, the loop-controlling question provides an entry to or exit from the structure. This entry or exit is the only entry to or exit from the structure. A loop within a loop is called a nested loop. The loop thats within another loop is called the inner loop; the outer one is called the outer loop. You also can use a loop to add, or accumulate, totals. You would use a variable called an accumulator, which is like a counter, but you can use it to add a value other than one. (With a counter, you can increment only by one.) A report that lists no details except the final values is called a summary report. For example, a bill that lists the total of what you owe and not the individual charges is a summary report. Read the Chapter Summary on page 227 and then review the Key Terms on pages 227228. Answer the Review Questions on pages 228231 and work through Find the Bugs on page 232. Then complete Exercises 2 and 5 presented on pages 232233, and find the answers to the Detective Work questions on page 236. When you feel youve mastered the material in this assignment, complete Self-Check 5. Answers to the self-check questions are provided at the end of this study guide. Answers to the Review Questions, Find the Bugs, Exercises, and Detective Work are on the Web.

28

Introduction to Programming

Self-Check 5
14: indicate whether the following statements are True or False. ______ 1. A common mistake when writing loops is not initializing the loop control variable. ______ 2. The for loop ensures that the loop executes at least once. ______ 3. All loops contain a question that provides entry to or exit from the structure. ______ 4. Looping is a type of structure. 5. What type of variable determines whether a loop will continue? __________________________________________________________________________ __________________________________________________________________________ 6. Adding 1 to a variable is called _______; decreasing a variable by 1 is called _______. 7. What are loops within loops called? __________________________________________________________________________ 8. The number of times a loop repeats depends on a _______. Check your answers with those on page 74.

Lesson 2

29

ASSIGNMENT 6: ARRAYS
Read the assignment and then read pages 237283 in your textbook. When youre comfortable with the material presented in the text, take the self-check to gauge your progress. If there are any areas you dont feel comfortable with, reread those sections in the textbook before returning to the study guide. When you feel youve mastered the material in Chapter 6, complete the graded project for this lesson.

Arrays are lists of variables in the computers memory that have the same name. Theyre distinguished from each other by subscripts or numbers that indicate the variables position in the array. An example of an array is a set of file folders in a file cabinet that are alphabetized from A through Z. Declaring an array involves declaring a program structure with multiple variables. Each variable is an element that has the same name and same data type. You also must declare the size of the array, which determines how many elements the array can contain. A simple way to declare and initialize an array is to write one statement that tells the type, name, and quantity of elements for the array. Some special types of arrays include the following:

VariableWhere values of the variable change when the program runs or is executed Constant arraysArrays where the final desired values are fixed at the beginning of the program Parallel arraysThese arrays involve two arrays where each element in the first array is associated with the element in the same position in the second array.

When searching for an array to find a value, you need to 1. Initialize a subscript 2. Use a loop to test each array element 3. Set a flag for when a match is found

30

Introduction to Programming

Also, keep the following in mind when creating arrays:

You often can replace multiple nested decisions by using a variable as a subscript to an array. Make sure your subscript values dont go out of the range of legal subscripts. When comparing a value with a range of values in an array, store either the highest or lowest value of the range for comparison.

Read the Chapter Summary on page 271 and then review the Key Terms on pages 271272. Answer the Review Questions on pages 272275 and work through Find the Bugs on pages 275276. Then complete Exercises 4, 5, and 6 presented on pages 276278, and find the answers to the Detective Work questions on page 283. When you feel youve mastered the material in this assignment, complete Self-Check 6. Answers to the self-check questions are provided at the end of this study guide. Answers to the Review Questions, Find the Bugs, Exercises, and Detective Work are on the Web.

Lesson 2

31

Self-Check 6
14: Indicate whether the following statements are True or False. ______ 1. Leaving a loop when a match is found is called an early exit. ______ 2. A compile-time array uses two arrays. ______ 3. The values in a variable array are created when the program is executed. ______ 4. When declaring an array, you must set the size of the array. 5. A/an _______ arrays values are fixed at the beginning of the program. 6. A variable that tells you something has occurred is called a/an _______. 7. An array variable is one _______ of the array. 8. A/an _______ provides initial values for every element in the array. Check your answers with those on page 74.

32

Introduction to Programming

ASSIGNMENT 7: USING METHODS


Read this assignment and then read pages 285337 in your textbook. When youre comfortable with the material presented in your text, take the self-check to gauge your progress. If there are any areas you dont feel comfortable with, reread those sections in the textbook before returning to the study guide. When you feel youve mastered the material in Chapter 7, move on to the next assignment.

Back in Chapter 3, you learned about methods, or program modules with statements to carry out a task. To refresh your memory, Chapter 7 begins with a summary of what you learned about methods. For instance, a method must include a header, body, and return statement. Youll then read about methods that require a single parameter. When writing these parameters, you include two things within the methods parentheses:

The type of parameter A local name for the parameter

When creating methods that require more than one parameter, you also indicate their data types and local names within the parentheses, only you separate the parameters by commas. Next youll read about creating methods that return values. You use this type of method when you want to send the value from a method back to the method that called it. In this type of method, you include a return type, which can be a number, character, string, and others types depending on the program language. In the last chapter, you read about how you can use arrays to hold variables. Besides passing variables or constants to methods, you can also pass arrays. In overloading methods, one identifier can take on different meanings depending on the arguments calling the method. Multiple methods have a shared name, but different parameter lists. A problem you may run into when overloading methods is that you may create ambiguous methods, meaning the

Lesson 2

33

compiler cant decide which method to use. To avoid this problem, you can create different parameter lists for methods with the same name. Modern programming languages include prewritten methods you can use, for instance, to write a line or print something. To use one of these built-in methods, make sure you know the following:

What the method does The methods name The methods required parameters The methods return type

To help you plan the logic of your programs, you may want to create an IPO chart. These tools help to identify and categorize items in the module. Lastly, youll read about two things to strive for when creating your programs:

Reducing coupling Increasing cohesion

Coupling measures the strength of a connection between two program modules. The tighter the cohesion, the more likely the errors. Cohesion refers to the statements and how they serve the purpose of a module. When you increase cohesion, operations are related to each other. Modules with high cohesion are more reliable, stronger, and make programs easier to read, write, and maintain. Read the Chapter Summary on page 324 and then review the Key Terms on page 325. Answer the Review Questions on page 326 and work through Find the Bugs on page 330. Then complete Exercises 2 and 7 presented on pages 332-333, and find the answers to the Detective Work questions 1 and 2 on page 336. When you feel youve mastered the material in this assignment, complete Self-Check 7. Answers to the self-check questions are provided at the end of the study guide. Answers to the Review Questions, Find the Bugs, Exercises, and Detective Work are on the Web.

34

Introduction to Programming

After you complete the self-check and have reviewed the material presented in Lesson 2, complete the graded project. After you complete the graded project, move on to Lesson 3.

Self-Check 7
14: Indicate whether the following statements are True or False. ______ 1. You can pass an array to a method. ______ 2. You can create methods with single or multiple parameters. ______ 3. The prewritten method printline is understood in all languages. ______ 4. You want your modules to depend on each other, or by tightly coupled. 5. Methods with shared names but different parameter lists are considered _______. 6. A method that returns nothing is known as a _______ method. 7. If a module has high _______, its stronger, more reliable, and easier to maintain. 8. If a compiler cant determine which method to use after youve overloaded a method, youve created a/an ________ method. Check your answers with those on page 75.

Lesson 2

35

NOTES

36

Introduction to Programming

Lesson 2 Making Decisions and Special Situations

G r a d e d P r o je c t G r a d e d P r o je ct

PROJECT NUMBER:

41880100
When you feel confident that you have mastered the material in this lesson, go to http://www.takeexamsonline.com and submit your answers online. Submit your answers for this graded project as soon as you complete it. Do not wait until another graded project is ready.

For this graded project, youll complete several tasks to test your knowledge of the material youve learned in this course so far. If youve read all of the material in each assignment and have completed the exercises in the text, you shouldnt have any problems successfully completing these tasks. For this graded project, youll generate the following:

A print chart A hierarchy chart A flowchart Pseudocode

37

Scenario
Minihan Sales employs seven salespeople. Each salesperson has an ID number, as shown in the following table:
ID Number 103 104 201 319 367 375 400 Name Edwards Rogers Krybek Delaney LaFleur Smith Black

When a salesperson makes a sale, a record is created that includes the date, time, and dollar amount of the sale, as shown in the following table. Note that time is expressed in hours and minutes, based on a 24-hour clock. The sale amount is expressed in whole dollars.
Field Description Salesperson Month D ay Year Time Sale amount Positions 13 45 67 811 1215 1622 Data Type Numeric Numeric Numeric Numeric Numeric Numeric Decimals 0 0 0 0 0 0 Examples 319 02 21 2008 13 15 95900

Sale Amount $0 to $50,000 $51,000 to $125,000 $126,000 to $200,000 $201,000 and up

Rate .04 .05 .06 .07

38

Graded Project, Lesson 2

Youll design a print chart, a hierarchy chart, a flowchart, and pseudocode that produces a report that lists the total sales and total commissions earned by all salespeople for time frames based on the hour of the day (0005, 0612, 1318, and 1923). 1. Create a print chart for this program using the data provided. Hint: You can insert a table or use an Excel spreadsheet to create this print chart. 2. Create a hierarchy chart for this program using the data provided. Hint: Use Visio or Microsoft Words Drawing toolbar. 3. Create a flowchart for this program using the data from the data provided. Hint: Use Visio or Microsoft Words Drawing toolbar. 4. Create the pseudocode for this program using the data provided. When youre satisfied with your completed project, e-mail the project to your instructor for grading by going to http://www.takeexamsonline.com. Make sure you include the project number, 41880100, to identify the project. Your instructor will use the following grading guidelines to grade your project:

Created the print chart Created the hierarchy chart Created the flowchart Created the pseudocode Total

20 points _______ 20 points _______ 30 points _______ 30 points _______ 100 points _______

Graded Project, Lesson 2

39

NOTES

40

Graded Project, Lesson 2

Advanced Programming Techniques

Lesson 3 Lesson 3

In this lesson, youll learn some advanced programming techniques. First, youll learn about control breaks, which occur when the program pauses to accomplish something else. Youll learn some advanced array manipulation techniques. Youll then learn how to create menus and submenus in your programs. Then, youll learn about sequential file merging, which consists of combining two or more files. Finally, youll learn some advanced modularization techniques. When you complete this lesson, youll be able to

Insert control breaks Validate user input Create master files Merge, match, and update files Pass and call values to or from a module

ASSIGNMENT 8: CONTROL BREAKS


Read the assignment and then read pages 339384 in your textbook. When youre comfortable with the material presented in the text, take the self-check to gauge your progress. If there are any areas you dont feel comfortable with, reread those sections in the textbook before returning to the study guide. When you feel youve mastered the material in Chapter 8, move on to the next assignment.

A control break occurs when a programs logic takes a temporary detour. For example, if you create an inventory for a CD store with CDs arranged by categories and you have a subtotal for the retail amount of each category, youve created a control break report. Another example of a control break would be placing page breaks in your report after each group of data, such as CD category. Control break reports must be arranged in a sequential order.

41

If your data involve comparing data from one record to see if it matches another, you can create a control break field, which is a special variable that remembers the data a variable is being compared with. Sometimes you may need to put control data within the control break module itself, such as in a heading or footer. Say, for instance, that your CD inventory reports page title reads Department category(), where category() stands for the CD category, such as Classical or Rock. You can use control data to print the appropriate department. A complete single-level control break report can be set up to perform the following tasks:

Print totals for previous groups of data Roll up the current-level totals to the next level Reset the current level totals to zero Perform other control break processing, if necessary Update the control break field

In a multiple-level control break report, the control breaks away for special processing. Read the Chapter Summary on page 372 and then review the Key Terms on pages 372373. Answer the Review Questions on pages 373378 and work through Find the Bugs on pages 378380. Then complete Exercises 1 and 3 presented on pages 380381, and find the answer to the Detective Work question on page 383. When you feel youve mastered the material in this assignment, complete Self-Check 8. Answers to the self-check questions are provided at the end of this study guide. Answers to the Review Questions, Find the Bugs, Exercises, and Detective Work are on the Web.

42

Introduction to Programming

Self-Check 8
14: Indicate whether the following statements are True or False. ______ 1. A control break program can print totals. ______ 2. Control breaks can be performed only in response to a change in one condition. ______ 3. Control data can be used only in the body of a report, not headers or footers. ______ 4. Control break reports must be arranged in a sequential order. 5. A report that prints only group totals and not information about individual records is called a/an _______. 6. A temporary detour in a programs logic is known as a/an _______. 7. A variable that remembers data is called a/an _______. 8. A break in a programs logic according to one variable is known as a/an _______. Check your answers with those on page 75.

Lesson 3

43

ASSIGNMENT 9: ADVANCED ARRAY MANIPULATION


Read this assignment and then read pages 385432 in your textbook. When youre comfortable with the material presented in the text, take the self-check to gauge your progress. If there are any areas you dont feel comfortable with, reread those sections in the textbook before returning to the study guide. When you feel youve mastered the material in Chapter 9, move on to the next assignment.

To keep your records organized, you may want to sort them in sequential order. The order you choose may be ascending (e.g., A to Z) or descending (e.g., Z to A) (Figure 7). Sometimes when you sort records you may have to swap two values, in which case you can create a temporary variable to hold one of the variables while you swap them.
FIGURE 7Fruit Arranged in Ascending Order

Apples Bananas Cantaloupe Grapes Pears Plums Raspberries

A bubble sort is a simple kind of sorting technique where pairs of list items are compared. With this kind of sort, one item is swapped with the one below it (ascending bubble sort) or the one above it (descending bubble sort).

44

Introduction to Programming

Keep the following guidelines in mind when using bubble sorts:

You perform one fewer pair comparison than there are elements. For example, if you have 10 elements, you make only 9 comparisons. To avoid unnecessary comparisons, add a flag to determine if elements have been sorted correctly.

Other types of sorts can also be used, including

Insertion sortAn insertion sort also looks at pairs of elements in an array. If it finds an element thats out of order, it moves backward until it locates a smaller element. A new position is then created for the out-of-order element, and all elements following it move down one position. Selection sortAn ascending selection sort assumes that the first element is the smallest and stores its position. Each element is then tested, and if an element is smaller than the first value, it switches with the first element. That value is then compared with other elements. IndexesAn index sorts data in a physical order that may differ from a logical order. For instance, a book index may be arranged alphabetically, though it doesnt provide any information about the topics. In an index, you store key fields that have the storage record for the records. Linked listsA linked list involves creating an extra field for each record to hold the address of the next item in the list.

You may want to consider using multidimensional arrays if youre using table or grid data with rows and columns rather than a list. Multidimensional arrays are useful if the value in an array depends on two or more variables. Multidimensional data are usually two-dimensional, and in some languages they can be three-dimensional.

Lesson 3

45

Read the Chapter Summary on page 420 and then review the Key Terms on page 421. Answer the Review Questions on pages 422425 and work through Find the Bugs on pages 426427. Then complete Exercises 1 and 7 presented on pages 428429, and find the answers to the Detective Work questions on page 432. When you feel youve mastered the material in this assignment, complete Self-Check 9. Answers to the self-check questions are provided at the end of this study guide. Answers to the Review Questions, Find the Bugs, Exercises, and Detective Work are on the Web.

46

Introduction to Programming

Self-Check 9
14: Indicate whether the following statements are True or False. ______ 1. With a bubble sort, theres one fewer comparison than the total number of elements. ______ 2. Multidimensional arrays are used for one-column list data. ______ 3. A bubble sort is a type of insertion sort. ______ 4. In an ascending selection sort, the first item is assumed to be the smallest. 5. What type of sort requires that an extra field be added? __________________________________________________________________________ __________________________________________________________________________ 6. Sorting from A to Z is an example of sorting in _______ order. Sorting from Z to A is an example of sorting in _______ order. 7. A/An _______ sorts files according to physical order rather than logical order. 8. To eliminate unnecessary passes in a bubble sort, you can create a/an _______. Check your answers with those on page 75.

Lesson 3

47

ASSIGNMENT 10: SEQUENTIAL FILE MERGING, MATCHING, AND UPDATING


Read the assignment and then read pages 433484 in your textbook. When youre comfortable with the material presented in the text, take the self-check to gauge your progress. If there are any areas you dont feel comfortable with, reread those sections in the textbook before returning to the study guide. When you feel youve mastered the material in Chapter 10, move on to the lesson graded project.

In a sequential file, files are stored in order, one after another, as in a customer log where customers are filed alphabetically by last name. Sometimes you may want to merge two or more files into one file while maintaining the sequential order. For example, say you have a customer list and your Webmaster sends you a list of new customers who recently purchased your product over the Internet. You want to merge these two files in order to update your customer file. To merge files, the files must meet the following conditions:

The files must have the same record layout. The files must be sorted in the same order according to the same field (e.g., alphabetically by last name).

The logic for creating a merge program is one youve used before.

A housekeeping() module A mainLoop() module A finishUp() module

Following are some of the steps youll take in creating a merge program. In the housekeeping() module, you declare a flag variable that turns on when two or more files have been inputted. The mainLoop() module then compares records from the files to be merged.

48

Introduction to Programming

In some situations, you may have a need for a master file and a transaction file. A master file holds somewhat permanent data, whereas a transaction file holds temporary data. For example, a library may have a master file of all its patrons and a separate transaction file of items that are currently checked out. Because the file of checked-out items will change, its temporary; the master file is more permanent. To update a master file, you can either

Change the information in the master file, or Copy the master file and make the changes to the copy

In the text, youll read other examples of master and transaction files as well as ways to update master files. Read the Chapter Summary on page 470 and then review the Key Terms on page 471. Answer the Review Questions on pages 472475 and work through Find the Bugs on pages 476477. Then complete Exercises 3 and 6 presented on pages 478479 and find the answers to the Detective Work questions on page 483. When you feel youve mastered the material in this assignment, complete Self-Check 10. Answers to the self-check questions are provided at the end of this study guide. Answers to the Review Questions, Find the Bugs, Exercises, and Detective Work are on the Web. After you complete the self-check and have reviewed the material presented in Lesson 3, complete the graded project. After you complete the graded project, move on to Lesson 4.

Lesson 3

49

Self-Check 10
14: Indicate whether the following statements are True or False. ______ 1. The logic for a merge program includes housekeeping(), mainLoop(), and finishUp() modules. ______ 2. One master file record can have more than one transaction. ______ 3. You can create a program either to make changes to master files OR to add or delete records, but not both; you would need a copy of the master file to process both tasks. ______ 4. The mainLoop() module in a merge file includes a flag that checks for the end of file data. 5. _______ files involves keeping the same order while combining two or more files. 6. A/An_______ file holds somewhat permanent data; a/an _______ file holds temporary data. 7. Items are stored together in _______ order when theyre arranged in some sort of order, such as alphabetically or numerically. 8. Items are stored together in _______ order when theyre arranged based on time. Check your answers with those on page 76.

50

Introduction to Programming

Lesson 3 Advanced Programming Techniques


PROJECT NUMBER:

G r a d e d P r o je c t G r a d e d P r o je ct

41880200
When you feel confident that you have mastered the material in this lesson, go to http://www.takeexamsonline.com and submit your answers online. Submit your answers for this graded project as soon as you complete it. Do not wait until another graded project is ready.

For this graded project, youll complete several tasks to test your knowledge of the material youve learned in this course so far. If youve read all of the material in each assignment and have completed the exercises in the text, you shouldnt have any problems successfully completing the tasks. For this graded project, youll read two scenarios and complete a variety of tasks.

Scenario 1
A gift shop has stored the following information about its customers:

First name Last name Address Amount spent on a yearly basis

The store manager wants you to create a program that will identify the top 100 customers so she can send them a thank-you mug with the stores logo.

51

1. Create a flowchart for a program that will sort the top 1,000 customers by their annual purchase amount and print the names and addresses of the top 100 customers, or fewer if there arent 100 customers.

Scenario 2
The students in two junior high schools in your district, Jefferson and Audubon, are being merged into one school. Student files contain the following information:

Student ID Last name First name Address

The files are sorted by student ID number. 1. Create a scenario for a program that merges these two student files into one file, keeping the files in order by student ID number. When youre satisfied with your completed project, e-mail the project to your instructor for grading by going to http://www.takeexamsonline.com. Make sure you include the project number, 41880200, to identify the project. Your instructor will use the following grading guidelines to grade your project:
Created the flowchart for Scenario 1 Created the pseudocode for Scenario 2 Total 50 points _______ 50 points _______ 100 points _______

52

Graded Project, Lesson 3

More Advanced Programming

Lesson 4 Lesson 4

Welcome to the final lesson in this course. Youve learned many valuable lessons on programming and logic. In this final lesson, youll learn more advanced programming techniques. First youll learn about object-oriented programming. Youll then explore event-driven programming, system modeling, and relational databases. Congratulations for making it to this point! Youve nearly completed this course. When you complete this lesson, youll be able to

Design object-oriented programs Create event-driven programs Design graphical user interfaces Use UML diagrams for system modeling Create databases and tables Write queries

ASSIGNMENT 11: OBJECTORIENTED PROGRAMMING


Read the assignment and then read pages 485545 in your textbook. When youre comfortable with the material presented in the text, take the self-check to gauge your progress. If there are any areas you dont feel comfortable with, reread those sections in the textbook before returning to the study guide. When you feel youve mastered the material in Chapter 11, move on to the next assignment.

In this assignment, youll learn about object-oriented programming, which concentrates on an applications data and the methods you need to work with the data. Object-oriented programming has the following traits:

It has classes and objects. Messages are passed to objects. Messages may work differently on different objects.

53

Objects can share or inherit traits of other objects. It offers encapsulation and information hiding.

Object-oriented programming also incorporates the following four concepts:


ClassesCategories of objects with common attributes ObjectsItems in a class InheritanceTraits are acquired from predecessors PolymorphismAn operation works differently depending on the context

All classes have names; some have data and/or methods. You can display your classes in a class diagram, as shown in Figure 8.
FIGURE 8A class diagram is divided into three sections.

Class Name

Attributes

Methods

Classes generally contain data, which is private, and methods, which are public. With object-oriented programming, you can instantiate an object. With instantiation, you create a class object that has a statement that includes the type of object and the objects name. Inheritance is an important aspect of object-oriented programming. When you create descendent classes, they take on the attributes of the original class. This is handy for reusing data. You can also think of inheritance as a parent/child relationship; the original class is the parent and the new class is a child that inherits traits from the parent.

54

Introduction to Programming

With polymorphism, the same request can have a different effect depending on the context. This trait is specific to object-oriented programming. A method with the same name as its class is a constructor method. Its called every time an object in that class is instantiated. Alternatively, with destructor methods, a method is executed when an object is destroyed. Read the Chapter Summary on page 533 and then review the Key Terms on pages 534536. Answer the Review Questions on pages 536539 and work through Find the Bugs on pages 539540. Then complete Exercises 1, 2, and 4 presented on page 540, and find the answers to the Detective Work questions on page 545. When you feel youve mastered the material in this assignment, complete Self-Check 11. Answers to the self-check questions are provided at the end of this study guide. Answers to the Review Questions, Find the Bugs, Exercises, and Detective Work are on the Web.

Lesson 4

55

Self-Check 11
14: Indicate whether the following statements are True or False. ______ 1. A constructor method has the same name as its class. ______ 2. Polymorphism means that the same request is carried out differently in different situations. ______ 3. Inheritance involves the creation of an object by stating the object type and name. ______ 4. Object-oriented programming focuses on the procedures needed to accomplish a goal. 5. Built-in classes that come with prepackaged software are stored in _______. 6. Methods that execute upon the destruction of an object are called _______. 7. Classes are made up of _______. 8. Original classes can be thought of as _______ classes; descendent classes can be thought of as _______ classes. Check your answers with those on page 76.

56

Introduction to Programming

ASSIGNMENT 12: EVENT-DRIVEN PROGRAMMING WITH GRAPHICAL USER INTERFACES


Read the assignment and then read pages 547587 in your textbook. When youre comfortable with the material presented in the text, take the self-check to gauge your progress. If there are any areas you dont feel comfortable with, reread those sections in the textbook before returning to the study guide. When you feel youve mastered the material in Chapter 12, move on to the next assignment.

Event-driven programming involves using a graphical user interface (GUI) rather than typing commands in the command line. An example of a GUI youre probably familiar with is the Windows Operating System GUI, which features icons and menus that you click on with your mouse (Figure 9). Eventdriven programs use sources and listeners. For instance, if you click on a menu item (the source), the program waits for (or listens to) the command so it knows when to respond.

FIGURE 9The Windows Operating System GUI

Lesson 4

57

Common user events include the following:


Key press Mouse point Click Right-click Double-click Drag

The following are just a few of the GUI components that you can include in your applications:

Labels Text fields Buttons Check boxes Option buttons List boxes

Keep the following guidelines in mind when designing GUIs:


Make the interface natural and predictable. Make the screen attractive and user-friendly. Let your users customize the applications, if possible. Let your program be forgiving. Remember that the GUI is only a means to an end.

Creating an event-driven application involves a number of different steps, including the following: 1. Understand the problem. 2. Create storyboards. 3. Define objects. 4. Define connections. 5. Plan logic. 6. Code the program. 7. Translate the program into machine language.

58

Introduction to Programming

8. Test the program. 9. Put the program into production. Lastly, event-driven programs use a type of error checking called exception-handling or exceptions. An exception occurs when an object is thrown from one module to another module that catches it and takes care of the problem. Read the Chapter Summary on page 578 and then review the Key Terms on pages 579580. Answer the Review Questions on pages 580582 and work through Find the Bugs on pages 583584. Then complete Exercises 3 and 8 presented on pages 584585, and find the answers to the Detective Work questions on page 587. When you feel youve mastered the material in this assignment, complete Self-Check 12. Answers to the self-check questions are provided at the end of this study guide. Answers to the Review Questions, Find the Bugs, Exercises, and Detective Work are on the Web.

Lesson 4

59

Self-Check 12
14: Indicate whether the following statements are True or False. ______ 1. You can define your connections between screens by creating an interactivity diagram to depict relationships. ______ 2. The first step in designing any computer program is to understand the problem. ______ 3. In error handling with exceptions, one module searches for data while another one handles it. ______ 4. A good guideline to follow when developing event-driven applications is to make sure that the user cant modify the application in any way. 5. With a/an _______ interface, icons and menus are used instead of command lines. 6. A GUI component that the user can type text into is called a/an _______. 7. In object-oriented programming, error handling involves one module _______ the exception to another that _______ it. 8. A component from which an event is generated is the _______ of the event. Check your answers with those on page 76.

60

Introduction to Programming

ASSIGNMENT 13: SYSTEM MODELING WITH UML


Read this assignment and then read pages 589619 in your textbook. When youre comfortable with the material presented in the text, take the self-check to gauge your progress. If there are any areas you dont feel comfortable with, reread those sections in the textbook before returning to the study guide. When you feel youve mastered the material in Chapter 13, move on to the next assignment.

For most of this course, youve been learning how to create individual programs. System design refers to the way that all programs in a computer system work together. You could take an entire course on how to create good system design. This assignment concentrates on UML and how you can use it to create sound systems. UML (Unified Modeling Language) is a standard way for people to communicate when discussing system design. Its used to specify, construct, and document object-oriented method systems. Note that UML is a modeling language, not a programming language. UML has its own notation thats used to create diagrams to model different system types. Table 3 lists the nine types of UML diagrams and when theyre used. Youll read more about each type of diagram in your text.
Table 3 TYPES OF UML DIAGRAMS
UML Diagrams Use case diagrams Class diagrams Object diagram Sequence diagram Communication diagram State machine diagram Activity diagram Component diagram Deployment diagram Description Shows how a business works from an outside perspective Illustrates classes by showing their names, attributes, and methods Illustrates classes as in a class diagram, but at one point in time Shows event timing Illustrates object organization for a system Shows class or object status at different points in time Illustrates a systems action flow Shows a systems files, database tables, documents, etc. Displays a systems hardware

Lesson 4

61

Which type of diagram you should use will depend on what you want to communicate. You may want to combine one or more types of UML diagrams to convey how your system works to others. Read the Chapter Summary on page 612 and then review the Key Terms on pages 612614. Answer the Review Questions on pages 614616. Then complete Exercises 1 and 6 presented on pages 617618, and find the answers to the Detective Work questions on page 619. When you feel youve mastered the material in this assignment, complete Self-Check 13. Answers to the self-check questions are provided at the end of this study guide. Answers to the Review Questions, Exercises, and Detective Work are on the Web.

62

Introduction to Programming

Self-Check 13
14: Indicate whether the following statements are True or False. ______ 1. To develop good system design, communication among programmers is important. ______ 2. If you want to show the order of events for a single-use case, you should use a collaboration diagram. ______ 3. Object diagrams and class diagrams are similar, except that the class diagram concentrates on one instance. ______ 4. You can elide information from your diagrams to display information more clearly. 5. What type of UML diagram would you use to show what your classes are doing at different points in time? __________________________________________________________________________ __________________________________________________________________________ 6. What type of UML diagram would you use to show the files and tables used by a system? __________________________________________________________________________ __________________________________________________________________________
(Continued)

Lesson 4

63

Self-Check 13
7. What two types of relationships can you show in a class diagram? __________________________________________________________________________ __________________________________________________________________________ 8. What are the three types of use case variations? __________________________________________________________________________ __________________________________________________________________________ __________________________________________________________________________ Check your answers with those on page 77.

64

Introduction to Programming

ASSIGNMENT 14: USING RELATIONAL DATABASES


Read the assignment and then read pages 621663 in your textbook. When youre comfortable with the material presented in the text, take the self-check to gauge your progress. If there are any areas you dont feel comfortable with, reread those sections in the textbook before returning to the study guide. When you feel youve mastered the material in Chapter 14, complete the graded project for this lesson.

In Assignment 1, you learned about data hierarchies. Databases use a data hierarchy to organize their information. Databases contain files, which are often called tables because they use rows and columns. Each field or column is called a key field. A group of database tables can be combined in a relational database. Database management software is used to manage databases. You can use this software to perform the following tasks:

Create table descriptions Identify key fields Add, delete, and update records Organize records into sorted order Write questions that select records for viewing Write questions that extract information from several tables Create reports and forms with your data Secure data

Before you create a database, you must plan it out. Youll need to decide what columns will be included in your table and provide names for them. Youll also have to determine what type of data will be contained in each column. The key column (or columns) in the database is known as the primary key.

Lesson 4

65

When creating an application, you may need to create several tables. If you create new tables, youll need to create relationships between your tables. The three types of relationships among tables are

One-to-many (one row in a table is related to many rows in another table) Many-to-many (many rows in a table are related to many rows in another table) One-to-one (one row in a table is related to exactly one row in another table)

Normalization is the process of designing database tables according to what the users need and avoiding problems such as data redundancy or anomalies. There are three types of normalization: first normal form (1NF), second normal form (2NF), and third normal form (3NF). Lastly, you want to make sure that any databases you create are secure. Many databases contain information, such as sensitive corporate information, that shouldnt be accessible to the public. The following are five major issues that should be addressed when securing a database:

Data integrity Lost-data recovery Avoiding concurrent update problems Authentication and permissions Encryption

Read the Chapter Summary on pages 652653 and then review the Key Terms on pages 653655. Answer the Review Questions on pages 655658 and work through Find the Bugs on page 659. Then complete Exercises 1 and 2 presented on pages 659660, and find the answers to the Detective Work questions on page 663. When you feel youve mastered the material in this assignment, complete Self-Check 14. Answers to the self-check questions are provided at the end of this study guide. Answers to the Review Questions, Find the Bugs, Exercises, and Detective Work are on the Web.

66

Introduction to Programming

After you complete the self-check and have reviewed the material presented in Lesson 4, complete the graded project.

Self-Check 14
14: Indicate whether the following statements are True or False. ______ 1. Keeping users needs in mind when planning and creating a database is known as normalization. ______ 2. In database notation, the table name is followed by the field names in parentheses and the primary key is underlined. ______ 3. SQL is the most common language for accessing database tables. ______ 4. In a one-to-one relationship, one row can have a relationship with several rows in one other table. 5. In what normal form are partial key dependencies eliminated? __________________________________________________________________________ __________________________________________________________________________ 6. The column or field that makes a record unique from other records is the _______. 7. The process whereby information is coded in a way that humans cant read it is called _______. 8. When data is repeated unnecessarily, its called _______. Check your answers with those on page 77.

Lesson 4

67

NOTES

68

Introduction to Programming

Lesson 4 More Advanced Programming


PROJECT NUMBER:

G r a d e d P r o je c t G r a d e d P r o je ct

41880300
When you feel confident that you have mastered the material in this lesson, go to http://www.takeexamsonline.com and submit your answers online. Submit your answers for this graded project as soon as you complete it. Do not wait until another graded project is ready.

For this graded project, youll complete several tasks to test your knowledge of the material youve learned in this course so far. If youve read all of the material in each assignment and have completed the exercises in the text, you shouldnt have any problems successfully completing the tasks. For this graded project, youll read four scenarios and complete a variety of tasks.

Scenario 1
Youve been asked to create a program for a real estate company. The program will organize the street address, price, number of bedrooms, and number of bathrooms in a house. Create a class named Home. Make sure the class Home contains the following information:

The street address The price The number of bedrooms The number of bathrooms

69

Make sure you include methods to set values for each data field. Also, dont allow negative values for the price, number of bedrooms, or number of baths. Be sure to include a method that displays Homes values. 1. Create a class diagram for this program. 2. Create pseudocode for this program.

Scenario 2
The owner of Florals by Lara has asked you to create an interactive program for her flower shop. She wants a program where the customer can choose any of the following:

A floral arrangement ($25 base price) Cut flowers ($15 base price) A corsage ($10 base price)

The customer can choose one of the following flowers as the dominant flower:

Roses Lilies Carnations Daisies

After the customer clicks Order Now, the total of the order should be displayed to the customer. 1. Design the storyboard you would use to create this program.

Scenario 3
A local bank has asked you to create a program for the following types of loans:

House Car Education

70

Graded Project, Lesson 4

1. Create a class diagram called the LoanType class and include generalizations for three classes: House, Car, and Education.

Scenario 4
The following table shows a database table that can be used to keep track of CDs. Its arranged by tblCDs (title, artist, year).
Title The Essential Nina Simone Hello Nasty Just Won't Burn Artist Nina Simone Beastie Boys Susan Tedeschi Year 1993 1998 1998

1. Redesign the table so that its in 2NF format. When youre satisfied with your completed project, e-mail the project to your instructor for grading by going to http://www.takeexamsonline.com. Make sure you include the project number, 41880300, to identify the project. Your instructor will use the following grading guidelines to grade your project:

Created the class diagram for Scenario 1 Created the pseudocode for Scenario 1 Created the storyboard for Scenario 2 Created the class diagrams for Scenario 3 Created the 2NF table for Scenario 4 Total

10 points _______ 25 points _______ 20 points _______ 25 points _______ 20 points _______ 100 points _______

Graded Project, Lesson 4

71

NOTES

72

Graded Project, Lesson 4

Self-Check 1
1. False 2. True 3. False 4. False 5. character 6. variables 7. flowchart 8. procedural programming

Answers Answers

Self-Check 2
1. False 2. True 3. False 4. False 5. Sequence, selection, loop 6. nesting 7. Loop 8. Case structure

Self-Check 3
1. True 2. True 3. False 4. False 5. hierarchy chart 6. leader, body, return statement 7. housekeeping or initializing 8. data dictionary

73

Self-Check 4
1. False 2. True 3. True 4. True 5. AND, OR 6. decision table 7. AND 8. <>

Self-Check 5
1. True 2. False 3. True 4. True 5. Loop control 6. incrementing, decrementing 7. Nested loops 8. constant

Self-Check 6
1. True 2. False 3. True 4. True 5. compile-time 6. flag 7. element 8. initializing loop

74

Answers

Self-Check 7
1. True 2. True 3. False 4. False 5. overloaded 6. void 7. cohesion 8. ambiguous

Self-Check 8
1. True 2. False 3. False 4. True 5. summary report 6. control break 7. control break field 8. single-value control break

Self-Check 9
1. True 2. False 3. False 4. True 5. Linked list 6. ascending, descending 7. index 8. flag

Answers

75

Self-Check 10
1. True 2. True 3. False 4. False 5. Merging 6. master, transaction 7. sequential 8. temporal

Self-Check 11
1. True 2. True 3. False 4. False) 5. libraries 6. destructors 7. objects 8. parent, child

Self-Check 12
1. True 2. True 3. True 4. False 5. graphical user 6. text field 7. throwing, catches 8. source

76

Answers

Self-Check 13
1. True 2. False 3. False 4. True 5. State machine 6. Component 7. Association relationship, whole-part relationship 8. Extend, include, generalization

Self-Check 14
1. True 2. True 3. True 4. False 5. Second 6. primary key 7. encryption 8. data redundancy

Answers

77

You might also like