Presentation is loading. Please wait.

Presentation is loading. Please wait.

4/26/2017 Intro to C++ Lecture 2.

Similar presentations


Presentation on theme: "4/26/2017 Intro to C++ Lecture 2."— Presentation transcript:

1 4/26/2017 Intro to C++ Lecture 2

2 Programming Languages…
4/26/2017 Assembly Language Machine Language Fortran Pascal COBOL BASIC Ada Visual Basic C and C++ Java Smalltalk Programming languages are artificial languages created to tell the computer what to do They consist of vocabulary and a set of rules (grammar/syntax) to write programs The software development life cycle (SDLC) is an organized method of software development

3 C++ Predecessors Early procedural languages included
4/26/2017 Early procedural languages included FORTRAN: Formula Translation ALGOL: Algorithmic Language COBOL: Common Business Oriented Language BASIC: Beginners All-purpose Symbolic Instruction Code Pascal C Smalltalk, Simula, etc. were the object-oriented predecessors of C++

4 Third-Generation and Fourth-Generation (High-Level) Languages
4/26/2017 The Evolution of Programming Languages

5 First-Generation Languages
4/26/2017 Machine language: Consists of binary numbers (0s and 1s) Is the earliest programming language Is the only language the computer understands without translation It is machine dependent; each family of processors has its own machine language

6 Second-Generation Languages
4/26/2017 Assembly language: Resembles machine language Is a low-level language Uses brief abbreviations for program instructions. Abbreviations are called mnemonics A program is written in source code (text file) and translated into machine language by an assembler

7 Third-Generation Languages
4/26/2017 Procedural languages: Are high-level languages that tell the computer what to do and how to do it Create programs at a high level of abstraction Are easier to read, write, and maintain than machine and assembly languages Use a compiler or interpreter to translate code Fortran and COBOL are third-generation languages

8 Compilers and Interpreters
4/26/2017 An interpreter translates source code one line at a time and executes the instruction A compiler is a program that changes source code to object code, all in one shot Example of an interpreted language: BASIC; a compiled language: C

9 The Great Software Crisis of the 60’s
4/26/2017 Spaghetti Code and the Great Software Crisis: goto statements resulted in programs that were difficult to follow This made them difficult to modify, maintain, and even develop! This problem led to the software crisis of the 1960s Programs were not ready on time Programs exceeded their budgets Programs contained too many errors Customers were not satisfied Management was also very frustrated!

10 Structured Programming to the rescue…
4/26/2017 Structured programming languages: Were developed to improve software development Include Algol and Pascal Are well-structured and organized Forbid the use of goto statements Use three fundamental control structures Sequence, Selection, Repetition

11 Modular Programming Languages developed in the 70’s…
4/26/2017 Modular programming languages: Were developed because of problems in structured programming languages Are used to create programs that are divided into separate modules Each module carries out a special function Require specified input to produce specified output

12 Fourth-Generation Languages
4/26/2017 Fourth-generation languages are non-procedural, high-level specification languages They do not force programmers to follow procedures to produce results (they’re very close to English, sometimes) Types of fourth-generation languages include: Report generators Languages for printing database reports (generate a program to generate the report) Query languages Languages for getting information out of databases (generate a program to process a query or generate a form) Also include visually-oriented languages More ambitious 4GL environments attempt to automatically generate whole systems from the outputs of CASE tools, specifications of screens and reports, and possibly also the specification of some additional processing logic, including data flow diagrams, entity relationship diagrams, entity life history diagrams Fifth-generation languages These include artificial intelligence and neural networks oriented languages

13 SKIP: Object-Oriented Programming
4/26/2017 Object-oriented programming (OOP): Relies on component reusability The ability to produce program modules that perform a specific task Eliminates the distinction between programs and data Uses objects that contain data and procedures

