New Perspectives on Computer Concepts 2011 Instructor’s Manual1 of 18

Computer Concepts

Chapter Twelve: Computer Programming

A Guide to this Instructor’s Manual:

We have designed this Instructor’s Manual to supplement and enhance your teaching experience through classroom activities and a cohesive chapter summary.

This document is organized chronologically, using the same heading in bluethat you see in the textbook. Under each heading you will find (in order): Lecture Notes that summarize the section, Figures and Boxes found in the section (if any), Teacher Tips, Classroom Activities, and Lab Activities. Pay special attention to teaching tips, and activities geared towards quizzing your students, enhancing their critical thinking skills, and encouraging experimentation within the software.

In addition to this Instructor’s Manual, our Instructor’s Resources CD also contains PowerPoint Presentations, Test Banks, and other supplements to aid in your teaching experience.

For your students:

Our latest online feature, CourseCasts, is a library of weekly podcasts designed to keep your students up to date with the latest in technology news. Direct your students to where they can download the most recent CourseCast onto their mp3 player. Ken Baldauf, host of CourseCasts, is a faculty member of the Florida State University Computer Science Department, where he is responsible for teaching technology classes to thousands of FSU students each year. Ken is an expert in the latest technology and sorts through and aggregates the most pertinent news and information for CourseCasts so your students can spend their time enjoying technology, rather than trying to figure it out. Open or close your lecture with a discussion based on the latest CourseCast.

Table of Contents

Chapter Objectives / 2
Section A: Programming Basics / 3
Section B: Procedural Programming / 6
Section C: Object-Oriented Programming / 8
Section D: Declarative Programming / 11
Section E: Secure Programming / 13
Glossary of Key Terms / 17

Chapter Objectives

Students will have mastered the material in Chapter Twelve when they can answer the following questions:

New Perspectives on Computer Concepts 2011 Instructor’s Manual1 of 18

  • How many lines of code are in a typical computer program?
  • Do the activities performed by computer programmers differ from those performed by software engineers and systems analysts?
  • What’s the best computer programming language?
  • What is a programming paradigm?
  • How is a computer program created?
  • What kinds of errors are discovered when programs are tested?
  • In addition to programming languages, what other tools do programmers use?
  • What is an algorithm?
  • What’s the point of flowcharts, pseudocode, and structured English?
  • How do programmers make programs do things in the right order?
  • How does object-oriented programming work?
  • How does declarative programming work?
  • Is it easy to write Prolog rules?
  • What makes computer programs vulnerable to hackers?
  • How can programmers produce more secure code?
  • Can consumers take steps to avoid vulnerabilities that exist in software with code defects?

New Perspectives on Computer Concepts 2011 Instructor’s Manual1 of 18

READING ASSIGNMENT FASTPOLL T/F QUESTIONS

120100 A line of program code typically contains a keyword or command. (Answer: True) (676)

120200 BASIC, COBOL, and C are classified as third-generation languages. (Answer: True) (677)

120300 Programming paradigms include FORTRAN and Ada. (Answer: False) (679)

120400 In a program, a variable represents a value that can change. (Answer: True) (680)

120500 VDE is an example of an object-oriented programming language. (Answer: False) (683)

120600 A programmer who omits a command word from a line of code has made a logic error. (Answer: False) (685)

120700 Programmers use a tool called an errata to step through a program to locate syntax errors. (Answer: False) (685)

120800 Pseudocode is a bug or error in a line of program code. (Answer: False) (692)

120900 A control structure specifies the sequence in which a program is executed. (Answer: True) (695)

121000 FOR…NEXT and DO…WHILE are examples of commands for loops. (Answer: True) (698)

121100 A programmer could define a class called “pizza” to solve the pizza problem using object-oriented programming. (Answer: True) (702)

121200 Inheritance, methods, messages, and polymorphism are associated with the declarative paradigm. (Answer: False) (705)

121300 Goals, rules, and instantiation are associated with the agile paradigm. (Answer: False) (718)

121400 Java is a declarative programming language. (Answer: False) (712)

121500 Prolog facts contain an argument and a predicate. (Answer: True) (714)

121600 Buffer overflows are associated with security vulnerabilities. (Answer: True) (723)

121700 Programmers can use threat modeling and formal methods to create more secure programs. (T) 725

SECTION A: PROGRAMMING BASICS (674)

