Sie sind auf Seite 1von 25

1st Oct, 2018

PROGRAMMING FUNDAMENTALS

Course Instructor: Khalil Ullah,PhD


Assistant Prof. and HoD
Department of
Software Engineering
University of Malakand

Lecture # 1
Contents of Today’s Lecture
 Welcome
 Course Syllabus
 Tentative Schedule
 An Important Note to the Students
 Introduction
Course Outline
Course Text Book
Reference Book1
Reference Book2
Reference Book3
An Important Note to the Students
 This is a basic and one of the most important course in Software Engineering.
Although this field is an exciting and challenging discipline, the course may
intimidate you. A good textbook and a good instructor are an advantage but you
are the one who does the learning. If you keep the following ideas in mind, you will
go through this course very well.
 This course is a foundation for some exciting and challenging courses and fields like
database, multi-media programming, digital image processing, microprocessors,
web designing, databases and many other advanced programming language
 This course is also a foundation for successful completion of your Final Year Project.
 Writing codes is an essential part of SE program. If you can code no one can stop
you from getting a good job.
 Attempt the exercise and some review questions at the end of each chapter and try
to make logic for it. Then try to code it.
 Strong mathematical programming and logical background will be fruitful.
Basic Background
 The Basic Background assumed for this course is
 DigitalLogic Design; Numbering systems, Bolean
Algebra.
 Introduction to Computing

 Programming fundamentals
Assesment
Method Quantity (%)
Attendance& participation - 00
Quizzes/assignments 6 20
Term projects/presentations 1/1 00
Midterm Exam(s) 1 30
Final Exam 1 50

10
COURSE OBJECTIVE
• This course aims to prepare undergraduates for
the programming work they will undertake
during their time in Undergraduate program
and subsequently, including
subsequent programming-heavy courses such
as Compilers and Database Systems
Implementation, in addition to the group
project and later individual project work.

11
Course Information
• Class Policies
– Attendance
• Full Attendance !!! No Leaves
• Genuine Reasons (20% of lectures)
– Collaborations
• Discussions & Exchange of ideas is encouraged
• Copying/Cheating will NOT be tolerated
• VIVA would DEFINITELY be conducted for group
reports (if any)

12
C and C++
• The C programming language is incredibly
popular, and it's easy to see why.
• Programming in C is efficient and gives the
programmer a great deal of control.
• Many other programming languages like C++,
Java and Python were developed using C.
• Chances are increasing each day that if you're a
programmer, you won't use C++ exclusively for
your work.
• However, learning C++ is highly beneficial, even
if you don't use it regularly. Here's why:
13
Why C and C++?
• You'll be able to read and write code for software that can be used on many
different types of computer platforms, including everything from small
microcontrollers to desktop, laptop and mobile operating systems.
• You'll better understand what high-level languages are doing behind the
scenes, such as memory management and garbage collection. This
understanding can help you write programs that work more efficiently.

• If you're a software developer, you could also benefit from learning C.


Software developers often write, maintain and run scripts as part of their
job. A script is a list of instructions for a computer's operating system to
follow. To run certain scripts, the computer sets up a controlled execution
environment called a shell. Since most operating systems run shells based
on C, C shell is a popular scripting adaptation of C used by IT pros.

14
OOP – Object Oriented
Programming
• Programming Languages • Non-Procedural Programming
– Procedural Languages
– Object Oriented
int main()
{
• Procedural Programming
int a, b, c, d, e, y;
Languages (action oriented)
….
LOAD D y=(a-b)/(c+d*e);
MUL E }
ADD C
STOR Y
LOAD A
SUB B
DIV Y
STOR Y
A B
Y 
C  DE 15
C++ History
• BCPL (1967)
BCPL B
– Martin Richards
– Language for writing OS &
compilers
• B (1970) C
– Ken Thompson
– Used to create early
version of UNIX @ Bell
C++
• C
– Dennis Ritchie @ Bell
– Hardware Independent
• C++ (1980)
– Bjarne Stroustrup
– OO Extension of C

16
C & C++
• C++ is superset of C
• Everything done in C can be done in C++
• C++ extends C in 5 directions
– Operator & Function Overloading
– Information Hiding (Abstraction)
– Inheritance
– Polymorphism (Virtual Functions)
– Library Building (Templates, Exceptions)
• Most of these are OO concepts. Hence we can
say that OO C is actually C++