14 SKIP: Objects 4/26/2017 Objects are units of information that contain data as well as methods that process and manipulate the data Classes of objects: Hierarchy or category of objects Objects at the top of the category are broader in scope than the subclass objects Objects near the bottom are narrower in scope Inheritance refers to an object’s capacity to “pass on” its characteristics to its subclasses

15 Programming Language Classification
4/26/2017 Computer languages (not just programming languages!) can be classified into two general categories: Imperative and Declarative Imperative languages include: Generic/General Programming Languages They allow user-defined data types, data abstraction, polymorphism, etc. Procedural Programming Languages Object-Oriented Programming Languages Declarative languages include: Functional Programming Languages (e.g., Haskell, Scheme, etc.) Logical Programming Languages (e.g., Prolog) Even Markup Languages like HTML They’re not programming languages because they don’t allow for the three fundamental control structures but they do declare what pages should look like, etc. Procedural Programming (structured and modular): An important methodology for dealing with complexity is structured programming Structured Programming requires well-organized, structured code that uses the three fundamental control structures (sequence, selection, repetition) Complex tasks need to be broken down into simpler subtasks  this is modular programming Procedural programming reduces complex problems to collections of simple, interconnected modules – it combines structured and modular programming! It is up to the programmer to implement procedural programming

16 3GL Programming Languages
4/26/2017 Most high-level programming languages can be categorized into one of three main categories: Procedural Languages (FORTRAN, BASIC, COBOL, Pascal, etc.) Object-Oriented Languages (Smalltalk, Effiel, etc.) Hybrid Languages allow both OO and Procedural (such as C++)

17 3GL vs. 4GL 3GL: Procedure-oriented (structured) languages
4/26/2017 3GL: Procedure-oriented (structured) languages Programmers concentrate on the procedures used in the program Procedure: a logically consistent set of instructions which is used to produce one specific result 3GL: Object-oriented languages Items are represented using self-contained objects Can be used to create programs for graphical windows environments 4GLs: fourth-generation languages Permit users to access and format information without the need for writing any procedural code Use high-level English-like instructions to specify what to do, not how to do it .

18 Procedural Programming Basics
4/26/2017 The purpose of most application programs is to process data to produce specific results Basic procedural operations.

19 What Can a Procedural Program Do?
4/26/2017 A linear, procedural program is structured to instruct a computer to: Read Input Calculate Store data Write Output Work in a sequential progression (Sequence) Compare and branch (Selection) Iterate or Loop (Repetition)

20 Advantages of Procedural Programming
4/26/2017 Easier to test and debug Structured walkthroughs of the code “goto-less” I.e., they’re well-structured and include the three fundamental control structures Standard method for solving a problem A single program can be written by more than one programmer By dividing the program up into modules Programs can share routines (again, because of modularization)

21 What’s structured programming?
4/26/2017 A Structure is One or More Instructions (Flowchart Symbols) Combined According to Rules E.g., only one point of entry and exit Structured programming is a set of rules that prescribe good style habits for programmer. An organized, well structured code Easily sharable; easy to debug and test Requires shorter time to develop, test, and update The key idea is that any numerical algorithm can be composed using the three fundamental control structures: Sequence, selection, and repetition

22 What Are the Rules for Writing a Structured Program?
4/26/2017 3 basic control structures: Sequence Selection (decision) Repetition (looping or iteration)

23 Modularization 4/26/2017 Modular Program: a program consisting of interrelated segments arranged in a logical and understandable form Easier to develop, correct, and modify than other kinds of programs Module: a small segment which is designed to perform a specific task A group of modules is used to construct a modular program

24 Modular Programming 4/26/2017 Behind most software development over the last century Encourages subroutines Large programs are divided by functional parts into subroutines or modules Go to instructions only permitted within subroutines Three objectives when creating routines: Smaller, simpler routines Breakup complex routines into simple functions Strong cohesion Routine does one function such as printing Instructions are closely related Loose coupling Non-existent or weak connection between routines One routine does not depend on other routines

