1 / 77

بسم الله الرحمن الرحيم

بسم الله الرحمن الرحيم. COURSE TITLE: PROGRAMMING FUNDANENTALS. INSTRUCTOR : ILTAF MEHDI. Course Details. Lectures Assignments Presentation Lab Work (Practical). LANGUAGE?. Language is a source of communication between people. It is medium of Expression

Télécharger la présentation

بسم الله الرحمن الرحيم

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. بسم الله الرحمن الرحيم By Iltaf Mehdi

  2. COURSE TITLE:PROGRAMMING FUNDANENTALS INSTRUCTOR: ILTAF MEHDI By ILTAF MEHDI

  3. Course Details Lectures Assignments Presentation Lab Work (Practical) By ILTAF MEHDI

  4. LANGUAGE? Language is a source of communication between people. It is medium of Expression What is the computer language? To establish a communication between user and computer . (HRF, MRF) In general, there are two classes of languages Natural languages Programming Languages By ILTAF MEHDI

  5. Natural languages These are the languages through which the human beings communicate with each other. For example: English, Urdu, French, Pashto etc. Programming languages These are the languages through which the human beings communicate with the computer. These are the most widely used mediums between the user and the computer. Examples are C, C++, COBOL, PASCAL, BASIC, FORTRAN etc. The programming languages are classified into two types: 1) Low level languages. 2) High level languages By ILTAF MEHDI

  6. 1) Low-Level Language It consists of two types of languages Machine language Machine Language was the first language used for computers as a source of communication This is the only language which is directly understandable by the machine (computer) and needs no translation programs (compiler, Assembler, Interpreter). Machine language is the language of binary digits 0’s and 1’s(“0” means “OFF” and “1” means “ON) that is why it is also called as binary language. It is very difficult to write programs using 0’s and 1’s i.e. in machine language. Thus machine language is totally machine dependent and is efficient for computers and inefficient for programmers. By ILTAF MEHDI

  7. Main Points of Machine language • The first language that was invented. • It is machine dependant. • It is also called binary language. • It is the most complicated and hard language. • A program created in machine language cannot be run on any other computer • Machine language depends on electric pulses (i.e on / off). By ILTAF MEHDI

  8. ASSEMBLY LANGUAGE The computer professionals developed one step higher language than the machine language which is called Assembly language .The binary codes of machine language (0’s and 1’s) were replaced by some special codes called mnemonics. The programs in Assembly language are written using these mnemonic codes as: ADD for addition, SUB for subtraction MUL for multiplication These mnemonics are understandable by the human but not understandable by the machine. To make it understandable for the machine, a program called assembler is developed its function is to translate a program written in assembly language into machine language By ILTAF MEHDI

  9. Main points of Assembly Language it is one step easy then machine language. It is also called symbolic language (abbreviation are used). It is machine dependent. Slow and tedious language. Special words are used as symbols called MNEMONICS. A program created on one computer cannot run on another type of computer. By ILTAF MEHDI

  10. 2) High Level Language These languages are fairly machine independent and English like. The programmer can understand more easily and enable the programmer to write instructions easily using English words and familiar mathematical symbols such as if else, for, goto, +,-etc. A program written in high-level language is translated into machine understandable form with the help of Translation programs i.e.interpreter or compiler. By ILTAF MEHDI

  11. Main Points of High Level Language It is English like language. It is much easy to learn. High level program is just like giving instruction to a person in daily life. High level program need preprocessor to convert the program into machine codes. Different types of programming languages are FORTRAN, Pascal, C and C++ etc By ILTAF MEHDI

  12. The high level languages are of two types: • Procedural languages/Structured languages. • OOP (Object Oriented Programming) languages A Procedural language is that in which each statement tells the computer to do something. Get some input and process the input and provide the output to the user , in simple words a program in a procedural language is a list of instructions that’s created by a user or programmer OOP In this language different objects are created from each other and then used in different functions. By ILTAF MEHDI

  13. Programming Language Characteristics Programming languages have some characteristics that describe how they work and provide information about the types of computing tasks for which they are appropriate. When you need to select a language to use for a program, it is useful to understand some of the general characteristics of programming languages and the advantages or disadvantages of these characteristics are given as By ILTAF MEHDI

  14. Characteristics of High Level languages The general characteristics of ‘High Level Languages’ are as follows Machine Independence High-Level languages are machine independent. This is a very valuable advantage because it means that a program written in a high-level language can be run on many different types of computers with very little or practically no effort. Easy to learn and use: These languages are very similar to the languages normally used by us in our day-to-day life. Hence they are easy to learn and use. By ILTAF MEHDI

  15. Fewer errors In case of high-level languages, since the programmer need not write all the small steps carried out by the computer, he is much less likely to make an error. The computer takes care of all the little details, and will not introduce any error of its own unless something breaks down. Furthermore, compilers are so designed that they automatically catch and point out the errors made by the programmer. Hence diagnostic errors, if any, can be easily located and corrected by the programmer. Lower program preparation cost Writing program in high-level languages requires less time and effort which ultimately leads to lower program preparation cost. By ILTAF MEHDI

  16. Language Translator Translators are programs, which translate programs written in any high or assembly language into machine language (1’s and 0’s). There are three types of language translators Assembler Compiler Interpreter Program code Machine code Language translator By ILTAF MEHDI

  17. Language Translators Assembler The software that translates and assembly code into the computer’s machine code is called assembler. A program written by a programmer in assembly language is called source program. After this source code has been converted into object code Source Program Machine code Assembler By ILTAF MEHDI

  18. Language Translators Compiler A compiler is a computer software that translates a whole program, called the source code at once into machine code (object code) Interpreter An interpreter in another type of translator used for translating a language program into machine code It takes one statement of program and translates it into a machine instruction which is immediately executed by computer Source Program Machine code Compiler/Interpreter By ILTAF MEHDI

  19. PROGRAM Is a set of instructions, or a set of sequential instructions which are given to computer to solve a specific problem. Programs are written in computer languages like BASIC, PASCAL,C etc Run on computer -------------- -------------- ------C------- ---program- -------------- -------------- --------------- By ILTAF MEHDI

  20. Different types of Programs Generally there are THREE types of Programs that’s are created in a programming Languages Source Programs Object Programs Executable Programs By ILTAF MEHDI

  21. Source & Object Programs Source Program:-The program which is written by the programmer in a computer language is called source program. A Program that is created by programmer in a high level (C/C++) language with the extension of CPP/C. Object program:-The program which is converted into machine understandable code by the compiler is called object program.  A program that is created by the language processor in the form of codes is called Object program. A program that is converted in to object language (Machine) is called object program By ILTAF MEHDI

  22. Executable Program A program that is created by language processor to show or provide the output of a source program. A program that is directly run or executes to provide results of the input. A Program (software) that’s satisfy the user requirements or provide the solution of the user problem Executable program:-When source and object program are linked that’s create a new executable program is called exe program. By ILTAF MEHDI

  23. C Files First.C -------------- -------------- -Source-- ---program- -------------- -------------- --------------- First.Obj -------------- -------------- -Object-- ---Code---- -------------- -------------- --------------- After Compilation First.Exe After Linking -------------- -------------- -Executable-- ---Code- -------------- -------------- --------------- By ILTAF MEHDI

  24. COURSE TITLE:PROGRMMING FUNDAMENTALS INSTRUCTOR: ILTAF MEHDI By Iltaf Mehdi

  25. History of C Language • The C programming language was designed by Dennies Ritchie in the early 1970’s at Bell Laboratories. It was first used system implementation language for the nascent Unix operating system. The main reason to devised C was to overcome the limitations of B.  It was Derived from the type-less language BCPL ((Basic Combined Programming Language). C was was the evolution of B and BCPL by incorporating type checking. It was originally intended for use in writing compilers for other languages By Iltaf Mehdi

  26. History of C++ • C++ was devised by BjarneStroustrup in 1983 at Bell Laboratories. • It is an extension of C by adding some enhancements to C language. • Bjarne combined the simula's(a language designed for making simulations, created by Ole-Johan Dahl and Kristen Nygaard) features of object oriented and the efficiency of C. • The new features added to language are templates, namespaces, exception handling and use of standary library. By Iltaf Mehdi

  27. Difference between C And C++ • C++ is an extension of C language. This means that you can not only use the new features introduced with C++ but can also use the power and efficiency of C language. • C and C++ are no more language for writing compilers and other languages, these general purpose languages are used worldwide in every field. By Iltaf Mehdi

  28. Difference between C and C++ The main differences between C and C++ are: • C++ is object oriented while C is function or procedure oriented. • in C we use #include<stdio.h> as iclusion file, while in c++ we use #include<iostream.h> asinclusion file. • in C we use scanf function as standard input function, while in C++ we use stream cin>> for input. • like this for output in C we use printf function, while in C++ we use cout<< as a output function. By Iltaf Mehdi

  29. Constants • A constant value is the one which does not change during the execution of a program. • Unlike the variable the constant is fixed value that does not change during the execution of a program. • The const keyword specifies that a variable's value is constant and tells the compiler to prevent the programmer from modifying it. • It is simple in concept, variables declared with ‘const’ added become constants and cannot be altered by the program • Declaration and initialization of constant • You use the Const statement to declare a constant and set its value. By declaring a constant, you assign a meaningful name to a value. Once a constant is declared, it cannot be modified or assigned a new value. • const pi=3.14; By Iltaf Mehdi

  30. Comments • Comments are used to clarify the logic and for further explanation. • It is used to provide a brief description of the program which make program understandable to you and other. • Comments are ignored by compiler during the execution of the program. • Comments have no effect on the program output. By Iltaf Mehdi

  31. ways of writing comments • There are two ways of writing comments in c/c++ • C use // to comment a line. • This style is useful to comment individual line. • Forexample // some description about function used 2. Comments are also placed within the delimiters /* and */. Forexample if there is single line comment. It will be written as: /* this is single line comment */ • This form is most useful when a comment consists of severallines. e.g. /* this is multiple comment which which are enclosed in delimiters */ By IltafMehdi

  32. Comments Example: #include <stdio.h> #include <conio.h> void main (void) { // variable are declared here. int a ; int b; int c; // variable are initialized here. a=4; b=8; // sum of the value of variable c= a+b; /* variable c hold the result of sum so its value is printed by output statement.*/ printf(“Sum=%d”, c); getch(); } By Iltaf Mehdi

  33. Escape Sequence or Escape character • In c language some special characters are used for formatting. • For this purpose, backslash (called Escape character) followed by character is used in the statement. Different types of escape sequences are used in c/C++ • \a this is used for alert alarm or beep sound will be produced • \t this ES is used for tab, that’s causes in output printing for space of tab • \’ for single quote • \” for double quote • \\ for Backslash • \n this is used for new line, that’s causes the control to the beginning of newline • Forexample to insert a new line to your program output you can used backslash (\) followed by character (n). like • printf(“BCS \n BBA”); output: BCS BBA By Iltaf Mehdi

  34. Reserved Word • Reserved words or Keywords are those words that are reserved for the specific purpose and can not be used for other purposes. • They have special meaning and compiler knows their meanings. • In c/c++, all keywords are in lower-case. • Reserved words can not be used as user-defined names. Some of the reserved words are: • If, else , for, break, while, switch, case, default, int, float, return etc By Iltaf Mehdi

  35. Error and Types of Errors • An error is a mistake that is occurs in the course program during the compilation process. There are THREE types of Errors • Syntax Error: • Logical Error: • Run time Error By Iltaf Mehdi

  36. Types of Errors • Syntax Errors • It is that type of error in which a mistake is occurs in the syntax. 2. Logical Errors • It is that type of error in which a mistake is occurs logically that the compiler did not detect. • When a poor logic is define. 3. Run time errors • It is occurs when the program run but not show any results. By Iltaf Mehdi

  37. The C character set • A character or a group of characters denoted by alphabets, digits and special symbols used to represent information in a language is known as character set. • The C character set is as follows:- • Alphabets a ,b , c, d,………………,z A,B,C,D,…………….,Z • Digits 0,1,2,3,4,5,…………,9 • Special symbols !@#$%^&*()_+|{}[];:.<>?/|” “.~ By Iltaf Mehdi

  38. variable • “Those quantities whose values can be changed during the execution of the program”. • “A variable is a symbol that represents a storage location in the computer’s memory”. • Variable is a symbolic name for a memory location in which data is stored and subsequently recalled. • Variables are used for holding data values, so that they can utilized in a various computation in a program. • A variable is a value that can change any time. Naming variable: • All identifier rule must be follow while naming a variable. (see in coming slide) By Iltaf Mehdi

  39. Rules for Declaring Variables • Firstcharacter of a variable must be an alphabet or underscore. • A variable begins with a letter or underscore (_) and may consist of letters or digits. The underscore may be used to improve the readability of the variable name. • NoSpecialcharacter (like # ^* etc) are allowed in a variable name except underscore. • There is no restriction on the length of a variable name. However , only the first 31 characters of variable are significant By Iltaf Mehdi

  40. Rules for Declaring Variables • Both upper and lowercase letters are allowed in naming variables. An uppercaseletter is considered different from a lowercaseletter. • Duplicate variable names not allowed • Blankspaces are not allowed in a variable name • Keywords/reservedwordscan not be used as a variable name By Iltaf Mehdi

  41. Variable Declaration • Before using a variable it must be declare. • By declaration of a variable means to define the type of a variable. • The general format is: Datatype variablename; Where the data-type is the variable data type. It could be int, float, char. The variable-name is the variable name that is going to be used in the program in the future. • e.g. int Val; In this example keyword int define the type of the variable. It means variable Val can hold only integer data. Where as “Val” is the name of variable. • We can declare many variables in one statement, having the same data type separated with comma as: int rno, marks, age; By Iltaf Mehdi

  42. Variable Initialization • Assigning value to a variable is called initialization of a variable. • The general format is: Datatype variablename = value; • e.g. int val; // variable declaration val=1; // variable initialization • In the above example val=1 initialize the variable to 1. • it assign value 1 to variable val. By Iltaf Mehdi

  43. Data Types By Iltaf Mehdi

  44. Data Types in C • Integer types • Floating Point Types • Character Type • Void Type By Iltaf Mehdi

  45. Integer data types • Integers are whole numbers with a range of values, range of values are machine dependent. • Generally an integer occupies 2 bytes memory space and its value range limited to -32768 to +32768 (that is, -215 to +215-1). • A signed integer use one bit for storing sign and rest 15 bits for number. • To control the range of numbers and storage space, C has three classes of integer storage namely short int, int and long int. • All three data types have signed and unsigned forms. • A short int requires half the amount of storage than normal integer. Unlike signed integer, unsigned integers are always positive and use all the bits for the magnitude of the number. Therefore the range of an unsigned integer will be from 0 to 65535. • The long integers are used to declare a longer range of values and it occupies 4 bytes of storage space.GeneralSyntax:        int <variable name>; • likeint num1;short int num2;long int num3;Examples:      5, 6, 100, 2500. By Iltaf Mehdi

  46. float data type • The float data type is used to store fractional numbers (real numbers) with 6 digits of precision. • Floating point numbers are denoted by the keyword float. • When the accuracy of the floating point number is insufficient, we can use the double to define the number. • The double is same as float but with longer precision and takes double space (8 bytes) than float. • To extend the precision further we can use long double which occupies 10 bytes of memory space. General Syntax:          float <variable name>; • likefloat num1;double num2;long double num3;Examples:      9.125, 3.1254. By Iltaf Mehdi

  47. Character Type • Character type variable can hold a single character. • As there are singed and unsigned int (either short or long), in the same way there are signed and unsigned chars; both occupy 1 byte each, but having different ranges. • Unsigned characters have values between 0 and 255 • signed characters have values from –128 to 127. General Syntax: char <variable name>; • likechar ch = ‘a’;Examples:      a, b, g, S, j. By Iltaf Mehdi

  48. Void Type • The void type has novalues therefore we cannot declare it as variable as we did in case of integer and float. • The void data type is usually used with function to specify its type. • Like in our first C program we declared “main()” as void type because it does not return any value. • The concept of returning values will be discussed in detail in the C function chapter. By Iltaf Mehdi

  49. Expression • An expression in c/c++ is any valid combination of operators, constant and variables. e.g. • X= a+9; • z= a+b; By Iltaf Mehdi

  50. Statement • A statement is an instruction or a group of instructions that carry out certain action. • It is important to note that all c/c++ statement end with a semicolon. • Semicolon is used to separate the statement. • C/C++ statement can be divided into two types, these are: 1) Simple Statement 2) Compound Statement By Iltaf Mehdi

More Related