Presentation is loading. Please wait.

Presentation is loading. Please wait.

Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 2: Your First Program.

Similar presentations


Presentation on theme: "Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 2: Your First Program."— Presentation transcript:

1 Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 2: Your First Program

2 Today We Are Going To: Review our “KM_PER_MILE ” program Review our “KM_PER_MILE ” program Define the structure of a C++ program Define the structure of a C++ program Enumerate the types of information (Data) with which we will work Enumerate the types of information (Data) with which we will work Describe the operations which may be performed on those types of data Describe the operations which may be performed on those types of data

3 Topic A 2nd C++ Program

4 Hello, World! Recall the program we wrote Recall the program we wrote Here were the steps we took: Here were the steps we took: determined the purpose (write a message) determined the purpose (write a message) determine inputs (none)/outputs (message) determine inputs (none)/outputs (message) design algorithm (print statement) design algorithm (print statement) write code write code compile/fix/re-compile compile/fix/re-compile run program run program

5 Program Structure A C++ program requires a main function A C++ program requires a main function The main function can appear with different signatures The main function can appear with different signatures Important to exit properly Important to exit properly Blocks of code enclosed in braces {...} Blocks of code enclosed in braces {...} Provide lots of comments Provide lots of comments /*...*/ /*...*/ // //

6 C++ Syntax Reserved words are the language with which you write instructions Reserved words are the language with which you write instructions Examples: int, return Examples: int, return Punctuation: Punctuation: semi-colon (;) at end of each line semi-colon (;) at end of each line parentheses for method arguments parentheses for method arguments quotation marks quotation marks

7 External Components Often necessary to use components (code) provided by someone else Often necessary to use components (code) provided by someone else Examples are the I/O objects we use to print at the command line: cout, endl Examples are the I/O objects we use to print at the command line: cout, endl NOT reserved words NOT reserved words Use the #include to bring external code into our program Use the #include to bring external code into our program Must be careful to avoid giving the same name to different objects: namespaces Must be careful to avoid giving the same name to different objects: namespaces

8 Compiler Behavior Pre-processor directives: Pre-processor directives: describe the way the compiler behaves describe the way the compiler behaves #include is most common #include is most common examined before compilation begins examined before compilation begins Compilation: Compilation: translate into machine code (optimize) translate into machine code (optimize) search for errors search for errors Linking: Linking: combine components into an executable combine components into an executable

9 Topic Style and Readability

10 Importance of Style Do you remember the Y2K problem? Do you know why it happened? Do you remember the Y2K problem? Do you know why it happened? 80% to 85% of an application's life is spent in MAINTAINENCE, that is: FIXING BUGS 80% to 85% of an application's life is spent in MAINTAINENCE, that is: FIXING BUGS You MUST make your programs readable You MUST make your programs readable

11 Comments There is (almost) no such thing as too much commentary: explain to others, yourself, what you are doing There is (almost) no such thing as too much commentary: explain to others, yourself, what you are doing // is useful for brief notations about the logic of the program // is useful for brief notations about the logic of the program /*... */ is better for longer descriptions /*... */ is better for longer descriptions

12 Indentation and Spacing Almost as important as comments as an aid to understanding code Almost as important as comments as an aid to understanding code Show statements contained within a block by indenting them Show statements contained within a block by indenting them Add white space to demark new thoughts (like paragraphs of logic) Add white space to demark new thoughts (like paragraphs of logic) Block styles: you will have noticed that I use the “next line” block style Block styles: you will have noticed that I use the “next line” block style

13 Naming Conventions Capitalize first letter in a class name Capitalize first letter in a class name Do NOT capitalize first letter of members Do NOT capitalize first letter of members If a class or member name contains several words concatenate them and capitalize each successive word: theElmTree If a class or member name contains several words concatenate them and capitalize each successive word: theElmTree Use all caps for a constant: PI Use all caps for a constant: PI Separate the words in a constant with an underscore: MAX_VALUE Separate the words in a constant with an underscore: MAX_VALUE

14 Topic Development Environment

15 Working With Visual Studio.net C++ Visual Studio uses “projects” Visual Studio uses “projects” FIND the code you have written: FIND the code you have written: C:\Program Files\Microsoft Visual Studio\MyProjects C:\Program Files\Microsoft Visual Studio\MyProjects Look for the project you created Look for the project you created The files you need are the CPP files The files you need are the CPP files Others are aids for the environment Others are aids for the environment Watch carefully when you import and export files from a project Watch carefully when you import and export files from a project

16 More About Visual C++ Often useful to build in stages: compile, then build Often useful to build in stages: compile, then build NOTE: There is a difference between including a file in a project and using the file in your program. NOTE: There is a difference between including a file in a project and using the file in your program. Compilation order is important in C++ Compilation order is important in C++

17 Using Another Compiler Can obtain the Borland compiler for free from the Internet Can obtain the Borland compiler for free from the Internet Installation is straightforward Installation is straightforward Must set some Environment Variables Must set some Environment Variables Compile from a DOS prompt Compile from a DOS prompt Run from a DOS prompt Run from a DOS prompt

18 Questions


Download ppt "Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 2: Your First Program."

Similar presentations


Ads by Google