0% found this document useful (0 votes)
24 views13 pages

Computer Programming 01

The document discusses procedural versus object oriented programming and provides an introduction to basic C++ programming concepts like program structure, the main function, input/output streams, and escape characters. It also covers common errors in programming like syntax, runtime, and logic errors.

Uploaded by

Salman shakeel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views13 pages

Computer Programming 01

The document discusses procedural versus object oriented programming and provides an introduction to basic C++ programming concepts like program structure, the main function, input/output streams, and escape characters. It also covers common errors in programming like syntax, runtime, and logic errors.

Uploaded by

Salman shakeel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

COMPUTER

PROGRAMMING

Lecture 01
(Introduction)

Dr. Muniba Ashfaq


PROCEDURAL VS OBJECT
ORIENTED PROGRAMMING
 Procedural Programming
A procedural programming language is an
important programming language whose
programs have the ability to be primarily
structured in terms of reusable procedures, e.g.
subroutines and/or functions.
 Object-oriented Programming
 Object-oriented programming (OOP) is a
programming paradigm based on the concept of
"objects", which may contain data, in the form of
fields, often known as attributes; and code, in
the form of procedures, often known as
methods.
Dr. Muniba Ashfaq 2
HIGH-LEVEL LANGUAGE
10100110 01110110
#include <iostream> 00100110 00000000
11111010 11111010
int main() 01001110 10100110
{ 11100110 10010110
std::cout<<“HelloWorld”; 11001110 00101110
return 0; 10100110 01001110
11111010 01100110
}
01001110 10000110
etc...

Source code Executable code

 Compilers and linkers translate a


high level program into executable
machine code. Dr. Muniba Ashfaq 3
STRUCTURE OF C++ PROGRAM
 C++ program consists of three main parts;
 Preprocessor Directives.
 Start with “#”
 Themain( ) function.
 C++ statements.

C++ Program:
#include <iostream>

int main()
{
std::cout<<“Hello World!”;
return 0;
}

Dr. Muniba Ashfaq 4


BASIC STRUCTURE OF
A C++ PROGRAM
Example: Hello World
C++ Program:
#include <iostream>

int main()
{
output “Hello World!” std::cout<<“Hello World!”;
return 0;
}

Dr. Muniba Ashfaq 5


BASIC STRUCTURE OF
A C++ PROGRAM (CONT)

Example: Hello world


C++ Program:
#include <iostream>

int main()
Includes standard input/output {
library of procedures. std::cout<<“Hello World!”;
Read: “Hash-include” return 0;
}

Dr. Muniba Ashfaq 6


BASIC STRUCTURE OF
A C++ PROGRAM (CONT)

Example: Hello world


C++ Program:
#include <iostream>

int main()
{
std::cout<<“Hello World!”;
return 0;
every C++ program must have a
}
main

Dr. Muniba Ashfaq 7


BASIC STRUCTURE OF
A C++ PROGRAM

Example: Hello World

C++ Program:
#include <iostream>

int main()
{
Curly braces mark the beginning std::cout<<“Hello
and end of a block of World”;
instructions. return 0;
}

Dr. Muniba Ashfaq 8


BASIC STRUCTURE OF
A C++ PROGRAM

Example: Hello World

C++ Program:
#include <iostream>
Instruction (function call) to output int main()
“Hello World” {
std::cout<<“Hello
World”;

return 0;
}

Dr. Muniba Ashfaq 9


BASIC STRUCTURE OF
A C++ PROGRAM
“Statements” (lines of
instructions) always end with a
Example: Hello World semi-colon (;)

C++ Program:
#include <iostream>

int main()
{
std::cout<<“Hello
World”;
return 0;
}

Dr. Muniba Ashfaq 10


EXPLANATION
 Standard output stream object
 std::cout
 “Connected” to screen
 <<
 Stream insertion operator
 Value to right (right operand) inserted into output stream
 Namespace
 std:: specifies using name that belongs to “namespace” std
 std:: removed through use of using statements (using
namespace std;)
 Escape characters
 \
 Indicates “special” character output

Dr. Muniba Ashfaq 11


Escape Character
 Indicates that a “special” character is to be output
Escape Sequence Description

\n Newline. Position the screen cursor to the


beginning of the next line.
\t Horizontal tab. Move the screen cursor to the
next tab stop.
\r Carriage return. Position the screen cursor to the
beginning of the current line; do not advance to
the next line.
\a Alert. Sound the system bell.

\\ Backslash. Used to print a backslash character.

\" Double quote. Used to print a double quote character.

Dr. Muniba Ashfaq 12


PROGRAM ERRORS
 Syntax errors
 Violation of the grammar rules of the language
 Discovered by the compiler
 Error messages may not always show correct location of
errors
 Run-time errors
 Error conditions detected by the computer at run-time
 Logic errors
 Errors in the program’s algorithm
 Most difficult to diagnose
 Computer does not recognize an error

Dr. Muniba Ashfaq 13

You might also like