Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 29

PROGRAMMING

FUNDAMENTALS

LECTURE # 1: INTRODUCTION

BS
Joddat Fatima
1
joddat.fatima@gmail.com

Department of SE
Bahria University Islamabad
COURSE INFORMATION

 Instructor
Miss JODDAT FATIMA
Cabin: XC- Ground Floor
Email: joddat.fatima@gmail.com

 Office Hours
Monday-Wednesday : 10:30 to 12:30

2
WHO ARE YOU???

3
COURSE INFORMATION

 Course meeting times


 Lectures: 2 sessions/week (2+1)

 Course Ressources
 Object Oriented Programming in C++ by Robert Lafore
 C++ How to Programme by Dietel and Dietel
 A Structured Programjing Approach Using C++ by Behrouz A.
Forouzan

4
COURSE OBJECTIVE

 To introduce the concepts and the syntax of programming


language C++.

 To enable the students to develop skills of computer


programming using and simple logical problems

 Ability to analyze the requirements for solving simple


algorithmic problems.

5
COURSE CONTENTS

 Basic structure of C++


 I/O statements

 Operators

 Variables

 Selection Structure

 Repetition Structure

 Functions

 Arrays

 Structures

 Pointers
6
GRADING POLICY

7
INTRODUCTION

 COMPUTER
 Software
 Instructions to command computer to perform actions and make

decisions
 Hardware
 Various devices comprising computer

 Keyboard, screen, mouse, disks, memory, CD-ROM, processing units,

 The Ideal Way to Do Computing


 The ideal way to ask computer to do something is to order it in a natural

language e.g.
 I want to view this webpage 8
 Calculate my annual tax
WHY ANOTHER LANGUAGE?
 However, today’s computer’s are not intelligent enough to understand our orders
in natural language.

Ambiguity:
 The tourist saw the astronomer with the telescope
 The tourist used the telescope to see the astronomer.
 The astronomer that the tourist saw had a telescope.

Levels of Programming Language:


 Low-Level
 machine language 10110101011001
 Defined by hardware design
 High-Level
 Much more understandable 9
 A compiler translates high-level language into assembly language.
C++ TYPICAL ENVIRONMENT

 Phases of C++ Programs:


1. Edit
2. Preprocess
3. Compile
4. Link
5. Load
6. Execute

10
A WORD OF CAUTION

 IDEs, editors, debuggers, and other programming tools do not


write program themselves. They merely provide some help in
writing a program.

 Therefore,
THERE IS NO SHORTCUT TO PROGRAMMING
SKILLS AND EXPERIENCE.

11
HOW TO LEARN PROGRAMMING

 Everybody learns programming at their own pace.

 So do not be impressed by the person sitting next to you


because he coded a given program in 20 minutes and you are
taking more than an hour
Speed programming does not necessarily mean
quality of the final output.

12
HOW TO LEARN PROGRAMMING CONT..

 Writing a good description of the problem.


 Breaking down the given problem into small pieces.
 Turning small pieces into pseudo-code.
 Deciding the integration mechanism of the pieces.
 Writing the program for each piece.
 Integrating all the pieces together.

13
SCARE OF PROGRAMMING?

 Why most students are afraid of programming

 Paradigm Change
Programming is totally different paradigm. You are working on
something and you cannot even touch the final output you can only
feel it. It is different then other subjects like Physics, Chemistry,
Biology, etc.

 Peer Pressure
Some people are naturally good in programming so others think that
this is a natural ability and they cannot learn it.
Lack of Understanding in Fundamental Concepts 14
SCARE OF PROGRAMMING?

 Why most students are afraid of programming

 Lack of Understanding in Fundamental Concepts


Some people start programming without a clue of what is going on
behind the scene in the computer. As a result they have a flawed
understanding from day one of their programming experience

 Time Factor: Programming takes a lot of time


Programming may take a lot of time at the start but once a person is
comfortable with the concepts and has mastered the basic skills it is
just like any other profession.
15
A WORD OF ADVICE
 Without good command on programming any qualification in
Computer Science, Computer Engineering, Information
Technology and Software Engineering is “worthless”.

 There is an acute shortage of programmers in the global


software market and with time this shortage is increasing

16
17
18
19
PREPROCESSING DIRECTIVES

#include <iostream>

 Not a program statement its part of functioning body does


not need semi colon to end this.

 #include is called preprocessor directives while iostream is a


header file.

 It basically concerns the I/O in programming.


20
USING DIRECTIVES

using namespace std;

 A name space is a part of program it reorganize your certain


defined names; outside the namespace they are unknown.

 This shows that all program statements as follow are within


the this std namespace.

21
BASIC PROGRAM

 Start with common and one function i.e. main()

 Working controlled by main function

 Function start executing form first statement of main


sequence ends at main return 0;

 Body of a main surrounded by Braces { }

 If no main function error will be generated


22
PROGRAM STATEMENTS

 Fundamental Unit of the programming

 It tells the computer to do something that is required

 Always ends with a semi colon ; if not written error


generated.

 Compulsion statement of return 0; sends the program


back to initial position from where it was started.

23
COMMENTS IN C++

//comments.cpp
/*demonstrating comments*/

 Document programs
 Improve program readability

 Ignored by compiler

 Single-line comments & Multi-Line comments

24
DIVIDING CODE

 The separation in different lines of code has been done just to give
greater readability to the program, since main could have been
perfectly valid defined this way:

int main () { cout << " Hello World! "; cout << " I'm a C++ program ";
return 0;

 We were also free to divide the code into more lines if we considered it
more convenient:
int main ()
{
cout <<"Hello World!";
cout<< "I'm a C++ program";
return 0; 25
}
PROBLEM SOLVING TECHNIQUES

 What is the unknown?


 What is required?

 What are the data?


 What is given?

 What is the condition?


 By what condition the unknown is linked to the data?

26
CALCULATE AND PRINT THE AVERAGE GRADE
OF 3 TESTS FOR THE ENTIRE CLASS
 Input
 3 test scores for each student
 Output
 Average of 3 tests for each student
 Process
1. Get three scores
2. Add them together
3. Divide by three to get the average
4. Print the average
5. Repeat step 1 to 4 for next student
6. Stop if there are no more students
27
ALGORITHM ATM FOR WITHDRAWAL
 Output
 Money, error messages
 Inputs
 User Identification (ATM card), password, amount
 Process
1. Get the ATM card for identification and ask for password
2. Check password
3. If password is not valid, generate an error message and go to step number 8.
4. Get the amount from the user
5. Check the current balance
6. If amount is greater than current balance, generate an error message and go to
step number 8.
7. Subtract the amount from the balance and give out the cash.
8. Return the ATM card
9. Stop

28
29

You might also like