C++ lecture 2

24 5 0
C++ lecture 2

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

C++ Programming Language Lecture Problem Analysis and Solution Representation The Hashemite University Computer Engineering Department (Adapted from the textbook slides) Outline    Program development cycle Algorithms development and representation Examples The Hashemite University Program Development Cycle  Program development cycle steps:    Problem definition Problem analysis (understanding) Algorithm development:  Ways for algorithm representation:        Human language Pseudocode Flowcharts (also called UML activity diagram) Coding Execution and testing Maintenance Recall that such cycle and all the techniques presented in this lecture are the same for any programming language you want to use not only The Hashemite University for C++ Problem Definition   To understand the problem is half the solution Describe it by precise, up to the point statements that will make both analyzing and solving the problem easier and clearer The Hashemite University Problem Analysis    Determine the inputs, outputs, and the required operations Explore all possible solutions Pick the easiest, in terms of implementation cost (space, time) one The Hashemite University Algorithm Development  Algorithm is a procedure that determines the:       Actions to be executed Order in which these actions are to be executed (which is called program control and in industry it is called work flow) So, it is a plan for solving the given problem You must validate the developed algorithm, i.e make sure that it solves the correct problem You must verify the developed algorithm, i.e make sure that it produces correct results You must check the feasibility (in terms of the needed resources, ease of implementation, ease of understanding and debugging, its expected execution time, etc.) of the developed algorithm The Hashemite University Algorithm Representation – Human Language   Use your own language to represent the steps of the developed algorithm Example: adding two integers: Prompt the user to enter two numbers Add them and store the result Display the sum to the user on the screen The Hashemite University Algorithm Representation – Pseudocode         Artificial, informal language used to develop algorithms Kind of structured English for describing algorithms Middle approach between human language and C++ code It is convenient and user friendly Not actually executed on computers Allows us to “think out” a program before writing the code for it Usually easy to convert into a corresponding C++ program Consists only of executable statements, i.e Hashemite University no definitions orThedeclarations Pseudocode Notations I  Input:    Output:     Input from keyboard: Get Input from file or memory location: Read Output to printer: Print Output to file: Write Output to screen: Display, Prompt (usually followed by Get) Values assignment:    Initial values: Initialize, Set Results of computation: =,  Keeping variables for later use: Save, Store The Hashemite University Pseudocode Notations II  Arithmetic computation:    Control structures:   Either use exact operators (+, *, /, -) or equivalent words of them (add, multiply, divide, subtract) Computations: either use Compute or represent the actual operation mathematically E.g Compute average or avg = sum/count Use the actual words as it is: If, If – then – Else, While, – While, For – to , Relational operators:   Write them as words: greater then, less than or equal, etc Or you can use their symbols: >,

Ngày đăng: 12/10/2021, 21:08

Mục lục

    C++ Programming Language Lecture 2 Problem Analysis and Solution Representation

    Algorithm Representation – Human Language

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan