by sir fakhri alam programing fundamental

Slides:



Advertisements
Similar presentations
Copyright © 2002 W. A. Tucker1 Chapter 1 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Advertisements

Introduction to C Programming
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
Introduction to C Programming
C programming Language and Data Structure For DIT Students.
Chapter 1 Introduction to Programming. Computer Hardware CPU Memory –Main or primary –Secondary or auxiliary Input device(s) Output device(s)
CHAPTER 1: INTORDUCTION TO C LANGUAGE
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Using C Programming Language.  The programs that run on a computer are referred to as software.  You’ll learn key programming methodology that are enhancing.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Introduction COMP104: Fundamentals and Methodology.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
CSC141 Introduction to Computer Programming
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Programming With C.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 1- 1 October 20, October 20, 2015October 20, 2015October 20,
1 Problem Solving with C++ The Object of Programming Walter Savitch Chapter 1 Introduction to Computers and C++ Programming Slides by David B. Teague,
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Course Title: Introduction to C++ Course Instructor: ADEEL ANJUM Chapter No: 01 1 BY ADEEL ANJUM (MCS, CCNA,WEB DEVELOPER)
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
INTRODUCTION TO COMPUTING CHAPTER NO. 04. Programming Languages Program Algorithms and Pseudo Code Properties and Advantages of Algorithms Flowchart (Symbols.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Agenda Computer Languages How to Write a Simple C Program
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Chapter 1: Introduction to Computers and Programming.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Software Engineering Algorithms, Compilers, & Lifecycle.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
Introduction to Programming By: Prof. Muhammad Abu Baker Siddique 2 nd Lecture 1.
Chapter 1 Introduction 2nd Semester H
Programming what is C++
Basics of Computer A Computer is Electronic device that can
Programming Languages
Engineering Problem Solving With C An Object Based Approach
Chapter 1: Introduction to computers and C++ Programming
CSC201: Computer Programming
CSCI-235 Micro-Computer Applications
Completing the Problem-Solving Process
Introduction to C Language
Chapter 2 - Introduction to C Programming
Programming Fundamental
C Programming Hardik H. Maheta.
Programming Introduction to C++.
Java programming lecture one
Chapter 2 - Introduction to C Programming
Choice of Programming Language
Programming COMP104: Fundamentals and Methodology Introduction.
Welcome In The World Of ‘C’.  TEXT BOOK: Programming in ANSI ‘C By: E Balagurusamy. TMH  Reference Books: 1) The ‘C Programming Language By: Kernighan.
Unit# 8: Introduction to Computer Programming
TRANSLATORS AND IDEs Key Revision Points.
C# Programming: From Problem Analysis to Program Design
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
Topics Introduction Hardware and Software How Computers Store Data
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Chapter 2 - Introduction to C Programming
Programming Fundamentals Lecture #3 Overview of Computer Programming
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
PROGRAMMING FUNDAMENTALS Lecture # 03. Programming Language A Programming language used to write computer programs. Its mean of communication between.
C programming Language
Programs written in C and C++ can run on many different computers
Lecture 8 Programming Paradigm & Languages. Programming Languages The process of telling the computer what to do Also known as coding.
Chapter 2 - Introduction to C Programming
Introduction to C Programming
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

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

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

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++

Evolutionary Tree of Major Programming Languages

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

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.

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:

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.

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

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.

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)

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

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

An example: Machine binary languageLow-level assemblyHigh-level

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

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

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

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.

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.

 { } : 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

 ; : 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

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.

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.