25 SUBPROGRAM (function)
4/26/2017 SUBPROGRAM (function) . . . SUBPROGRAM1 SUBPROGRAM1 a meaningful collection of SEQUENCE, SELECTION, REPETITION (LOOP), or SUBPROGRAMS

26 Introduction to C++ Modules in C++ can be classes or functions
4/26/2017 Modules in C++ can be classes or functions Function: accepts an input and produces an output by processing the input in some fashion A function’s processing is encapsulated and hidden within the function

27 A Multiplying Function
4/26/2017 A Multiplying Function

28 Classes and Functions 4/26/2017 Function: encapsulates a set of operations, while a class encapsulates data plus one or more sets of operations Class: contains both data and functions used to manipulate the data Identifier: a name given to an element of the language, such as a class or function

29 The Software Development Life Cycle (SDLC)
4/26/2017 The SDLC was introduced in the 1970s to address problems in creating programs It provides an organized plan for breaking down the task of program development into manageable parts Five phases of the SDLC: Defining the problem Designing the program Coding the program Testing, debugging, and formalizing the program Implementing and maintaining the program

30 Phase 1: Defining the Problem
4/26/2017 The first step in program development What do you want to solve? What is the objective and question? Get the requirements from the client (possibly other software engineers) Systems analysts provide program specifications (specs) to the programmers The specs define: Input data Processing Output Including the appearance of the user interface Software engineers need clear specifications (as opposed to requirements): Clear, specific statement of goal Expected output Expected input

31 Phase 2: Designing the Program
4/26/2017 Programmers create the program’s design Top-down design focuses on the program’s main goal (main routine), then breaks the program into manageable components (subroutines/modules) Control structures are used to see how each subroutine will do its job Makes programming easier to develop, debug, and maintain Developing an algorithm, which is a step-by-step description of how to arrive at a solution Program design tools: Structure charts – show the top-down design Flow charts – show the logic of program Pseudocode – alternative to flow charts

32 Structured Design Structured programming implements structured design
4/26/2017 Structured programming implements structured design Control structures are logical constructs that specify how the instructions in a program are to be executed Three fundamental types of control structures: Sequence control structure – Instructions are executed in the order in which they appear Selection control structures – The program branches to different instructions depending on whether a condition is met; IF…THEN…ELSE Repetition control structure – The program repeats the same instructions over and over; DO-WHILE and DO-UNTIL

33 Structure Chart and Flowchart
4/26/2017 Structure Chart Flowchart

34 Phase 3: Coding the Program
4/26/2017 Coding requires the translation of the algorithm into specific program instructions An appropriate programming language is chosen, and the code is typed according to its syntax rules Documentation is created for future use Best if the documentation is done in-line using a tool like JavaDoc, Doxygen, etc. The variable names and definitions, a description of the files needed, and the layout of the output are produced A user manual is developed to explain how the program works

35 Phase 4: Testing and Debugging the Program
4/26/2017 Testing and debugging eliminate all errors Syntax and logic errors are corrected Debugging is the process of eliminating errors

36 Phase 5: Implementing and Maintaining the Program
4/26/2017 The program is: Tested by users Thoroughly documented Maintained and evaluated regularly

37 Algorithms 4/26/2017 Algorithm: A step-by-step sequence of instructions that must terminate Pseudocode Use of English-like phrases to describe an algorithm Formula Use of mathematical equations to describe an algorithm Flowchart Use of diagrams that employ symbols to describe an algorithm

38 Program Design Process
4/26/2017 AL-KHOWARIZMI Algorithm Design (underlying logic of program) Program Composition Debug & test (error free & reliable) Documentation Maintenance Grace M. Hopper First “Bug” 75% of costs!

39 What’s an Algorithm? 4/26/2017 A predetermined series of instructions for carrying out a task in a finite number of steps I.e., Baking A Cake! Two commonly used tools to help document the program logic (the algorithm): Flowcharts and Pseudocode. Generally, Flowcharts work well for small problems but Pseudocode is used for larger problems

