Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Programming By: Prof. Muhammad Abu Baker Siddique 2 nd Lecture 1.

Similar presentations


Presentation on theme: "Introduction to Programming By: Prof. Muhammad Abu Baker Siddique 2 nd Lecture 1."— Presentation transcript:

1 Introduction to Programming By: Prof. Muhammad Abu Baker Siddique 2 nd Lecture 1

2 Summary Review of pervious lecture Pre-Requisites Development Environment of C C Program Structure I/O (Input/Output) Libraries Memory Concepts Quick Review 2

3 Points to remember/Pre- Requisites A computer is an electronic device capable of performing arithmetic and logical operations. A computer system has two components: hardware and software. The central processing unit (CPU) and the main memory are examples of hardware components. 3

4 All programs must be brought into main memory before they can be executed. When the power is switched off, everything in main memory is lost. Secondary storage provides permanent storage for information. Hard disks, flash drives, floppy disks, ZIP disks, CD-ROMs, and tapes are examples of secondary storage. 4 Points to remember/Pre- Requisites

5 Input to the computer is done via an input device. Two common input devices are the keyboard and the mouse. The computer sends its output to an output device, such as the computer screen. Software are programs run by the computer. The operating system monitors the overall activity of the computer and provides services. 5 Points to remember/Pre- Requisites

6 The most basic language of a computer is a sequence of 0s and 1s called machine language. Every computer directly understands its own machine language. A bit is a binary digit, 0 or 1. A byte is a sequence of eight bits. A sequence of 0s and 1s is referred to as a binary code or a binary number. 6 Points to remember/Pre- Requisites

7 7

8 Development Environment As programmer we need different tools to develop a program. These tools are needed for the life cycle of programs. Editors Compiler and Interpreter Debugger Linker Loader 8

9 9 Development Environment of C Editors: First of all we need a tool for writing the code of a program. For this purpose we used Editors in which we write our code. Compiler and Interpreter: As we write the code in English and we know that computers can understand only 0s and 1s. So we need a translator which translates the code of our program into machine language.

10 10 Development Environment of C Debugger: Another important tool is Debugger. Every programmer should be familiar with it. Debugger is used to debug the program i.e. to correct the logical errors. Using debugger we can control our program while it is running.

11 11 Development Environment of C Linker: Most of the time our program is using different routines and functions that are located in different files, hence it needs the executable code of those routines/functions. Loader: After a executable program is linked and saved on the disk and it is ready for execution.

12 12 How a typical C++ program is processed As a programmer, you need to be concerned only with Step 1. That is, you must learn, understand, and master the rules of the programming language to create source programs.

13 13 Programming with the Problem Analysis – Coding–Execution Cycle To be a good problem solver and a good programmer, you must follow good problem solving techniques. One common problem- solving technique includes analyzing a problem, outlining the problem requirements, and designing steps, called an algorithm, to solve the problem. Algorithm: A step-by-step problem-solving process in which a solution is arrived at in a finite amount of time.

14 14 Programming with the Problem Analysis – Coding–Execution Cycle In a programming environment, the problem- solving process requires the following three steps: 1. Analyze the problem, outline the problem and its solution requirements, and design an algorithm to solve the problem. 2. Implement the algorithm in a programming language, such as C++, and verify that the algorithm works. 3. Maintain the program by using and modifying it if the problem domain changes.

15 15 Programming with the Problem Analysis – Coding–Execution Cycle

16 16 Processing a C++ Program #include using namespace std; int main() { cout << "My first C++ program." << endl; getch (); return 0; }

17 17 C++ Program Structure #include : The C++ program given in the preceding section contains the statement #include. In a C++ program, statements that begin with the symbol # are called preprocessor directives. These statements are processed by a program called preprocessor. The compiler knows that it is a system file, and therefore looks for it in a special place.

18 18 C++ Program Structure : 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 has code to do that work for you

19 19 C++ Program Structure using namespace std; allows you to use cout and endl without the prefix std::. It means that if you do not include this statement, then cout should be used as std::cout and endl should be used as std::endl. We will elaborate on this later in this chapter.

20 20 C++ Program Structure int main(): The name main is special, in that the main is actually the one which is run when your program is used. 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. C regards the name "main" as a special case and will run this function first. If you forget to have a main function, or mistype the name, the compiler will give you an error.

21 21 C++ Program Structure (): Notice that there are parentheses (“( )”, normal brackets) with main. Here the parentheses contain nothing. There may be something written inside the parentheses. It will be discussed in next later on.

22 22 C++ Program Structure { }: 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.

23 23 C++ Program Structure 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.

24 24 C++ Program Structure << : The sign << indicates the direction of data. Here it is towards cout and the function of cout is to show data on the screen.

25 25 C++ Program Structure "My first C++ program”: 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.

26 26 Problem-Solving- Input / Output We will print student’s roll number.

27 Quick Overview Assembly language uses easy-to-remember instructions called mnemonics. Assemblers are programs that translate a program written in assembly language into machine language. Compilers are programs that translate a program written in a high-level language into machine code, called object code. 27

28 Quick Overview A linker links the object code with other programs provided by the integrated development environment (IDE) and used in the program to produce executable code. Typically, six steps are needed to execute a C++ program: edit, preprocess, compile, link, load, and execute. A loader transfers executable code into main memory. 28

29 Quick Overview An algorithm is a step-by-step problem- solving process in which a solution is arrived at in a finite amount of time. The problem-solving process has three steps: analyze the problem and design an algorithm, implement the algorithm in a programming language, and maintain the program. 29

30 Quick Overview Programs written using the structured design approach are easier to understand, easier to test and debug, and easier to modify. In structured design, a problem is divided into smaller sub problems. Each sub problem is solved, and the solutions to all of the sub problems are then combined to solve the problem. 30

31 Quick Overview In object-oriented design (OOD), a program is a collection of interacting objects. An object consists of data and operations on that data. The ANSI/ISO Standard C++ syntax was approved in mid-1998. 31

32 Helping Material Computer Science: A structured programming approach using C++ by Behrouz A. Forouzan, Richard F.Gilberg C++ How to Program, 4 th Edition by Deitel and Deitle C++ Programming: Program Design including Data Structures Problem solving in C++ by D.S Malik 32

33 Thank You! 33


Download ppt "Introduction to Programming By: Prof. Muhammad Abu Baker Siddique 2 nd Lecture 1."

Similar presentations


Ads by Google