1 / 19

C++ Crash Course

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
Télécharger la présentation

C++ Crash Course

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. What’s this course about? • Goal: Be able to design, write and run simple programs in C++ on a UNIX machine.

  3. 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.

  4. 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

  5. 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

  6. 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

  7. Programming Steps • Define the problem • Design the solution • Program code • Testing • Deployment

  8. Programming Steps • Define the problem • What are we trying to accomplish? Why is this program being written? • Design the solution • Program code • Testing • Deployment

  9. Programming Steps • Define the problem • 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? • Program code • Testing • Deployment

  10. Programming Steps • Define the problem • Design the solution • 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 • Testing • Deployment

  11. Programming Steps • Define the problem • Design the solution • Program code • Testing • Execute the program: run in the CPU (Central Processing Unit) • Black box testing • White box testing • Unit testing • Deployment

  12. Programming Steps • Define the problem • Design the solution • Program code • Testing • Deployment • Once we’ve tested sufficiently, we can put the code into the real world!

  13. Programming Steps • Define the problem • Design the solution • Program code • Testing • 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 

  14. 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 understands also includes user-created identifiers, naming things for the compiler or interpreter grammar: syntax rules guiding understanding

  15. 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

  16. What is a program? • Written in hierarchical chunks • Preprocessor statements • Comments • Collection of functions… …which are collections of statements …which are collections of tokens.

  17. What is a program? • Let’s write one! • The problem: average three numbers

  18. 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.

  19. 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

More Related