40 How to make a plan …? Visio or dia
4/26/2017 How to make a plan …? Do a hand calculation (brainstorming!) Make a flowchart Visio or dia Write the Pseudocode

41 Flowchart: Symbolic Representation of Algorithms
4/26/2017 Flowchart: A graphic representation of an algorithm often used in the design phase of programming to work out the logical flow of a program Uses symbols to represent each logical step of the algorithm. The order in which the steps are carried out is indicated by connecting “flow lines” Use a few, basic flowchart symbols Follow UML (Unified Modeling Language) Standard defined by OMG group:

42 Basic Flowchart Symbols
4/26/2017 Some basic symbols:

43 Basic Control Structures
4/26/2017 Basic Control Structures a sequence is a series of statements that execute one after another selection (branch) is used to execute different statements depending on certain conditions repetition (looping) is used to repeat statements while certain conditions are met. a subprogram (module) is used to break the program into smaller units

44 SEQUENCE Can contain any symbol except for the decision or loop symbol
4/26/2017 Can contain any symbol except for the decision or loop symbol Steps are executed in sequence with no instruction changing the order Flow lines connect each instruction

45 4/26/2017 SELECTION (branch)

46 REPETITION (loop) 4/26/2017

47 Pseudocode Logical steps Written in English and symbols, terms, etc.
4/26/2017 Logical steps Written in English and symbols, terms, etc. Indenting for logical structures begin some game display instructions pick a number between 1 and 100 repeat turn until number is guessed or seven turns are completed input guess from user respond to guess end repeat end some game display end message Looks like BASIC (Chris Clark)

48 Pseudocode for three control constructs
4/26/2017

49 What is Pseudocode? An alternative to flowcharting
4/26/2017 What is Pseudocode? An alternative to flowcharting Represents logic in an English-like manner Rules Avoid the use of words peculiar to a particular programming language Indent lines to make the pseudocode easy to read and understand Show key words (Move, Write, Read) in a different color, font, or capitalized Punctuation is optional End every If with EndIf Begin every loop with a Loop instruction; End every loop with EndLoop Main routine is to be shown first Terminate all routines with an End instruction (e.g., EndMain)

50 Example 1 4/26/2017 Write an algorithm in pseudocode that finds the average of two numbers

51 SKIP: Average of two StartAverageOfTwo 0. Input: Two numbers
4/26/2017 StartAverageOfTwo 0. Input: Two numbers Add the two numbers Divide the result by 2 Return the result by step 2 End

52 Example 2 4/26/2017 Write an algorithm to change a numeric grade to a pass/no pass grade.

53 SKIP: Pass/No Pass Grade
4/26/2017 Pass/NoPassGrade Input: One number if (the number is greater than or equal to 70) then 1.1 Set the grade to “pass” else 1.2 Set the grade to “nopass” End if Return the grade End

54 Flowchart & Pseudocode
4/26/2017 Start Sum=0 Count = 0 Input Grade More grades? Sum = Sum + Grade Count = Count + 1 Average = Sum/Count Stop No Yes Flowchart Pseudocode BEGIN Average Grade sum=0 count = 0 DO INPUT grade IF grade < 0 EXIT sum = sum + grade count = count +1 END DO IF count > 0 THEN average = sum/count ELSE average = 0 END IF END Average Grade

55 Your first program in C++
4/26/2017 Writing a program in Linux involves three steps… hello.cpp a.out compiler

56 Details of a Typical C++ Environment
4/26/2017 Phases of C++ Programs: Edit Preprocess Compile Link Load & Execute Loader Primary Memory Program is created in the editor and stored on disk. Preprocessor program processes the code. Loader puts program in memory. CPU takes each instruction and executes it, possibly storing new data values as the program executes. Compiler Compiler creates object code and stores it on disk. Linker links the object code with the libraries, creates a.out and stores it on disk Editor Preprocessor Linker CPU . Disk

