2. Course ObjectivesCourse Objectives
Objectives of this course are three foldObjectives of this course are three fold
1.1. To appreciate the need for aTo appreciate the need for a
programming languageprogramming language
2.2. To introduce the concept and usabilityTo introduce the concept and usability
of the structured programmingof the structured programming
methodologymethodology
3.3. To develop a useful program for theTo develop a useful program for the
processes that are used in Physicsprocesses that are used in Physics
22
3. Course ContentsCourse Contents
To achieve our first two objectives weTo achieve our first two objectives we
will be discussingwill be discussing
Basic Programming constructs andBasic Programming constructs and
building blocksbuilding blocks
Structured programmingStructured programming
OOP conceptsOOP concepts
33
4. Course ContentsCourse Contents
Introduction to C++Introduction to C++
Variables and expressionsVariables and expressions
Control structuresControl structures
– Decision MakingDecision Making
– LoopingLooping
User Defined FunctionsUser Defined Functions
44
5. Course ContentsCourse Contents
Arrays and PointersArrays and Pointers
Dynamic memory AllocationDynamic memory Allocation
File handlingFile handling
Structures and UnionsStructures and Unions
Object oriented programmingObject oriented programming
ConceptsConcepts
55
6. ResourcesResources
Books:Books:
– C++ How to Program by Deitel & DeitelC++ How to Program by Deitel & Deitel
– Let Us C++ by Yashavant KanetkarLet Us C++ by Yashavant Kanetkar
Slides, Materials from Internet etc.Slides, Materials from Internet etc.
66
7. Course PolicyCourse Policy
Policy for the distribution of marks andPolicy for the distribution of marks and
examination is as followsexamination is as follows
Assignments/Quiz 15%Assignments/Quiz 15%
Midterm 15 %Midterm 15 %
Final 70%Final 70%
77
8. Instructor ProfileInstructor Profile
Kamran UllahKamran Ullah
Lecturer in CS/IT, IBMSLecturer in CS/IT, IBMS
– Since September 2014Since September 2014
PhD Scholar in Computer SciencePhD Scholar in Computer Science
– From IIUI since Fall 2011From IIUI since Fall 2011
MS (CS)MS (CS)
– From IIUI in July 2011From IIUI in July 2011
4½ years teaching experience in4½ years teaching experience in
– Islamic Centre, University of PeshawarIslamic Centre, University of Peshawar
– Iqra National University, PeshawarIqra National University, Peshawar
– IIUI as visiting LecturerIIUI as visiting Lecturer
9. Computer ProgrammingComputer Programming
and Programmingand Programming
LanguageLanguage
Writing a code in computer languageWriting a code in computer language
which run again and again to do awhich run again and again to do a
specific task.specific task.
The term computer language includesThe term computer language includes
a wide variety of languages used toa wide variety of languages used to
communicate with computers (i.e. C+communicate with computers (i.e. C+
+, Java)+, Java)
99
10. What is a Program?What is a Program?
““A precise sequence of stepsA precise sequence of steps
toto
solve a particular problem”solve a particular problem”
1010
13. Critical SkillsCritical Skills
– AnalysisAnalysis
– Critical ThinkingCritical Thinking
– Attention to DetailAttention to Detail
1313
14. Design RecipeDesign Recipe
To design a program properly, weTo design a program properly, we
must:must:
– Analyze a problem statement, typicallyAnalyze a problem statement, typically
expressed as a word problemexpressed as a word problem
– Express its essence, abstractly and withExpress its essence, abstractly and with
examplesexamples
– Formulate statements and comments in aFormulate statements and comments in a
precise languageprecise language
– Evaluate and revise the activities in lightEvaluate and revise the activities in light
ofof
1414
15. Where to write program?Where to write program?
C++ is a compiler and compile yourC++ is a compiler and compile your
written program forwritten program for
– Checking ErrorsChecking Errors
– Ready to execute on computerReady to execute on computer
User should be provided a EnvironmentUser should be provided a Environment
(IDE) to write, compile and test the(IDE) to write, compile and test the
programprogram
– i.e: Borland C++, Dev C++, Visual C++i.e: Borland C++, Dev C++, Visual C++
– We will use Visual C++We will use Visual C++ 1515
16. First Program in C++First Program in C++
1.1. #include <iostream>#include <iostream>
2.2. using namespace std;using namespace std;
3.3. void main()void main()
4.4. {{
5.5. cout<<"In the name of Allah"<<endl;cout<<"In the name of Allah"<<endl;
6.6. cout<<"This is my first Program in C++...";cout<<"This is my first Program in C++...";
7.7. cin.get();cin.get();
8.8. }}
1616
19. Explain the ProgramExplain the Program
(line by line)(line by line)
#include <iostream>#include <iostream>
‘‘#’#’ uses for preprocessor directiveuses for preprocessor directive
HereHere #include#include is used include theis used include the
library function defined inlibrary function defined in iostreamiostream filefile
1919
20. Explain the ProgramExplain the Program
(line by line)(line by line)
using namespace stdusing namespace std
Basically, what usingBasically, what using namespacenamespace
stdstd does is to inject all the names of does is to inject all the names of
entities that exist in the stdentities that exist in the std
namespace into the global namespacenamespace into the global namespace
– i.ei.e coutcout andand endlendl
2020
21. Explain the ProgramExplain the Program
(line by line)(line by line)
void main()void main()
main()main() is the basic function telling theis the basic function telling the
computer to where the executedcomputer to where the executed
should be started.should be started.
voidvoid tells the computer that main()tells the computer that main()
function does not return any value.function does not return any value.
2121
22. Explain the ProgramExplain the Program
(line by line)(line by line)
{{ is used to start the main function andis used to start the main function and
}} is used to end the main function.is used to end the main function.
Actually it define a block of code.Actually it define a block of code.
Its mean that execution started in justIts mean that execution started in just
below thebelow the {{ and will remain alive whenand will remain alive when
it it get theit it get the }}
– But: A program has many blocksBut: A program has many blocks
2222
23. Program with many blocksProgram with many blocks
#include <iostream>#include <iostream>
using namespace std;using namespace std;
void main()void main()
{{
int F;int F;
cout<<“Enter value for F”;cout<<“Enter value for F”; cin>>F;cin>>F;
if(F<0)if(F<0)
{{
cout<<“F must be positive”;cout<<“F must be positive”;
exit(0);exit(0);
}}
cin.get();cin.get();
}}
2323
24. Explain the ProgramExplain the Program
(line by line)(line by line)
cout<<"In the name of Allah"<<endl;cout<<"In the name of Allah"<<endl;
cout<<cout<< is used for output a lineis used for output a line
– It may be a STRING directly given or mayIt may be a STRING directly given or may
a variable.a variable.
endlendl is used to end the line (as weis used to end the line (as we
used ENTER button in MSWord)used ENTER button in MSWord)
2424
25. Explain the ProgramExplain the Program
(line by line)(line by line)
cin.get()cin.get() stops the execution of thestops the execution of the
program until the user press theprogram until the user press the
ENTER button from keyboard.ENTER button from keyboard.
getch()getch() may also be used which ismay also be used which is
used to press any key.used to press any key.
2525
26. What does Semi-What does Semi-
Colon(;) do?Colon(;) do?
If you have noticed that there is aIf you have noticed that there is a
semi-colon(;) at the end some of lines.semi-colon(;) at the end some of lines.
Remember it is a rule that everyRemember it is a rule that every
statement must be end with a semi-statement must be end with a semi-
colon.colon.
2626
27. You can write multiple statement in aYou can write multiple statement in a
single line:single line:
cout<<“IIUI”;
cin.get();
==
cout<<“IIUI”; cin.get();
2727
What does Semi-What does Semi-
Colon(;) do?Colon(;) do?
28. SummarySummary
Course IntroductionCourse Introduction
Programming LanguageProgramming Language
What is a Program?What is a Program?
Writing a simple Program and Line-by-Writing a simple Program and Line-by-
Line ExplanationLine Explanation
2828