Presentation is loading. Please wait.

Presentation is loading. Please wait.

by sir fakhri alam programing fundamental

Similar presentations


Presentation on theme: "by sir fakhri alam programing fundamental"— Presentation transcript:

1 Introductory Chapter Fundamentals and Methodology Reading Materials Object oriented programming using C++ (IT series). Object Oriented programming in C++ (Rabert Lafore) Internet Material (most important) Department of Computer Science, UOM | Introduction | Fakhre Alam10/20/2016

2 Objectives  How to solve a problem (by computer) fundamental problem solving techniques  How to design an algorithm algorithm design  How to write a program in C++ implementation

3 We learn C++, Why?  C++ is one of the most popular languages  C++ (originally C)  Basic, Pascal, Java, Perl, Cobol, Scheme, Lisp, Smalltalk, Ada, …  C++ is portable (runs on PC, Machintosh, Unix, Mainframes …)  C++ is widely used in industries (almost by everyone)  C++ is not easy to learn   The most common versions of C++:  Microsoft Visual C++  Eclipse  g++ (for Unix machines) C C++

4 Evolutionary Tree of Major Programming Languages

5 Course description Introduction C++ basics for Structured (or procedural) Programming Sequential (assignments) Branching (if statement) Looping (while-do statement) Arrays and algorithms Functions (local/global, value/ref), recursion Department of Computer Science, UOM | Introduction | Fakhre Alam

6 Computer Program  A set of instruction that tells a computer what to do is called program.  A program is a precise sequence of steps to solve a particular problem.  Written in Programming Languages.  Programmer uses programming languages or tools to write programs.  Computer program can solve many problems by giving instructions to computer.  Can perform task quickly.

7 Computer Program  A program can process large amount of data easily.  Display result according to user requirements.  Processing is high efficient and less time consuming  Different types of programs are used in different fields to perform certain tasks.  A computer program performs a specific task, and may interact with the user and the computer hardware.  Computer work model:

8 Algorithms & Pseudo Code  Algorithm: a step by step procedure to solve a problem  Algorithms  Computer Program  Algorithms are written sequentially in a simple meaningful steps and in user own language called pseudo code.  Pseudo code simplifies program development by separating it into two main parts: Logical design and Coding.  Algorithm to input two numbers, calculates sum and display result:  1) Start  2) Input A  3) Input B  4) Total= A+B  5) Display Total  6) End  Algorithms reduce complexity, increase flexibility and provide ease of understading.

9 Flowchart  Flowchart is a graphical representation of an algorithms. It is a way of visually presenting the flow of data, operations performed on data and sequence of these operations.  Flowchart for adding two numbers: StartInput A, BSum=A+BDisplay SumEnd

10 Programming Languages  A set of words, symbols and codes used to write program is called programing language.  Several programming languages are available for writing programs related to different fields of computer science such as 3-D graphics, Web, System programming and AI programming.  Two types of Programming Languages:  Low Level Languages:  Languages which are near to computer hardware and far from human languages are called low level language.  Easily understood by computer and require deep knowledge of computer hardware.  High Level Languages:  Programming language that is close to human language is called high level language.  Easy as compared to low level language and easy for human to understand.  Execute in the same sequence in which it is written and each instruction tells computer what to do.

11 What is a (programming) language?  A program needs to be written in a language  There are many programming languages  Low-level, understandable by a computer  High-level, needs a translator!  C++ is a high level programming language A sequence of instructions A program (in computer language) An algorithm (in human language)

12 Types of Low Level Languages  Machine Language:  Programming language in which instructions are written in binary form is called machine language.  Directly understood by the computer.  Execute very fast.  Machine dependent and difficult to understand by human.  Assembly Language:  Also called symbolic language and it is one step higher than machine language.  In this language symbols also called mnemonics are used instead of binary codes. E.g. sub for subtraction  Assembly language is mostly used for writing system software

13 Types of High Level Languages  Procedural Languages:  In procedural languages program is a predefined set of instructions and computer execute these instructions in the same sequence in which the instructions are written.  Example includes FORTRAN, Basic, COBOL, PASCAL and C  Object Oriented Languages:  OOP is programming language in which programs are written on the basis of objects, where object is a a collection of data members and member functions.  In OOP, data and all possible functions on data are grouped together.  Example includes C++ and JAVA.  Non- Procedural Languages:  In these types of languages user only needs to tell the computer “what to do” not “how to do”. Can be easily used by non technical users to perform their specific task.  Example includes SQL and RPG

14 An example: Machine binary languageLow-level assemblyHigh-level