57 Code (write) the program
4/26/2017 Carefully enter the code Remember most C++ statements end with a ; Commands are in lower case

58 DEMO: 1. Edit 4/26/2017 Start up an editor (emacs) to edit a file called hello.cpp Type the following into the file: #include <iostream> using namespace std; int main(void){ cout << “Hello World” << endl; return 0; }

59 DEMO: 2. Compile Compile your program g++ hello.cpp
4/26/2017 Compile your program g++ hello.cpp This tells the computer to call the compiler to create the program The compiler is a program that takes the code that you write and translates it into machine language Machine code is made up of many simple instructions composed of 0’s and 1’s

60 DEMO: 3. Execute 4/26/2017 You should now have a file called a.out inside your directory This file is called an executable a.out holds the binary version of your code (the computer doesn’t understand words, just 0’s and 1’s) To run the program type: ./a.out

61 What does the code mean? #include <iostream>
4/26/2017 #include <iostream> using namespace std; Allows us to use functions that other people have written to facilitate input and output Processed by the pre-processor (it’s called a pre-processor directive) Literally copies and pastes the libraries of functions that others wrote This is what makes Java and MFC so powerful!

62 What does the code mean? int main(void)
4/26/2017 int main(void) Remember, every C++ program is made of one or more functions A function is a piece of code that accomplishes one specific task Every executable C++ program has one function called main() This is where execution (the actual running) of the program (i.e., the computer instructions) starts…

63 What does the code mean? int main(void)
4/26/2017 What does the code mean? int main(void) When you type ./a.out to run the program you are essentially telling the computer to call this main() function Calling a function means to execute the code in the function

64 What does the code mean? int main(void)
4/26/2017 What does the code mean? int main(void) The int is the return type of the function. In other words when it finishes what kind of result does it give back. A whole number? A character? int means a whole number. We want to give this number back to tell us if the program was sucessfully completed

65 What does the code mean? int main(void)
4/26/2017 What does the code mean? int main(void) The void in the brackets is the parameter list for this function The parameter list indicates what this function needs to be given from the outset for it to work void indicates that we give nothing to this function.

66 What does the code mean? cout << “Hello World” << endl;
4/26/2017 cout << “Hello World” << endl; This line tells the computer to print something to the screen If you want to print something to the screen you use the cout function The endl adds an “end line” and flushes the buffer

67 What does the code mean? return 0;
4/26/2017 return 0; This is the last line in our program It basically means that the program is now done return means to go back to where the program was called from 0 is used to indicate that it was successfully completed (a general convention)

68 What does the code mean? 4/26/2017 Note also that the code of main() is contained within the { } These {} group code together. In this case it tells us that all the code between them are part of the main function #include <iostream> using namespace std; int main(void){ cout << “Hello World” << endl; return 0; }

69 Some Important Terms 4/26/2017 A source program (.cpp file type) consists of the program statements comprising a C++ or other programming language program. An object program (.obj file type) is the result of compiling a source program. Header files (.h file type) contain constant, variable, and function declarations needed by a program. An executable program is a program that can be run by a computer. Linking adds code from libraries to your file. Collects the object code from all files in the workspace and puts them into one executable program. A compiler is a program that translates a source program into an object program. An interpreter is a program that translates individual source program statements, one at a time, into executable statements. Each statement is executed immediately after translation.

70 object code from other source files
Compiling / Building 4/26/2017 (.cpp file) source code compiler (.obj file) object code (.h files) linked to libraries executable file object code from other source files

71 Error, error… does not compute!
4/26/2017 Syntax refers to the structure of a program and the rules about that structure Syntax Errors – Typing Errors Errors in spelling and grammar (syntax). “Doag. Bites, Man” You can use the compiler or interpreter to uncover syntax errors. You must have a good working knowledge of error messages to discover the cause of the error. Semantic Errors – Logic or Meaning Errors Errors that indicate the logic used when coding the program failed to solve the problem. “Man bites dog.” You do not get error messages with logic errors. Your only clue to the existence of logic errors is the production of wrong solutions. Run-time Errors (Exceptions) Code does something illegal when it is run (hence runtime) E.g., divide by zero

72 4/26/2017 Procedural programming produced significant improvements in software quality and development time…

73 So…Why are Programmers Now Using Object-Oriented Programming?
4/26/2017 So…Why are Programmers Now Using Object-Oriented Programming? Increasing dependence on information processing is creating a crisis Volume of information is increasing faster than the ability to create software Programmers cannot generate software to keep pace with the potential of new hardware

74 4/26/2017 Some Programming Issues are Not Adequately Addressed by Procedural Programming It is rarely possible to anticipate the design of a completed system before it’s actually implemented Systems are works in progress Development of GUIs is very complicated in traditional procedure-oriented programming languages Sharing data across routines is difficult and error-prone Focus of structured programming is on the modularity and procedures Data interactions are ignored Allowing modules to share all their data and interact freely creates subroutines that are very dependent on each other--therefore, we don’t have independent routines

75 So, What’s the Answer to the Data Sharing Problem?
4/26/2017 Modularize the data along with the procedures by giving each subroutine its own local data that it alone can read and write INFORMATION HIDING

76 4/26/2017 Information Hiding Allows the Programmer to Work with Modules or Procedures Developed by Others at an Abstract Level Abstraction Internal details are hidden from the user Data and procedures are not exposed to procedures not needing to know them

77 Another Advantage of Object-Oriented Programming is Reusability
4/26/2017 Another Advantage of Object-Oriented Programming is Reusability Building a house Electrical system Plumbing system Heating/air conditioning system Objects in Windows Buttons Menus Fields

78 How Procedural Programming Looks at a Problem
4/26/2017 Procedures Data acted upon by the procedures are maintained separately from the procedures Data assumes a secondary role! Program Procedure Data

79 How Object-Oriented Programming Looks at a Problem?
4/26/2017 Objects Data Methods Scope Methods surround the data and protect data from other objects Encapsulation and Information Hiding! Method Method Data Method Method OBJECT

80 Objects Objects are things (nouns)
4/26/2017 Objects are things (nouns) Objects have attributes (properties) Adjectives that describe an object Objects have methods (behaviors) Verbs that specify what the object can do Events are used to trigger behaviors Objects interact with each other by passing messages amongst themselves

81 Why Do We Still Write Procedural Programs?
4/26/2017 Way of breaking a program into routines Object-oriented programming works at a higher level of abstraction than procedural programming does After objects have been identified, methods are designed using procedural techniques We are concentrating on methods or procedures

82 4/26/2017

83 Common Business-Oriented Language (COBOL)
4/26/2017 Sample Cobol program COBOL: The earliest (1959) high-level language The most widely used business language A proven way to do accounting, inventory, billing, and payroll Requires programmers to explain what the program is doing at each step

84 Formula Translator (Fortran)
4/26/2017 Formula Translator (Fortran) Fortran: Began in the 1950s Is suited to scientific, mathematical, and engineering applications Is used to solve complex equations Features simplicity, economy, and ease of use Sample Fortran program

85 Ada Ada: Named after Augusta Ada Byron
4/26/2017 Ada Sample Ada program Ada: Named after Augusta Ada Byron Incorporates modular programming The required language for the U.S. Defense Department Suitable for control of real-time systems (missiles)

86 Beginner’s All-Purpose Symbolic Instruction Code (BASIC)
4/26/2017 Sample BASIC program BASIC: An easy-to-use language available on personal computers Widely taught in schools as a beginner’s programming language Designed as an interpreted language

87 Visual Basic (VB) Visual Basic:
4/26/2017 Visual Basic (VB) Sample Visual Basic Visual Basic: Is widely used in program development packages Uses event-driven programming Enables the programmer to develop an application by using on-screen graphical user interfaces

