Programming Logic and Design, Fourth Edition,Introductory1-1

Chapter 1

An Overview of Computers and Logic

  • Overview
  • Objectives
  • Teaching Tips
  • Quick Quizzes
  • Class Discussion Topics
  • Additional Projects
  • Additional Resources
  • Key Terms

Lecture Notes

Overview

Chapter 1 provides an introduction to computer hardware and to the software creation process. Students will learn the basic steps involved in the programming process. Next, they will learn about flowcharting and flowcharting symbols.Students will become familiar with using sentinel values. Finally, students will learn about assigning values to variables.

Chapter Objectives

  • Understand computer components and operations
  • Describe the steps involved in the programming process
  • Describe the data hierarchy
  • Understand how to use flowchart symbols and pseudocode statements
  • Use and name variables
  • Use a sentinel, or dummy value, to end a program
  • Use a connector symbol
  • Assign values to variables
  • Recognize the proper format of assignment statements
  • Describe data types
  • Understand the evolution of programming techniques

Understanding Computer Components and Operations

  1. Review the major components of a computer system.
  1. Describe the four major operations that occur in a computer. Discuss input and output devices.
  1. Understand the difference between high-level languages and machine language, and how they are related.
  1. Explain the purpose of compilers or interpreters.

If asked, explain the difference between a compiler and an interpreter. A compiler translates the entire source and stores the resulting machine language instructions in a disk file for later execution. An interpreter translates one line at a time and then executes it immediately.
  1. Understand the importance of correct program logic.

The logic errors can be very difficult to find, particularly if they only occur when certain data values are included in the input.
  1. Describe internal and external storage. The permanence of external storage is dependent on the lifetime of the particular type of media that is used.

Understanding the Programming Process

  1. List the six phases of programming, and then discuss each one in detail.
  1. The failure to understand the problem to be solved is the major cause of software project failures.

The ability of a programmer to understand a user’s needs by observing the user’s job functions and questioning the user is a key skill. In many organizations, the step of understanding the problem is performed by application analysts, and not programmers. In other organizations, programmers perform both analysis and programming, and may hold the job title of programmer/analyst.
  1. Describe flowcharts briefly
  2. Pseudocode allows a description of the program logic to be created without worrying about the details or syntax of a particular programming language.

The term “desk-checking” is also commonly used to describe the process of checking code for syntactical and logical correctness before compiling. This process was very necessary in earlier times when computing power was limited and scheduled, and a programmer may have been able to complete one compilation a day only.
  1. The actual coding of the program does not occur until after the logic has been totally described and checked.
  1. The repetitive process of coding, compiling, fixing syntax errors that must occur until the program is free of syntax errors.
  1. The repetitive process of testing, fixing logic errors, and retesting that must occur until all known errors have been corrected.
  1. Understand the importance of selecting appropriate test data to ensure that all of the code is tested. Consider boundary conditions such as minimum and maximum values.

Software testing, or Software Quality Assurance, can be a career of its own. Today, automated testing tools are available to attempt to thoroughly exercise all of the code in a program
An error-free test of the program does not guarantee that all errors have been corrected. The best that can be said is that “all errors that have been identified have now been corrected”.

Quick Quiz 1

  1. What are the two major components of a computer system?

Answer: hardware and software

  1. What are the four basic operations of a computer?

Answer: input, processing, output, and storage

  1. What is the most important phase in creating a program to solve a problem?

Answer: understanding the problem

  1. In a(n) ______network, all the computers are both clients and servers.

Answer: peer-to-peer

Understanding the Data Hierarchy

  1. Define data hierarchy. Describe each of the data types listed. Describe their relationships by using Figure 1-2.

Fields and records can be compared to the cells and rows in a spreadsheet. Files can be compared to the worksheets in a spreadsheet, and a database can be compared to a spreadsheet file containing multiple worksheets, or multiple spreadsheet files.

Using Flowchart Symbols and Pseudocode Statements

  1. Review the definitions offlowchart and pseudocode.
  1. Describe each of the flowchart symbols and its purpose.
  1. Describe flowlines and the depiction of direction with arrowheads on flowlines.
  1. Describe the use of terminal symbols
  1. Use Figure 1-7 to show the flowchart depiction of each line of pseudocode. This will help the students understand how much detail should appear in pseudocode.
  1. Discuss the need for repetitive processing of certain sets of program statements. Describe how the use of directed flowlines indicates repetition in a flowchart, using Figure 1-9.

Using and Naming Variables

  1. The variable represents a memory location which has a name assigned to it.
  1. Discuss rules for naming identifiers, and how they may differ from language to language.
  1. Describe camelCasing as a technique for naming identifiers.

The importance of meaningful names, to make code more readable and more maintainable. Most companies have naming standards for identifiers that should be followed.

Ending a Program by Using Sentinel Values

  1. Describe an infinite loop, and the requirement for some way of stopping a loop when it is processing.
  1. Describe decision testing, and introduce the flowchart decision symbol. Ensure that students understand the need to document both the Yes and No paths in a decision symbol.

In Figure 1-10, show how the directed flowlines show the code that forms the loop. Point out the necessary for a decision somewhere inside the loop, to avoid an infinite loop.
  1. A sentinel or dummy value can be used as a signal to stop the loop processing. Point out that if the loop is used to read files, the end-of-file marker is often used for this purpose.
  1. Figure 1-11 to show the use of a sentinel value in the decision point of the loop.