15 Language Processor/ Translator  Is a software that converts programs written in high level or assembly language into machine language. Several types of translators are available such as:  Compiler: Is a program that converts the instructions written in high level language called source program into machine language as a whole. The machine code is called object program.  Interpreter: Is another type of translator which convert high level instructions into machine language statement by statement due to which errors are found immediately. On the other hand interpreters are less efficient as compared to compilers.  Assembler: Assembler is also a translator for converting assembly language instruction into machine language

16 Integrated Development Environment (IDE) It contains  Editor  Compilers  Debugger  Linkers  Loaders

17

18 First C++ Program // welcome.cpp # include main() { cout << "Welcome to University of Malakand"; getch(); return 0; }

19 Step by step explanation  # include #include: This is a pre-processor directive. It is not part of our program; it is an instruction to the compiler. It tells the C compiler to include the contents of a file, in this case the system file iostream.h. The compiler knows that it is a system file, and therefore looks for it in a special place. : This is the name of the library definition file for all Input Output Streams. Your program will almost certainly want to send stuff to the screen and read things from the keyboard. iostream.h is the name of the file in which code are written that work for you.  Header files are collection of standard library functions to perform different tasks. Each header files contains different types of predefined functions. Many header files can be included in one program.  The extension of a header file is “.h”. The include preprocessor directive is used to include header files in programs.  The header files are normally stored in include subdirectory.

20 Step by step explanation  : conio.h header used in c programming contains functions for console input/output. Some of the most commonly used functions of conio.h are clrscr, getch, getche, kbhit etc. Functions of conio.h can be used to clear screen, change color of text and background, move text, check if a key is pressed or not and many more.  main() : The main function is the starting point of a C++ program. When the program is run, the control enters main() function and starts executing its statements.  A C ++ program is made up of a large number of functions. Each of these is given a name by the programmer and they refer to each other as the program runs.  Each program must contain main() function, otherwise it will not be executed.  Notice that there are parentheses (“( )”, normal brackets) with main. Here the parentheses contain nothing. There may be something written inside the parentheses.

21  { } : Next, there is a curly bracket also called braces("{ }"). For every open brace there must be a matching close. Braces allows to group together pieces of a program. The body of main is enclosed in braces. Braces are very important in C++; they enclose the blocks of the program.  cout: This is known as out put stream in C and C++. Stream is a complicated thing, you will learn about it later. Think a stream as a door. The data is transferred through stream, cout takes data from computer and sends it to the output. For the moment it is a screen of the monitor. hence we use cout for output.  << : The sign << indicates the direction of data. Here it is towards cout and the function of cout is to show data on the screen.  “ Welcome to Malakand University” : The thing between the double quotes (“ ”) is known as character string. In C programming character strings are written in double quotes. Whatever is written after << and within quotation marks will be direct it to cout, cout will display it on the screen. Step by Step explanation

22  ; : There is a semicolon (;) at the end of the above statement. This is very important. All C statements end with semicolon (;). Missing of a semicolon (;) at the end of statement is a syntax error and compiler will report an error during compilation. If there is only a semicolon (;) on a line than it will be called a null statement. i.e. it does nothing.  In this program we give a fixed character string to cout and the program prints it to the screen as.  getch(); : getch function prompts the user to press a character and that character is not printed on screen, getch header file is conio.h.  Common use of getch is that you can view the output (if any) of your program without having to open the output window if you are using turbo c compiler or if you are not running your program from command prompt. Step by Step explanation

23 Step by step explanation  return 0: Technically, in C or C++ main function has to return a value because it is declared as "int main“ which means "main function should return integer data type“ if main is declared like "void main", then there's no need of return 0. Some compilers even accept and compile the code even if you dont write return 0. varies from compiler to compiler.  0 traditionally indicates that the program was successful. You don't have to return 0 explicitly, because that'll happen automatically when main terminates. But it's important to keep in mind that main is the only function where omitting return is allowed.

24 Types of Errors in C++ program  Syntax Error: A type of errors that occurs when an invalid statement is written in program. Syntax errors occurs due to:  Missing terminator operator at the end of each statement.  Misspelling keyword and delimiters  Logical Errors: Errors that occurs due to poor logic of the programmer. A statement with logic error may produce unexpected and wrong results in the program. These error are difficult to find because compiler cannot detect them.  Run- Time Errors: Errors that occurs during the execution of program. It is caused when a statement directs the computer to execute an illegal operation such as dividing a number by zero. Run time errors are normally caused due to wrong input from the user.

25


Download ppt "by sir fakhri alam programing fundamental"

Similar presentations


Ads by Google