88 Pascal Pascal: Is named after Blaise Pascal
4/26/2017 Sample Pascal program Pascal: Is named after Blaise Pascal Encourages programmers to write well-structured programs Widely accepted as a teaching language Has been updated to reflect new approaches to programming

89 C Difficult to learn and programming is time consuming
4/26/2017 C C: Was developed by AT&T’s Bell Labs in the 1970s Combines high-level programming language with assembly language Programmers manipulate bits of data within a processing unit Sample C program Difficult to learn and programming is time consuming

90 Sample Smalltalk program
4/26/2017 Sample Smalltalk program Smalltalk: Developed in the 1970s by Xerox Corp “100% pure” object-oriented programming language Not often chosen for software development

91 C++ Sample C++ program C++: Incorporates object-oriented features
4/26/2017 C++ Sample C++ program C++: Incorporates object-oriented features Is widely used for professional program development

92 Java Java: Developed by Sun Microsystems
4/26/2017 Java Java: Developed by Sun Microsystems An object-oriented, high-level programming language with a twist First true cross-platform programming language Gained acceptance faster than any other programming language A simplified version of C++

93 4/26/2017 Java Java, continued : Java is designed to run on any computer platform Java Virtual Machine enables cross-platform use Java applets or small programs are downloaded to computers through networks Weaknesses include: The security risk in downloading applets The speed in running the programs

94 Sample Java Program 4/26/2017

95 Web-Based Languages Markup languages:
4/26/2017 Web-Based Languages Markup languages: Hypertext markup language (HTML) sets the attributes of text and objects within a Web page Extensible markup language (XML) is used for sharing data and objects in a Web environment Scripting languages: VBScript is used to write short programs (scripts) that are embedded in Web pages JavaScript is used to write scripts on Web pages Visual Studio .NET: Used for the development of scripts and programs that are accessible from the Web

96 The Programming Life Cycle
4/26/2017 The Programming Life Cycle Define the problem Make or buy software? Design the program by making an algorithm Code (write) the program Document the program Compile and execute the program Syntax and run time errors Test (debug) the program Logic errors

97 4/26/2017 Summary A programming language is an artificial language consisting of a vocabulary and a set of rules Machine language is the lowest-level programming language Assembly language contains symbols for programming instructions Third-generation (high-level) languages require programmers to specify the procedures to be followed Object-oriented languages combine procedures and data

98 Summary, continued Defining the program Designing the program
4/26/2017 Summary, continued The SDLC’s six phases are: Defining the program Designing the program Coding the program Testing, debugging, and formalizing the program Implementing and maintaining the program Top-down programming makes programs easier to debug and maintain Debugging requires finding and correcting syntax errors and logic errors

99 Flowcharts for the three constructs
4/26/2017

100 Alternative Control Structure Flowcharts
4/26/2017 Sequence Selection Repetition (Looping)

101 4/26/2017 Pseudocode! What is pseudocode? Pseudocode is basically short, English phrases used to explain specific tasks within a program's algorithm. Pseudocode should not include keywords in any specific computer languages. Indentation can be used to show the logic in pseudocode as well. Why is pseudocode necessary? Writing pseudocode WILL save you time later during the construction & testing phase of a program's development  let’s you “think out” the program before you code it. How do I write pseudocode? Consists mainly of executable statements Original Program Specification: Write a program that obtains two integer numbers from the user. It will print out the sum of those numbers. Variables required (names and types): int1: (integer) to store first integer int2: (integer) to store the second integer sum: (integer) to store the sum of the numbers Pseudocode: Prompt the user to enter the first integer int1 Prompt the user to enter a second integer int2 Compute the sum of the two user inputs sum = int1 + int2 Display an output prompt that explains the answer Display the result If you can’t write it in pseudocode, you won’t be able to write it in C++!


Download ppt "4/26/2017 Intro to C++ Lecture 2."

Similar presentations


Ads by Google