19
C++ Crash Course Class 1 What is programming?

C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

Embed Size (px)

Citation preview

Page 1: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

C++ Crash Course

Class 1What is programming?

Page 2: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

What’s this course about?

• Goal: Be able to design, write and run simple programs in C++ on a UNIX machine.

Page 3: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

What’s this course about?

• Goal: Be able to design, write and run simple programs in C++ on a UNIX machine.

Also: understand what it means to program, understand a bit better how computers work, and be better equipped with the ability to learn how to make the computer do what you want it to.

Page 4: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

What is programming?

• Programs are a set of instructions for the computer

• Computers are DUMB• Computer only understands binary, or specifically

machine code, low-level code• Programs are high-level, written for humans– C, C++, Ruby, Java, Perl, LISP…

• Programs have to be translated for the computer– Compiling vs. interpreting

Page 5: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

What is programming?

• Programs typically must be written for a specific platform or operating system– Operating system: Windows 7, MacOSX, Red Hat– Platform: combination of the hardware

architecture and software that runs on it

• We have several languages we could write in, all of which perform better with a certain purpose in mind

Page 6: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

Procedural vs. Object-Oriented• Procedural programming is linear:– Functions and procedures are pre-defined– When the program is run, it’s stepped through in a very

straightforward manner• Object-oriented models the everyday world:– With OOP, we can have a real-world object with attributes

and methods– Agent object sends a message, and doesn’t know what will

happen– Receiving object has to carry out instructions

• Code re-use is very important in both!– Crucial to understanding all programming

Page 7: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

Programming Steps

1. Define the problem2. Design the solution3. Program code4. Testing5. Deployment

Page 8: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

Programming Steps

1. Define the problem– What are we trying to accomplish? Why is this

program being written?

2. Design the solution3. Program code4. Testing5. Deployment

Page 9: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

Programming Steps

1. Define the problem2. Design the solution– What structure do we need? (functions, objects)– What algorithms will we use?– Write pseudocode– Test the algorithm on paper – what inputs does it

need? Where will it fail?3. Program code4. Testing5. Deployment

Page 10: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

Programming Steps

1. Define the problem2. Design the solution3. Program code– Type it up, compile, repeat– Pre-processing: include files, definitionsCompile: turn

source code to assembly to machine or object code– Link with library routines– Load in memory

4. Testing5. Deployment

Page 11: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

Programming Steps

1. Define the problem2. Design the solution3. Program code4. Testing– Execute the program: run in the CPU (Central Processing Unit)

– Black box testing– White box testing– Unit testing

5. Deployment

Page 12: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

Programming Steps

1. Define the problem2. Design the solution3. Program code4. Testing5. Deployment– Once we’ve tested sufficiently, we can put the

code into the real world!

Page 13: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

Programming Steps

1. Define the problem2. Design the solution3. Program code4. Testing5. Deployment– Once we’ve tested sufficiently, we can put the

code into the real world!

Repeat steps as necessary: code is rarely, if ever, perfect after the first run

Page 14: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

What is a program?

• Learning to program is a little like learning a foreign language.

vocabulary: reserved words, or things the compiler or interpreter already understandsalso includes user-created identifiers, naming things for the compiler or interpretergrammar: syntax rules guiding understanding

Page 15: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

What is a program?

• Tokens– Comments: for humans; tells a reader of the code

what it’s supposed to be doing– Keywords: words used by the language; you’re not

allowed to redefine these– Identifiers: words you make up to refer to concepts

you’ve written into the code (variables, functions)– Literals: explicit references in the code to numbers or

strings (known as “hard-coding”)– Symbols: operators or punctuation in the code

Page 16: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

What is a program?

• Written in hierarchical chunks

– Preprocessor statements– Comments– Collection of functions…

…which are collections of statements…which are collections of tokens.

Page 17: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

What is a program?

• Let’s write one!• The problem: average three numbers

Page 18: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

Error types• Compilation error:

– You made a mistake that makes it impossible for the compiler to figure out what you meant!

– Identifiable when the compiler complains.• Run-time error:

– The compiler was successful, but you made a mistake that makes it impossible for the computer to finish running the program!

– Identifiable when you get a complaint when running the program.• Logic error:

– Your program compiles and runs, but your input produces the wrong output!

– Identifiable by doing a program trace and figuring out what the program was supposed to spit out.

All of these mean it’s time for debugging.

Page 19: C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine

Homework

• Student survey on Blackboard – fill it out by tomorrow!

• Written HW #1 and project #1 due Thursday– Will be up on the course website later tonight

http://cs.jhu.edu/~obuzek/class/cs109