Unformatted text preview:

Slide 1ObjectivesIntroduction to ProgrammingProcedural Programming LanguagesProcedure-Oriented ProgramsProcedure-Oriented Programs (continued)Object-Oriented LanguagesHistory of C++Algorithms and ProceduresExample of an AlgorithmExample of an Algorithm (continued)FlowchartingSlide 13Flowchart ExampleClasses and ObjectsProgram TranslationProgram Translation (continued)Function and Class NamesFunction and Class Names (continued)Slide 20Function and Class Naming ConventionsC++ KeywordsC++ IdentifiersC++ Identifiers (continued)The main FunctionThe main Function (continued)Slide 27main Function CompositionThe cout ObjectC++ Sample Code using coutNewline Escape SequencePreprocessor CommandNamespacesMore C++ Sample CodeMore C++ Sample Code (continued)SyntaxProgramming StyleStandard C++ Program FormStandard C++ Program Form (continued)Poor Program FormatProper Program FormatCommentsComment structureCommon Programming ErrorsCommon Programming Errors (continued)SummarySummary (continued)A First Book of C++: From Here To There, Third Edition 2ObjectivesYou should be able to describe:•Introduction to Programming•Function and Class Names•The cout object•Programming Style•Common Programming ErrorsA First Book of C++: From Here To There, Third Edition 3Introduction to Programming•Computer program: Data and instructions used to operate a computer•Programming: Writing computer program in a language that the computer can respond to and that other programmers can understand•Programming language: Set of instructions, data, and rules used to construct a program–High-level languages use human language type instructions–Low-level languages use instructions tied to a computer typeA First Book of C++: From Here To There, Third Edition 4Procedural Programming Languages•Instructions are used to create self-contained units (procedures)•Procedures accept data as input and transform data to produce a specific result as an output •Initially, high-level programming languages were predominately proceduralA First Book of C++: From Here To There, Third Edition 5Procedure-Oriented Programs•Most high-level programs process data to produce one or more results •Procedural programs are constructed from sets of instructions, with each set called a procedure•Each procedure moves the data one step closer to the final desired outputA First Book of C++: From Here To There, Third Edition 6Procedure-Oriented Programs (continued)A First Book of C++: From Here To There, Third Edition 7Object-Oriented Languages•Allow for procedural instructions and for definitions of objects to be manipulated•Such definitions include:–The general characteristics of objects–Specific operations to manipulate objects•C++ is an object-oriented language–Has procedures and objects–Supports code reuseA First Book of C++: From Here To There, Third Edition 8History of C++•C++ began as extension to C, which is procedural language developed in the 1970s at AT&T Bell Laboratories•In early 1980s, Bjarne Stroustrup (also at AT&T) used his background in simulation languages to develop C++ •Object-orientation and other procedural improvements were combined with existing C language features to form C++A First Book of C++: From Here To There, Third Edition 9Algorithms and Procedures•Before writing a program, a programmer must clearly understand–What data is to be used–Desired result–Procedure needed to produce this result •The procedure is referred to as an algorithm•Algorithm: Step-by-step sequence of instructions describing how to perform a computationA First Book of C++: From Here To There, Third Edition 10Example of an Algorithm•Assume that a program must calculate sum of all whole numbers from 1 through 100•A computer can not respond to heuristic command: “Add the numbers from 1 - 100”•A computer is algorithm-responding machine and not intuition-responding machine•Several methods or algorithms can be used to find the required sumA First Book of C++: From Here To There, Third Edition 11Example of an Algorithm (continued)Sum = n(a + b)/2Where n = number of terms to be added (100) a = first number added (1) b = last number to be added (100) Sum = 100(1 + 100)/2 = 5050Figure 1.2: Summing the Numbers from 1 through 100 Method 3. Formula - Use the formula Sum = n(a + b)/2 = 5050A First Book of C++: From Here To There, Third Edition 12FlowchartingA First Book of C++: From Here To There, Third Edition 13FlowchartingA First Book of C++: From Here To There, Third Edition 14Flowchart ExampleA First Book of C++: From Here To There, Third Edition 15Classes and Objects•Data Object: Set of values packaged as single unit•Class: Set of objects with similar attributes•General concept of object-oriented programming is difference between an object and the larger set of which it is a member (class)•A red, Ford Taurus sedan is an instance, or object, of general class of automobilesA First Book of C++: From Here To There, Third Edition 16Program Translation•C++ source program: Set of instructions written in C++ language•Machine language: Internal computer language–Consists of a series of 1s and 0s•Source program cannot be executed until it is translated into machine language–Interpreted language translates one statement at a time–Compiled language translates all statements togetherA First Book of C++: From Here To There, Third Edition 17Program Translation (continued)A First Book of C++: From Here To There, Third Edition 18Function and Class Names•Modular programs: Segments arranged in logical order to form an integrated unit•Module: Segments of modular program•Function: Name of a C++ procedure–Composed of sequence of C++ instructions–Function interface is its inputs and outputs–Method of converting input to results is encapsulated and hidden within functionA First Book of C++: From Here To There, Third Edition 19Function and Class Names (continued)A First Book of C++: From Here To There, Third Edition 20Function and Class Names (continued)A First Book of C++: From Here To There, Third Edition 21Function and Class Naming Conventions•Identifiers: Names that convey an idea of the purpose of function or class•Identifier composition rules:–First character must be a letter or underscore–Only letter, digit or underscore may follow–Blank spaces allowed–Identify component words with initial capitalization–Cannot be C++ keyword–Should be a mnemonicA


View Full Document

WPU CS 2300 - A First Book of C++

Download A First Book of C++
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view A First Book of C++ and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view A First Book of C++ 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?