17
C++ Std Library
• C++ programs consist of classes & functions
• Programmers can also use existing classes and
functions provided in the C++ standard library
(for saving time)
• How to learn C++? 2 Aspects:
– Learn how to code in C++
– Learn how to use the C++ standard library
• A Note on Standard Libraries
– Some are released by compiler vendors
– Others are released by independent vendors
• Reference: Plauger’s Standard C Library
18
C++ Development Environment
• C++ System Parts • Development Tools:
– Development Environment – Borland C++ Builder
– Language – Microsoft Visual C++
– Standard C++ Library – GNU C++
• Phases:
– Edit
– Pre-Process
– Compile
– Link
– Load
– Execute

19
Program is created in
Editor Disk the editor and stored 1. Create Program
on disk.
2. Pre-Processor
Preprocessor Disk
Preprocessor program • Invoked Automatically
processes the code.
• Text replacements
Compiler creates
Compiler object code and stores
• What other files to
Disk
it on disk. compile?
Linker links the object 3. Compiler
Linker code with the libraries,
Disk
creates a.out and • Translates into
stores it on disk compatible Machine
Primary
Memory Language code (Obj
Loader code)
Loader puts program
• Contains “holes”
in memory.
Disk
4. Linking
..
..
..
• Links functions
described elsewhere
Primary (e.g., std. libraries)
Memory
CPU
CPU takes each
• Complete Obj code
instruction and with no holes is
executes it, possibly produced
storing new data
..
values as the program 5. Loading
.. executes. 20
..
6. Execution
Other details
• What If Scenario’s:
– A Program fails?
– Divide by Zero? (Illegal operation)
• Input/Output
– cin
• standard input stream
• normally keyboard but c. b. changed
– cout
• Standard output stream
• normally screen but c. b. changed
– cerr
• Standard error stream
• Display error messages (on screen)
21
Down to Business
• Sample Hello World
Name cout belongs to
1 // Fig. 1.2: fig01_02.cpp namespace std.
2 // A first program in C++. Function main returns an
3 #include <iostream> integer value.
Statements end with a semicolon
4
;
5 // function main begins program execution Pre-processor directive is
6 int main() excluded
\ is an escape sequence
7 { \n new line
8 std::cout << "Welcome to C++!\n"; \t tab
\r cursor to beginning of current
9
line
10 return 0; // indicate that program ended successfully \a sound alert
11 \\ used to print backslash
character
12 } // end function main \’ single quote character
\” double quote character
Welcome to C++! Keyword return is one of
several means to exit function;
value 0 indicates program 22
terminated successfully.
Down to Business
• Sample Add Integer

23
Declare integer variables.
1 // Fig. 1.6: fig01_06.cpp
2 // Addition program.
Calculations can be performed in
3 #include <iostream> output statements: alternative for
4 lines 18 and 20:
5 // function main begins program execution
std::cout << "Sum is " <<
6 int main() integer1 + integer2 << std::endl;
7 {
8 int integer1; // first number to be input by user Use stream extraction operator with
standard input stream to obtain user
9 int integer2; // second number to be input by user input.
10 int sum; // variable in which sum will be stored
11 Stream manipulator
std::endl outputs a
12 std::cout << "Enter first integer\n"; // prompt newline, then “flushes output
13 std::cin >> integer1; // read an integer buffer.”On some systems
where outputs accumulate in
14 the machine until there are
15 std::cout << "Enter second integer\n"; // prompt enough to make it display on
16 std::cin >> integer2; // read an integer the screen.It forces any
accumulated aoutput to be
17 displayed at that moment
18 sum = integer1 + integer2; // assign result to sum
19
20 std::cout << "Sum is " << sum << std::endl; // print sum
21
22 return 0; // indicate that program ended successfully
23
24 } // end function main Concatenating, chaining or
cascading stream insertion24
operations.
Reading Material
• Week 1
– From Chapter 1
• Software engineering case study: Introduction to
object technology and UML, 5th Edition, pp22
• History of C and C++, pp8
• C++ standard library, pp8
• Typical C++ development environment, pp12

25

Das könnte Ihnen auch gefallen