SECTION A OPENER QUESTION

122100 Computer programming languages have evolved through several generations. Experts are not in agreement about what constitutes a fifth-generation programming language. What is the controversy?

  1. Some experts believe that assembly languages should be included, whereas other experts do not.
  2. Some experts believe declarative languages are fifth-generation languages, whereas other experts believe that fifth-generation languages are those that allow programmers to use graphical tools to construct programs.
  3. Most experts believe that languages like C, BASIC, and Java are fifth-generation languages, but programmers disagree because those languages follow the procedural paradigm.
  4. A few experts don’t believe there is a fifth-generation of programming languages, but most experts think that Japanese computer scientists invented fifth-generation languages when they produced C++.

(Answer: b)

Computer Programming and Software Engineering (674)

LECTURE NOTES

  • Explain that a computer program is a set of step-by-step instructions that tell a computer how to solve a problem. Have the student create a set of step-by-step instructions to solve a very simple problem, like opening their book and finding this chapter.
  • Explain that the first computer programs were written in binary code, and thus, they are often referred to as code.
  • Use Figure 12-1 to discuss a simple computer program.
  • Have students calculate how many days of coding a program they would have to spend to write Vista with 50 million lines of code at 20 lines per day. Could it be written by one person in their lifetime?
  • Discuss the difference between computer programming and software engineering.

FIGURES

  • Figure 12-1, Figure 12-2

CLASSROOM ACTIVITIES

  • Assign a Project: Review binary code. Then, have students write their name in binary code to get an idea of the complexity of writing a program in binary.
  • Quick Quiz:
  • On average, one person can write, test, and document only ______lines of code in one day. (Answer: 20)
  • True/False: Software engineers have the skills to design, code, test, and document software- but they tend to focus on designing and testing activities. (Answer: True)

Programming Languages and Paradigms (676)

LECTURE NOTES

  • Discuss the definition of a programming language.
  • Using Figure 12-3, discuss keywords and parameters. Have the student imagine what other keywords there might be.
  • Discuss the categories of programming languages.
  • Discuss how languages are categorized by low-level and high-level. Ask the students to discuss the factors that place a language in one of these categories. Do the same for program generation.
  • Look at Figure 12-7 and discuss the various languages.
  • Discuss what a programming paradigm is using Figure 12-8.

FIGURES

  • Figure 12-3, Figure 12-4, Figure 12-5, Figure 12-6, Figure 12-7, and Figure 12-8

CLASSROOM ACTIVITIES

  • Assign a Project: As an outside the class activity, have students categorize each language listed in Figure 12-7 by generation. Compare the categories in class.
  • Quick Quiz:
  1. Today, fourth-generation languages are typically used for ______applications. (Answer: database)
  2. Prolog is an example of a(n) ______generation language. (Answer: fifth)

Program Planning (680)

LECTURE NOTES

  • Discuss how you must develop a method for solving a problem, whether it is by a computer or by a human.
  • Discuss the characteristics of a good problem statement.
  • Discuss the difference between an assumption, known information, a variable, and a constant.
  • Discuss the difference between predictive methodology and agile methodology.

FIGURES

  • Figure 12-9, Figure 12-10

CLASSROOM ACTIVITIES

  1. Assign a Project: Have students write a problem statement for a problem of your choice. Perhaps use something that is happening on campus or on the news.

Program Coding (682)

LECTURE NOTES

  • Discuss a text editor. Talk about how a word processor and a text editor are not the same. Demonstrate how a text editor can be used to enter code. Show how the editor does not do any automatic indention or coloring.
  • Discuss a program editor and demonstrate it with the same program.
  • Discuss the features that a VDE (visual development environment) provides.

FIGURES

  • Figure 12-11, Figure 12-12, Figure 12-13, Figure 12-14

CLASSROOM ACTIVITIES

  • Classroom Demonstration: Write a small program in an IDE and demonstrate how it works.
  • Quick Quiz:
  • In the context of a VDE, a(n) ______is a screen-based object whose behavior can be defined by a programmer. (Answer: control)
  • True/False: A programmer can select the events that apply to each control. (Answer: True)

Program Testing and Documentation (685)

LECTURE NOTES

  • Discuss syntax and logic errors and show an example of each.
  • Discuss what a debugger does and demonstrate how it works.
  • Discuss documentation and the need of it.

