Lecture 1 Introduction.pptx hfjsh huwhf uwej wiuehfi w

muhammadumairsoftwar 53 views 27 slides Feb 27, 2025
Slide 1
Slide 1 of 27
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27

About This Presentation

nfjjfsa


Slide Content

Programming Fundamentals CSPF 121 BSCS 1 Spring 2024

COURSE OBJECTIVES To introduce the concept and usability of the structured programming methodology To develop proficiency in making useful software using the C++ language/ python. To appreciate the need for a programming language Improving reasoning abilities to solve problems commonly encountered when writing programs and developing skills necessary to structure programs in a logical manner.

COURSE CONTENT History of C Language Variables and expressions in C++ Control structures Functions Arrays Structure Pointers File handling

Computers and Programming A computer is just a machine (the hardware ) for executing programs (the software ) Hence, the software rules the hardware! The process of creating software is called programming , and it is the focus of this course Virtually, anyone can learn how to program computers It requires only some grit!

Hardware Basics To be a successful programmer, you need to know some details of how computers work For instance, understanding the basics of hardware will help you analyze the performance (or efficiency ) of any of your programs Will the data of your program fit in memory ? If not, how would that impact the performance of your program? Is your program CPU-bound or IO-Bound ? If CPU-bound, how powerful is your CPU? If IO-bound, how big is your disk or network bandwidth?

Functional View of a Computer Input Devices CPU Main Memory Output Devices Secondary Memory

Program “A precise sequence of steps to solve a particular problem”

Functional View of a Computer E.g., Hard Disk The secondary memory is where your saved program and data reside It is a non-volatile storage I.e., when the power is turned off, your program and data will NOT be lost Secondary Memory

Functional View of a Computer Main Memory Secondary Memory E.g., Random Access Memory (RAM) The main memory is much faster (but more expensive) than the secondary one, however, it is volatile Your program and data are copied from secondary memory to main memory for efficiency reasons

Functional View of a Computer CPU Main Memory Secondary Memory The Central Processing Unit (CPU) is the “brain” of the computer It can at least perform: Arithmetic operations (e.g., adding 2 numbers) Logical operations (e.g., test if 2 numbers are equal) It can directly access information stored in main memory but not in secondary memory

Functional View of a Computer Input Devices CPU Main Memory Output Devices Secondary Memory E.g., Monitor E.g., Keyboard and mouse

Functional View of a Computer Input Devices Output Devices E.g., Keyboard and mouse E.g., Monitor Humans interact with computers via Input and Output (IO) devices Information from Input devices are processed by the CPU and may be shuffled off to the main or secondary memory When information need to be displayed, the CPU sends them to one or more Output devices

Programming Languages A program is just a sequence of instructions telling the computer what to do Obviously, we need to provide these instructions in a language that computers can understand We refer to this kind of a language as a programming language Python, Java, C and C++ are examples of programming languages Every structure in a programming language has an exact form (i.e., syntax ) and a precise meaning (i.e., semantic )

Things required to write a program 1. Source code 2. Text Editor 3. Compiler

1. SOURCE CODE: The files you create with your editor are called source files and for C++ they typically are named with the extension . cpp , . cp , or .c. The source code of a C++ program is stored on the disk with file extension . Any text editor be used to write and edit C++ source code

2. Text Editor This is a type of computer program that has an interface, menus, dialogue boxes and different options to write your desired code

3. Compiler C++ compiler translates a source program into the machine code . Machine code is called object code, which is stored in a new file with extension obj. The Object code is linked to the libraries. After linking an executable file with extension exe is created

High-Level to Low-Level Languages In a high-level language like Python, the addition of two numbers can be expressed more naturally: But, we need a way to translate the high-level language into a machine language that a computer can execute To this end, high-level language can either be compiled or interpreted c = a + b Much Easier!

Compiling a High-Level Language A compiler is a complex software that takes a program written in a high-level language and translates it into an equivalent program in the machine language of some computer Source Code (Program) Compiler Machine Code Running Program Inputs Outputs

Interpreting a High-Level Language An interpreter is a software that analyzes and executes the source code instruction-by-instruction ( on-the-fly ) as necessary E.g., Python is an interpreted language Source Code (Program) Computer Running An Interpreter Inputs Outputs

Compiling vs. Interpreting Compiling is a static (i.e., pre-execution), one-shot translation Once a program is compiled, it may be run over and over again without further need for the compiler or the source code Interpreting is dynamic (i.e., happens during execution) The interpreter and the source code are needed every time the program runs Compiled programs tend to be faster, while interpreted ones lend themselves to a more flexible programming environments ( they can be developed and run interactively )

Programming Language Generations Generations of programming languages are categorized into 5 categories First Generation of programming Language or 1GL string of 0s and 1s Second Generation of programming Language or 2GL sometimes called Assembly language e.g. ADD 12, 8 An assembler converts the assembly language statements into machine language.

Programming Language Generations Third Generation of Programming Language or 3GL Called High-Level programming languages such as C/C++, Pascal or Java etc Near to English Compiled type languages i.e. C/C++, Pascal, COBOL and Fortran etc Interpreter based languages i.e. QBasic, GW-Basic and Visual Basic etc are 3GL.

Programming Language Generations Fourth Generation of Programming Language or 4GL designed to be closer to natural language than a 3GL. for accessing databases are often described as 4GLs e.g. SELECT NAME FROM EMPLOYEES WHERE SALARY > $7000

Fifth Generation of Programming Language or 5GL use a visual or graphical development interface to create source language IBM, Microsoft, Borland etc Visual Studio.NET, JBuilder, NetBeans etc.

3) What is debugging? Debugging is the process of finding and removing errors in a program. In this process, the program is thoroughly checked for errors. Then errors are pointed out and debugged. 4) Name different types errors which can occur during the execution of a program? Syntax Errors Runtime Errors Logical errors  5) When a syntax error occurs? A syntax error occurs when the program violates one or more grammatical rules of the programming language. These errors are detected at compile time, i.e., when the translator (compiler or interpreter) attempts to translate the program.

6) When a runtime error occurs? A runtime error occurs when the computer is directed to perform an illegal operation by the program such as dividing a number by zero. Runtime errors are the only errors which are displayed immediately during the execution of a program. When these errors occur, the computer stops the execution of the programming and can display a diagnostic message that will help in locating the error. 7) When a logical error occurs? The logical error happens when a program implements a wrong logic. The translator (compiler or interpreter) does not report any error message for a logical error. These errors are the most difficult to locate. 8) What is flowchart? The flowchart is a pictorial representation of a program which helps in understanding the flow of control and data in the algorithm. 9) What is an algorithm? An algorithm is a finite set of steps which, if followed, accomplish a particular task. An algorithm must be clear, finite and effective.
Tags