Using the Connector

  1. The connector symbol for flowcharts are used to connect various sections of the flowchart.

Connectors can be used to indicate continuation, or to drill down in detail. A common use of connectors is to provide a top-level flowchart, with connectors that point to the lower-level detail of parts of the flowchart.

Quick Quiz 2

  1. A symbol shaped like a(n) ______represents a decision in a flowchart.

Answer: diamond

  1. A loop that runs forever is called a(n) ______loop.

Answer: infinite

  1. A sentinel value is used for what purpose?

Answer: It is used as a signal value to indicate that processing should stop.

  1. A code stored in a file that marks the end of the data is called a(n) ____ marker.

Answer: EOF or end-of-file

Assigning Values to Variables

  1. Understand the concept of an assignment statement, along with the assignment operator.

A common mistake for new programmers is to try to treat assignment statements like algebraic equations. Stress that the left side of the assignment statement cannot contain an expression.
  1. Review the concept of a variable, pointing out the difference between the variable’s memory address and its contents (or value).

Understanding Data Types

  1. Describe the two basic data types, text and numeric, and point out that different types of variables are used for different types of data.
  1. Understand when it’s appropriate to use constants. Understand the advantage of using a constant for a value that will be used in many areas of the program, and how easy it is to change the value of the constant and know that your entire program will use the changed value.
  1. Describe several types of numeric variables that are available in most programming languages. Discuss how these variable types affect the precision of the data.

When a programming strictly enforces the use of proper data types, and does not allow computations using mixed data types, we say that the language is “strongly typed”.

Understanding the Evolution of Programming Techniques

  1. Describe early programming, which required the use of machine language mnemonics and direct memory addresses Machine language has the higher probability of errors, because the code was not at all English-like.

Note that low level languages also required a much deeper understanding of how the computer worked internally, as there was close to a one-to-one relationship between the instruction and the machine action it caused.
  1. The higher-level languages provide more than just an English-like language to use. Many instructions in high-level languages perform several low-level operations automatically.
  1. The programming design in early days tended to be monolithic, while newer programming design builds reusable modules of code.
  1. Describe and contrast the two major programming techniques, procedural programming and object-oriented programming.

Quick Quiz 3

  1. In an assignment statement, which side of the = receives the value?

Answer: the left side

  1. What are the two basic types of data?

Answer: text and numeric

  1. A(n) ______can be used to represent a value that will not change while the program is running.

Answer: constant

  1. What numeric data type is used to represent only whole numbers?

Answer: integer

Additional Resources

  1. A short history of the computer:
  1. Tutorial on flowcharting:
  1. Intro to programming languages, with machine code sample:
  1. Advantages and disadvantages of OOP:

Key Terms

Assignment statement: a programming statement used to assign a value to a variable

Central Processing Unit (CPU): the hardware on a computer that performs the processing in a computer

Character: a data type containing a single character, including letters, numbers, and special symbols

Coding: the process of writing the programming instructions

Compiler or interpreter: language-translation software that translates a programming language into machine language.

Constant: a specific value which does not change; constants can be various types such as numeric, string, or character

Data:the facts are put into a computer for processing

Data hierarchy: a ranking of the data types, from smallest to largest

Data type: the type of data being stored in a variable, such as numeric, string, character, etc.

Database: a group of files, often called tables, that together serve the information needs of an organization

Decision: testing a value

Desk-checking: the process of walking through a program’s logic on paper before actually writing the program

Eof: end of file marker

External storage: storage located outside of the main memory of the computer, also called persistent storage, such as floppy disk, flash media, magnetic tape, etc. External storage is relatively permanent.

Field: a single data item, such as a last name

Files: a group of records that have a logical relationship, such as a set of student records

Floating-point number: fractional numeric value that contains a decimal point

Flowchart: a pictorial representation of the logical steps required to solve a problem

Hardware: the equipment, or the devices, associated with a computer.

Identifier: a name for a variable

Infinite loop: a repeating flow of logic with no end

Integer: whole number

Internal storage: storage located inside the computer, also called memory, main memory, primary memory, or random access memory (RAM); internal storage is volatile (non permanent)

Input devices: devices that allow for the entry of data into a computer, such as a mouse, keyboard, scanner, video camera, etc.

Logical error: an error in how the program arrives at an answer or result

Machine language: the specific language that controls the computer’s on/off circuitry

Object-oriented programming: programming technique that focuses on objects and describes their features (attributes) and their behaviors

Output devices: devices that allow for the delivery of data from the computer to the user, such as a printer, monitor, speakers, etc.

Procedural programming: programming technique which focuses on the procedures that programmers create

Processing: the process of organizing data, check data for accuracy, performing mathematical or other manipulations on data

Programming language: a computer language that allows a programmer to write instructions for the computer

Pseudocode: an English-like representation of the logical steps required to solve a problem

Queries: questions that retrieve data from a database

Records: a group of fields that have a logical relationship, such as a student record consisting of name and address fields

Sentinel: a value which does not represent real data, but serves as a signal to stop; also called a dummy value

Software: programs which contain instructions that tell the computer what to do

Syntax: the rules of a programming language that govern its word usage and punctuation

Syntax error: misuse of the programming language’s grammar rules

Variable: a memory location whose contents can vary or differ over time.