FIGURES

  • Figure 12-15, Figure 12-16

CLASSROOM ACTIVITIES

  • Quick Quiz:
  1. A(n) ______error is an error in the logic or design of a program (Answer: logic)
  2. A(n) ______error shows up when you run a program. (Answer: runtime)
  3. True/False: Syntax errors are usually more difficult to identify than logic errors. (Answer: False)

Programming Tools (686)

LECTURE NOTES

  • Describe an SDK and an IDE. If you have an IDE demonstrate how it is used.
  • Discuss what components are and how they are used.
  • Describe an API. Show students the Windows API as an example.
  • Discuss how computer games are developed.

FIGURES

  • Figure 12-17, Figure 12-18

CLASSROOM ACTIVITIES

  • Quick Quiz:
  1. A(n) ______is a type of SDK that packages a set of development tools into a sleek programming application. (Answer: IDE or integrated development environment)
  2. A(n) ______is a prewritten module, typically designed to accomplish a specific task. (Answer: component)
  3. True/False: C, Java, and C++ are the most popular programming languages for commercial games. (Answer: True)

SECTION B: PROCEDURAL PROGRAMMING (689)

SECTION B OPENER QUESTION

122200 Procedural programs are based on a step-by-step algorithm. How do programmers devise the algorithms for their programs?

  1. They create objects, classes, and methods, and then figure out the step-by-step way to send messages back and forth between them.
  2. They look at APIs and VDEs, which offer templates for common program functions.
  3. They think about how a task might be carried out manually and devise flowcharts, structured English, or pseudocode to describe the steps.
  4. They first devise facts about the problem, then they come up with the steps based on rules.

(Answer: c)

Algorithms (689)

LECTURE NOTES

  • Explain that algorithms are a series of steps for carrying out a task that can be written down and implemented.
  • Use Figure 12-20 to show the steps contained in one of the pizza program algorithms. Compare this to Figure 12-21, which extends these steps and provides more detail.

FIGURES

  • Figure 12-19, Figure 12-20, Figure 12-21

CLASSROOM ACTIVITIES

  • Group Activity: Divide the class into two groups and have each group write an algorithm for a simple task that can be completed in the classroom. Have the groups exchange algorithms and attempt to carry out each other’s instructions. Were any steps left out? Was each group able to successfully complete the algorithm?
  • Quick Quiz:
  1. A(n) ______is a set of steps for carrying out a task that can be written down and implemented. (Answer: algorithm)
  2. True/False: The traditional approach to programming uses a procedural paradigm. (Answer: True)
  3. True/False: Algorithms are usually written in a format specific to a particular programming language. (Answer: False)

Expressing an Algorithm (692)

LECTURE NOTES

  • Introduce pseudocode using Figure 12-22, which shows the pizza problem algorithm expressed in pseudocode.
  • Explain that as with structured English, there are variations on the conventions used to write pseudocode, but one standard convention has the following features:
  • A limited set of non-computer language specific command words are used (e.g., display, input, IF...THEN, output).
  • The command words are often indicated in bold.
  • An arrow symbol () indicates that the value of a variable changes (e.g., SquareInches1  Size1 * Size1).
  • The = symbol is used in logical expressions (e.g., If Shape1 = “round”).
  • The commands associated with an IF...THEN statement or other control structures are indented.
  • Output messages are surrounded by quotes.
  • Figure 12-23 shows a flowchart for the pizza program. Review the flowchart symbols before you walk through the program flow.
  • Discuss what a walkthrough is and its importance.
  • Figure 12-24 shows how to conduct a walkthrough and check the pseudocode for the pizza program.

FIGURES

  • Figure 12-22, Figure 12-23, Figure 12-24

CLASSROOM ACTIVITIES

  • Assign a Project: Have students sketch a flowchart for the algorithm they created in the previous section. Make sure they correct any errors that were discovered.
  • Quick Quiz:
  1. ______is a notational system for algorithms that has been described as a mixture of English and your favorite programming language. (Answer: Pseudocode)
  2. Before finalizing the algorithm for a computer program, what should be performed? (Answer: A walkthrough)

Sequence, Selection, and Repetition Controls (695)

