CS 110 - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

CS 110

Description:

Write a program that computes the square footage of a house, given the dimensions of each room. ... The dimensions of each room in feet (real numbers) Output ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 19
Provided by: vdou8
Category:

less

Transcript and Presenter's Notes

Title: CS 110


1
CS 110
  • Introduction to Computer Programming

2
Instructor
  • Name Vana Doufexi
  • Office 2-229 Ford Building
  • Email vdoufexi_at_cs.northwestern.edu
  • Office phone 491-5708
  • Office hours By appointment.

3
Resources
  • Class webpage http//www.cs.northwestern.edu/aca
    demics/courses/110
  • Use to
  • read important announcements
  • read about class policies
  • look up your grades
  • download homework handouts
  • download class notes
  • access helpful tutorials
  • access the discussion forum (provided by
    Blackboard)

4
Resources
  • Discussion Forum
  • Use to
  • discuss class material
  • ask questions on the material or the assignments
    (but NEVER post solutions)
  • share solutions to posted practice problems
  • get hints and tips for the assignments.

5
What is a computer?
  • A device that can
  • accept data (input),
  • manipulate it (process) according to specific
    instructions
  • generate results (output) as a result of the
    processing.
  • (optional) store the results

6
What is programming?
  • Program a sequence of human-readable
    instructions telling a computer how to do a
    particular task or solve a given problem.
  • Programming Designing, writing and testing a
    computer program.

7
The programming process
  • Analyze Find the core problem
  • Decide the inputs and outputs
  • Decide how to go from the inputs to the outputs
    (only the process, not detailed mechanics)
  • Break it down into sub-problems.
  • This part is completed on paper.
  • The end result is usually a flow-chart or
    pseudocode.

8
The programming process
  • Implement
  • Write instructions
  • Tackle each sub-problem separately by writing a
    set of instructions (a function) for it.
  • The computer can only understand instructions
    written in machine language (sequences of 1s and
    0s).
  • In order to make the programming process easier
    for humans, researchers developed new, easier
    (for humans) to understand languages as well as
    special tools that could convert programs written
    in human-readable languages into programs written
    in machine language.
  • C is an example of such a language.

9
The programming process
  • Implement
  • Write instructions (continued)
  • Some operations that we may need our program to
    perform are so common (e.g. reading input from
    the keyboard) that it would be expedient to have
    a ready module for it.
  • A collection of such modules is called a library.
    For example, the Input/Output library contains
    modules (functions) that can be invoked to read
    input from the keyboard, or write output to the
    screen, etc.
  • A library function may be invoked from within a
    program.

10
The programming process
  • Implement
  • Compile your program
  • The compiler is the tool that translates a
    program written in a high-level language such as
    C into a program written in machine language.
  • The first step in the compilation process is
    called preprocessing. The preprocessor scans the
    input program for special instructions called
    preprocessor directives.
  • These directives tell the preprocessor to do
    things such as include an already existing
    library into the program.

11
The programming process
  • Implement
  • Compile your program (continued)
  • The second step in the compilation process is the
    actual translation.
  • The compiler tries to figure out whether the
    program satisfies the rules of the language. A
    good compiler will catch several types of
    mistakes and give informative descriptions and
    suggestions to the programmer.
  • One type of mistake is a syntax error. For
    example, a missing parenthesis in an arithmetic
    expression. Such mistakes are generally easy for
    the compiler to identify.

12
The programming process
  • Implement
  • Link your program
  • Once a program has been compiled successfully, a
    tool called a linker is used to combine all its
    components together and generate an executable
    program.
  • Execute (run) your program
  • In order to run your program, you use an
    operating system command to load it into your
    computer's memory and execute its (machine
    language) instructions one at a time.

13
The programming process
  • Test and debug
  • A program that compiles and executes successfully
    does not necessarily work as expected.
  • It is very important to test the program with
    several kinds of inputs to make sure that it
    always gives the expected outcome.
  • Programs often contain a type of error called a
    bug (or, more formally, a logic or design error).
    Such errors are hard to find and sometimes are
    not found until long after a program has been
    released.
  • A tool called the debugger is very helpful in
    finding such errors.

14
The programming process
  • Test and debug
  • The recommended way to test a program is one
    module at a time.
  • Once all modules have been tested successfully,
    start combining them a few at a time and test
    again.
  • This way, it is easier to identify where
    potential errors are.

15
The programming environment
  • The Visual Studio environment
  • This application encompasses almost all of the
    tools that you will need for the programming
    process
  • a text editor to write the program
  • a compiler
  • a linker
  • a loader to load the program into memory so that
    it can be executed
  • a debugger

16
How to program example
  • Write a program that computes the square footage
    of a house, given the dimensions of each room.
  • Step 1
  • Input
  • The number of rooms (an integer)
  • The dimensions of each room in feet (real
    numbers)
  • Output
  • The square footage of the house in square feet
    (real number)
  • Subproblems
  • compute the area of a room
  • add up the areas of all rooms

17
How to program example
  • Write a program that computes the square footage
    of a house, given the dimensions of each room.
  • Step 2
  • Translate your instructions into C language.
  • We will learn how by exploring variables, types,
    statements, expressions, assignments,
    conditionals, loop constructs, functions, etc.
  • Compile your code
  • The compiler is a program that converts the
    human-readable instructions that you wrote into
    machine-executable instructions.

18
How to program example
  • Write a program that computes the square footage
    of a house, given the dimensions of each room.
  • Step 3
  • Test Debug your program
  • There are two types of mistakes
  • syntax mistakes (easy to fix compiler helps)
  • design mistakes, a.k.a. bugs (often hard to find
    debugger helps).
  • Test your program to make sure it works correctly
    and can handle situations such as erroneous input
    (what if someone types in negative dimensions?)
Write a Comment
User Comments (0)
About PowerShow.com