LECTURE NOTES

  • Discuss control structures.
  • Compare a sequence control (Figure 12-25) which changes the order of instructions the computer performs, to a selection control (Figure 12-27), which tells the computer what to do based on whether a condition is true or false.
  • Explain that repetition controls are also called loops or iterations, and repeat one or more instructions until a condition is met. The flowchart in Figure 12-28 demonstrates the looping process.
  • Discuss which types of controls you might use in the pizza program—sequence, selection, or repetition—and for what purpose. Students may need to use all types within the flowchart or program.

TEACHER TIP

Students might need some help with the sections on control structures, depending on the depth of understanding you wish them to develop. The text is written with the goal that students will be able to list the three types of control structures (sequence, selection, and repetition controls) and describe the purpose of each.

FIGURES

  • Figure 12-25, Figure 12-26, Figure 12-27, Figure 12-28, Figure 12-29

CLASSROOM ACTIVITIES

  • Quick Quiz:
  1. During ______the first instruction in the program is executed first, then the second instruction, and so on, to the last instruction in the program. (Answer: sequential execution)
  2. True/False: Control structures are instructions that specify the sequence in which a program is executed. (Answer: True)
  3. List at least two of the most frequently used repetition commands. (Answers: FOR…NEXT, DO…WHILE, DO…UNTIL, WHILE…WEND)

Procedural Languages and Applications (700)

LECTURE NOTES

  • Discuss what makes a program a procedural language.
  • List some of the most popular procedural languages.
  • Review the advantages and disadvantages of the procedural paradigm, as discussed on page 701.

TEACHER TIP

There is a tendency to classify a computer language into a single category— statements such as “COBOL is a procedural language” and “BASIC is an interpreted language” are typical. However, a computer language has many characteristics. For example, BASIC provides high-level commands, is usually interpreted, and is procedural. The approach in Chapter 12 is to apply characteristics to computer languages, rather than to attempt to classify them into a single category. You should reinforce this idea to your students.

SECTION C: OBJECT-ORIENTED PROGRAMMING (702)

SECTION C OPENER QUESTION

122300 Object-oriented programming has become quite popular. Why?

  1. It allows programmers to structure problems in a cognitively similar way as they perceive the real world.
  2. Object-oriented programs are the fastest, most efficient type of programs for today’s computer hardware.
  3. It creates the most secure programs, with the fewest security holes.

d.It is the best programming paradigm for working with words and concepts.

(Answer: a)

Objects and Classes (702)

LECTURE NOTES

  • Explain that the object-oriented paradigm is based on the idea that the solution for a problem can be visualized in terms of objects that interact with each other.
  • Point out that an object is defined as a unit of data that represents an abstract or real-world entity.
  • Examples of objects are shown in Figure 12-30.
  • Distinguish between an object and a class. There can be many objects, but in order to organize similar objects a class is created. A class is a template for a group of objects with similar characteristics.
  • Discuss class attributes and how they are used to describe the object. Review the examples in Figure 12-31. Discuss that any of these can be public or private, based on the availability of the object.
  • Discuss the data types associated with the class and review the UML (unified modeling language) diagram in Figure 12-32. The class is named, the data types are defined, and the type of attribute is designated.

FIGURES

  • Figure 12-30, Figure 12-31, Figure 12-32

CLASSROOM ACTIVITIES

  • Class Discussion: Display the class attribute data types on an overhead monitor or whiteboard and have students describe each. Be sure to provide an example of each one. Refer to Figure 12-31 if necessary. Discuss what kinds of attributes the pizza program might have and what type of variables those would be.
  • Quick Quiz:
  1. A(n) ______is a unit of data that represents an abstract or real-world entity (such as a person, place, or thing). (Answer: object)
  2. True/False: The object-oriented paradigm is based on the idea that the solution for a problem can be visualized in terms of objects that interact with each other. (Answer: True)
  3. In terms of object-oriented programming, what is a class? (Answer: A template for a group of objects with similar characteristics)

Inheritance (704)

LECTURE NOTES

  • Explain that in object-oriented terms, inheritance refers to passing certain characteristics from one class to other classes. Compare this to passing genes from a parent to a child. For example, ask where they got the color of their eyes. Ask if they have any special talents that one of their parents has (such as swimming or playing ball). Inheritance in object-oriented terms produces new classes with inherited attributes, creating a superclass and subclasses.
  • Review the hierarchical structure in Figure 12-33.

TEACHER TIP