SlideShare a Scribd company logo
1 of 47
Introduction to Programming


      Lab No. 1
        saqib.rasheed@mail.au.edu.pk




                Air University         1
Platform

  Air University   2
Tools of the trade

• Editor
• Interpreter and Compilers
• Debuggers



             Air University   3
Integrated Development Environment
                (IDE)


  It contains
        •   Editor
        •   Compilers
        •   Debugger
        •   Linkers
        •   Loaders



              Air University         4
Program is created in the
  Editor               Disk         editor and stored on disk.
                                     Preprocessor program
Preprocessor           Disk          processes the code.
                                    Compiler creates
 Compiler             Disk          object code and stores
                                    it on disk.
  Linker              Disk          Linker links the object
                                    code with the libraries
                 Primary Memory
  Loader
                                     Loader puts program
                                     in memory.
    Disk                    ..
                            ..
                            ..



               Primary Memory
                                     CPU takes each
   CPU                               instruction and
                                     executes it, possibly
                                     storing new data
                            ..
                            ..
                                     values as the program
                            ..
                                     executes.


                   Air University                                5
First Program


No we are going to write first program in
                   C++




                  Air University            6
#include <iostream.h>
main ( )
{
  cout << “ Welcome to Air University “;
}



                  Air University           7
cout<< can be used with
• Variable
  – cout<<num;
• String
  – cout<<“Hello Word”;
• Expression
  – cout<<a + b;
• Constant
  – cout<<20;
• Call of Function
  – cout<<pow(a);
Escape Sequence
a     Bell (beep)
b     Backspace
n     New Line
r     Return
t     Tab (8 spaces)




                        9
#include <iostream.h>
main ( )
{
cout << “nt Welcome to Air University n“;
cout<<“ nSchool of Engineeringn”;
}



                                               10
Practice Que 1
Write a program to display following output,
                  *****                           *****
                  *****                           *****
                  *****                           *****
                  *****                           *****
                  *****                           *****
                  *****                           *****
                  *****                           *****
                  *****                           *****
                  *****                           *****
                  *****                           *****
                  *****                           *****
                    #################################
                    #################################
                    #################################

                               Air University             11
Practice Que 2
Write a program which prints following output,
$******************************************$
$******************************************$
$*           Welcome to Air University         *$
$*           School of Engineering             *$
$*                   lslamabad.                *$
$****************************************** $
$****************************************** $



                       Air University               12
Variable

Variable                X



       Air University       13
•   Pic of the memory
                        Variable
•   25




             name
•   10323    of the
             variable




                          Air University   14
Variable
Rules to Write Variable.
  1.   First Letter Character
  2.   Underscore _ (Not Recommended)
  3.   Can’t use real numbers (Syntax Errorr)

           int num1;




                        Air University          15
Variable
• Small post box




                   X


                   Air University   16
Variable
Variable is the name of a location in
the memory

         e.g. x= 2;




                      Air University    17
Variable
In a program a variable has:
1. Name
2. Type
3. Size
4. Value


             Air University    18
Variable
i.e


      int x = 2;
      float y = 3.6

             Air University   19
Assignment Operator
        =
       x=2


X               2
            Air University   20
Assignment Operator
L.H.S = R.H.S.

X+ 3 = y + 4 Wrong
Z = x +4

x +4 = Z   Wrong


                   Air University   21
X = 10 ;           X        10
X = 30 ;
                   X        30

           Air University    22
X = X + 1;

    10                              + 1
                           =   11

X
          Air University                  23
Example Of Assignment Operator
#include <iostream.h>
void main ()
{
  int a, b;
  a = 10;
  b = 4;
  a = b;
  b = 7;
  cout << "a :";
  cout << a;
  cout << " b :";
  cout << b;
}




                    Air University   24
Data type
• int i ; -> Declaration line




                                                 i
                                Air University       25
#include <iostream.h>
main ( )
{
   int x ;
   int y ;
   int z ;
   x = 10 ;
   y = 20 ;
   z=x+y;

    cout << " x = " ;
    cout << x ;

    cout<< " Y = " <<y;

    cout << " z =x + y " << x+y ;
}



                                    Air University   26
int x, y, z ;
int x; int y; int z ;


         Air University   27
Data Types
 1.   int
 2.   short
 3.   long
 4.   float
 5.   double
 6.   char
       Air University   28
Arithmetic operators
Plus          +
Minus         -
Multiply      *
Divide        /
Modulus       %


           Air University   29
Arithmetic operators

      i+j
      x*y
      a/b
      a%b
      Air University   30
% = Remainder

 5%2=1
 2%2=0



   Air University   31
4/2=2
5/2=?


 Air University   32
Precedence
• Highest:                    ()
• Next:                        *,/,%
• Lowest:                      +,-




             Air University            33
Precedence
21.2   5     192                      19.2




                       3
          24        8

             2




                                  1
  X = 2 + 4 * 6 ( 10 – 2 ) / 10
   Y = 10 / 5 * 2 ( 8 - 2 ) + 6



                 Air University              34
Quadratic Equation
• In algebra
           y = ax2 + bx + c

• In C
           y = a*x*x + b*x + c




                                 35
a*b%c +d

           36
a*(b%c) = a*b%c



                  37
Practice Que 3
Write a program in C++, which takes radius from
 the user and calculate the area of sphere i.e
          Area=4pr2

(Hint p = 3.1416
Area = 4 * 3.1416 * r * r)



                       Air University         38
Practice Que 4




Write a program to find the number of bytes
 occupied by various data types using the
 sizeof operator?




                     Air University           39
Practice Que 4
                           (Code)
#include<iostream.h>
void main ()
{
   int a;              //Declaration of Variables for all data type
   char b;
   float c;
   long int d;
   bool e;
   short f;
   double g;
   unsigned char h;
   unsigned short i;
   unsigned int j;
   unsigned long k;



                                Air University                        40
Practice Que 4
                             (Code)
    cout<<"nThe Size of Integer is    = "<<sizeof(a);
    cout<<"nThe Size of Chacter is     = "<<sizeof(b);
    cout<<"nThe Size of Float is    = "<<sizeof(c);
    cout<<"nThe Size of Long Integer is = "<<sizeof(d);
    cout<<"nThe Size of Boolean is     = "<<sizeof(e);
    cout<<"nThe Size of Short is     = "<<sizeof(f);
    cout<<"nThe Size of Double is      = "<<sizeof(g);
    cout<<"nThe Size of Unsigned char is = "<<sizeof(h);
    cout<<"nThe Size of Unsigned short is = "<<sizeof(i);
    cout<<"nThe Size of Unsigned int is = "<<sizeof(j);
    cout<<"nThe Size of Unsigned Long is = "<<sizeof(k)<<endl;
}


                                 Air University                   41
Simple Program In C++ using 5 Arithmetic
               Operators


1)   + (Plus)
2)   - (Minus)
3)   * (Multiply)
4)   / (Divide)
5)   % (Modulo)
                    Air University          42
Assignment No 1
Write a program that take two values from user
 and perform all arithmetic operation on them
             and display the result.




                    Air University           43
Instructions of Assignment
     •   Take help from books
     •   Take help from Internet
     •   Do not copy paste
     •   Copied assignments will be marked Zero
     •   Viva will be conducted in next lab
     •   Total Marks 15
     •   Last date Next Lab
     •   Late assignment will not be considered

44
Simple Program In C++ using 5 Arithmetic
                 Operators
#include<iostream.h> //Header File Used for Input/Output
void main ()              //Mian Funcation Starting With Braces
{
   int num1, num2, res; //Declaring Three Variables of type int
   cout<<"Enter the First Number= ";     //Display the Statement
   cin>>num1;                            //Stores the value in memory
   cout<<"Enter the Second Number= ";
   cin>>num2;

   res = num1 + num2; //Adding two Integers
   cout<<"Addition = "<<res<<endl;
   res = num1 - num2; //Subtracting two Integers



                                Air University                          45
Simple Program In C++ using 5 Arithmetic
                Operators
cout<<"Subtraction ="<<res<<endl;
  res = num1 * num2;       //Multiplication two Integers

  cout<<"Multiplication ="<<res<<endl;
  res = num1 / num2;       //Dividing two Integers

  cout<<"Division = "<<res<<endl;
  res = num1 % num2;       //Modulus of two Integers

  cout<<"Modulus = "<<res<<endl;
}     //End of Mian Funcation

                           Air University                  46
For Slides



https://sites.google.com/site/saqibrashied/cplusplus

More Related Content

What's hot

Reanalyzing the Notepad++ project
Reanalyzing the Notepad++ projectReanalyzing the Notepad++ project
Reanalyzing the Notepad++ projectPVS-Studio
 
Top 10 C# projects errors found in 2016
Top 10 C# projects errors found in 2016Top 10 C# projects errors found in 2016
Top 10 C# projects errors found in 2016PVS-Studio
 
Source code of WPF samples by Microsoft was checked
Source code of WPF samples by Microsoft was checkedSource code of WPF samples by Microsoft was checked
Source code of WPF samples by Microsoft was checkedPVS-Studio
 
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1PVS-Studio
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manualAnil Bishnoi
 
A Slipshod Check of the Visual C++ 2013 Library (update 3)
A Slipshod Check of the Visual C++ 2013 Library (update 3)A Slipshod Check of the Visual C++ 2013 Library (update 3)
A Slipshod Check of the Visual C++ 2013 Library (update 3)Andrey Karpov
 
Picking Mushrooms after Cppcheck
Picking Mushrooms after CppcheckPicking Mushrooms after Cppcheck
Picking Mushrooms after CppcheckAndrey Karpov
 
Tesseract. Recognizing Errors in Recognition Software
Tesseract. Recognizing Errors in Recognition SoftwareTesseract. Recognizing Errors in Recognition Software
Tesseract. Recognizing Errors in Recognition SoftwareAndrey Karpov
 
PVS-Studio vs Chromium - Continuation
PVS-Studio vs Chromium - ContinuationPVS-Studio vs Chromium - Continuation
PVS-Studio vs Chromium - ContinuationPVS-Studio
 
C programming session 02
C programming session 02C programming session 02
C programming session 02Vivek Singh
 
Checking OpenCV with PVS-Studio
Checking OpenCV with PVS-StudioChecking OpenCV with PVS-Studio
Checking OpenCV with PVS-StudioPVS-Studio
 
Checking the Source Code of FlashDevelop with PVS-Studio
Checking the Source Code of FlashDevelop with PVS-StudioChecking the Source Code of FlashDevelop with PVS-Studio
Checking the Source Code of FlashDevelop with PVS-StudioPVS-Studio
 
Top 10 bugs in C++ open source projects, checked in 2016
Top 10 bugs in C++ open source projects, checked in 2016Top 10 bugs in C++ open source projects, checked in 2016
Top 10 bugs in C++ open source projects, checked in 2016PVS-Studio
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++cpjcollege
 
Brief analysis of Media Portal 2 bugs
Brief analysis of Media Portal 2 bugsBrief analysis of Media Portal 2 bugs
Brief analysis of Media Portal 2 bugsPVS-Studio
 
I just had to check ICQ project
I just had to check ICQ projectI just had to check ICQ project
I just had to check ICQ projectPVS-Studio
 

What's hot (19)

Reanalyzing the Notepad++ project
Reanalyzing the Notepad++ projectReanalyzing the Notepad++ project
Reanalyzing the Notepad++ project
 
Top 10 C# projects errors found in 2016
Top 10 C# projects errors found in 2016Top 10 C# projects errors found in 2016
Top 10 C# projects errors found in 2016
 
Source code of WPF samples by Microsoft was checked
Source code of WPF samples by Microsoft was checkedSource code of WPF samples by Microsoft was checked
Source code of WPF samples by Microsoft was checked
 
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 1
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manual
 
A Slipshod Check of the Visual C++ 2013 Library (update 3)
A Slipshod Check of the Visual C++ 2013 Library (update 3)A Slipshod Check of the Visual C++ 2013 Library (update 3)
A Slipshod Check of the Visual C++ 2013 Library (update 3)
 
Picking Mushrooms after Cppcheck
Picking Mushrooms after CppcheckPicking Mushrooms after Cppcheck
Picking Mushrooms after Cppcheck
 
Tesseract. Recognizing Errors in Recognition Software
Tesseract. Recognizing Errors in Recognition SoftwareTesseract. Recognizing Errors in Recognition Software
Tesseract. Recognizing Errors in Recognition Software
 
PVS-Studio vs Chromium - Continuation
PVS-Studio vs Chromium - ContinuationPVS-Studio vs Chromium - Continuation
PVS-Studio vs Chromium - Continuation
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
CodeChecker summary 21062021
CodeChecker summary 21062021CodeChecker summary 21062021
CodeChecker summary 21062021
 
Checking OpenCV with PVS-Studio
Checking OpenCV with PVS-StudioChecking OpenCV with PVS-Studio
Checking OpenCV with PVS-Studio
 
Checking the Source Code of FlashDevelop with PVS-Studio
Checking the Source Code of FlashDevelop with PVS-StudioChecking the Source Code of FlashDevelop with PVS-Studio
Checking the Source Code of FlashDevelop with PVS-Studio
 
Top 10 bugs in C++ open source projects, checked in 2016
Top 10 bugs in C++ open source projects, checked in 2016Top 10 bugs in C++ open source projects, checked in 2016
Top 10 bugs in C++ open source projects, checked in 2016
 
Deep C
Deep CDeep C
Deep C
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
C++ practical lab
C++ practical labC++ practical lab
C++ practical lab
 
Brief analysis of Media Portal 2 bugs
Brief analysis of Media Portal 2 bugsBrief analysis of Media Portal 2 bugs
Brief analysis of Media Portal 2 bugs
 
I just had to check ICQ project
I just had to check ICQ projectI just had to check ICQ project
I just had to check ICQ project
 

Viewers also liked

Labmanualc2ndedition2 2-121115034959-phpapp02
Labmanualc2ndedition2 2-121115034959-phpapp02Labmanualc2ndedition2 2-121115034959-phpapp02
Labmanualc2ndedition2 2-121115034959-phpapp02Getachew Ganfur
 
Artificial Intelligence Presentation
Artificial Intelligence PresentationArtificial Intelligence Presentation
Artificial Intelligence Presentationlpaviglianiti
 
How chinese english deviates from standard english
How chinese english deviates from standard englishHow chinese english deviates from standard english
How chinese english deviates from standard englishKogura
 
We bill demo instructions
We bill demo instructionsWe bill demo instructions
We bill demo instructionsAmberBaylor
 
περιβαλλοντικές οργανώσεις ΓεωργιάκουΣ.
περιβαλλοντικές οργανώσεις ΓεωργιάκουΣ.περιβαλλοντικές οργανώσεις ΓεωργιάκουΣ.
περιβαλλοντικές οργανώσεις ΓεωργιάκουΣ.katerina_a
 
ΠΕΡΙΒΑΛΛΟΝΤΙΚΕΣ ΟΡΓΑΝΩΣΕΙΣ
ΠΕΡΙΒΑΛΛΟΝΤΙΚΕΣ ΟΡΓΑΝΩΣΕΙΣΠΕΡΙΒΑΛΛΟΝΤΙΚΕΣ ΟΡΓΑΝΩΣΕΙΣ
ΠΕΡΙΒΑΛΛΟΝΤΙΚΕΣ ΟΡΓΑΝΩΣΕΙΣkaterina_a
 
Mostafa Dawood Ali (National)
Mostafa Dawood Ali (National)Mostafa Dawood Ali (National)
Mostafa Dawood Ali (National)Mostafa Dawood
 
When a uniform distribution appears? 一様分を生成する数学的なメカニズム例3個についてのメモ
When a uniform distribution appears? 一様分を生成する数学的なメカニズム例3個についてのメモWhen a uniform distribution appears? 一様分を生成する数学的なメカニズム例3個についてのメモ
When a uniform distribution appears? 一様分を生成する数学的なメカニズム例3個についてのメモToshiyuki Shimono
 
Commissione pari opportunità lmaschile
Commissione pari opportunità lmaschileCommissione pari opportunità lmaschile
Commissione pari opportunità lmaschileflobertime
 
Spending time with bob pp 1
Spending time with bob pp 1Spending time with bob pp 1
Spending time with bob pp 1MarquiseW
 

Viewers also liked (20)

c++
c++c++
c++
 
Lab # 2
Lab # 2Lab # 2
Lab # 2
 
c++ lab manual
c++ lab manualc++ lab manual
c++ lab manual
 
Labmanualc2ndedition2 2-121115034959-phpapp02
Labmanualc2ndedition2 2-121115034959-phpapp02Labmanualc2ndedition2 2-121115034959-phpapp02
Labmanualc2ndedition2 2-121115034959-phpapp02
 
Artificial Intelligence Presentation
Artificial Intelligence PresentationArtificial Intelligence Presentation
Artificial Intelligence Presentation
 
How chinese english deviates from standard english
How chinese english deviates from standard englishHow chinese english deviates from standard english
How chinese english deviates from standard english
 
Projects
ProjectsProjects
Projects
 
Ownership
OwnershipOwnership
Ownership
 
We bill demo instructions
We bill demo instructionsWe bill demo instructions
We bill demo instructions
 
Presentación 3 menu
Presentación 3 menuPresentación 3 menu
Presentación 3 menu
 
περιβαλλοντικές οργανώσεις ΓεωργιάκουΣ.
περιβαλλοντικές οργανώσεις ΓεωργιάκουΣ.περιβαλλοντικές οργανώσεις ΓεωργιάκουΣ.
περιβαλλοντικές οργανώσεις ΓεωργιάκουΣ.
 
ΠΕΡΙΒΑΛΛΟΝΤΙΚΕΣ ΟΡΓΑΝΩΣΕΙΣ
ΠΕΡΙΒΑΛΛΟΝΤΙΚΕΣ ΟΡΓΑΝΩΣΕΙΣΠΕΡΙΒΑΛΛΟΝΤΙΚΕΣ ΟΡΓΑΝΩΣΕΙΣ
ΠΕΡΙΒΑΛΛΟΝΤΙΚΕΣ ΟΡΓΑΝΩΣΕΙΣ
 
Mostafa Dawood Ali (National)
Mostafa Dawood Ali (National)Mostafa Dawood Ali (National)
Mostafa Dawood Ali (National)
 
Naskah soal uas statistik 2014
Naskah soal uas statistik 2014Naskah soal uas statistik 2014
Naskah soal uas statistik 2014
 
1
11
1
 
Ppt 10 jurnal
Ppt 10 jurnalPpt 10 jurnal
Ppt 10 jurnal
 
When a uniform distribution appears? 一様分を生成する数学的なメカニズム例3個についてのメモ
When a uniform distribution appears? 一様分を生成する数学的なメカニズム例3個についてのメモWhen a uniform distribution appears? 一様分を生成する数学的なメカニズム例3個についてのメモ
When a uniform distribution appears? 一様分を生成する数学的なメカニズム例3個についてのメモ
 
The kleshas
The kleshasThe kleshas
The kleshas
 
Commissione pari opportunità lmaschile
Commissione pari opportunità lmaschileCommissione pari opportunità lmaschile
Commissione pari opportunità lmaschile
 
Spending time with bob pp 1
Spending time with bob pp 1Spending time with bob pp 1
Spending time with bob pp 1
 

Similar to Lab # 1

System programmin practical file
System programmin practical fileSystem programmin practical file
System programmin practical fileAnkit Dixit
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented TechnologiesUmesh Nikam
 
C_and_C++_notes.pdf
C_and_C++_notes.pdfC_and_C++_notes.pdf
C_and_C++_notes.pdfTigabu Yaya
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 FeaturesJan Rüegg
 
Hello world! Intro to C++
Hello world! Intro to C++Hello world! Intro to C++
Hello world! Intro to C++DSCIGDTUW
 
DeVry GSP 115 All Assignments latest
DeVry GSP 115 All Assignments latestDeVry GSP 115 All Assignments latest
DeVry GSP 115 All Assignments latestAtifkhilji
 
Friend this-new&delete
Friend this-new&deleteFriend this-new&delete
Friend this-new&deleteShehzad Rizwan
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++Marco Izzotti
 
project report in C++ programming and SQL
project report in C++ programming and SQLproject report in C++ programming and SQL
project report in C++ programming and SQLvikram mahendra
 

Similar to Lab # 1 (20)

Labsheet_3
Labsheet_3Labsheet_3
Labsheet_3
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
 
System programmin practical file
System programmin practical fileSystem programmin practical file
System programmin practical file
 
C programming day#1
C programming day#1C programming day#1
C programming day#1
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
 
C_and_C++_notes.pdf
C_and_C++_notes.pdfC_and_C++_notes.pdf
C_and_C++_notes.pdf
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
 
Hello world! Intro to C++
Hello world! Intro to C++Hello world! Intro to C++
Hello world! Intro to C++
 
C++
C++C++
C++
 
DeVry GSP 115 All Assignments latest
DeVry GSP 115 All Assignments latestDeVry GSP 115 All Assignments latest
DeVry GSP 115 All Assignments latest
 
Cinfo
CinfoCinfo
Cinfo
 
Functions
FunctionsFunctions
Functions
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
Friend this-new&delete
Friend this-new&deleteFriend this-new&delete
Friend this-new&delete
 
C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
C++ Question
C++ QuestionC++ Question
C++ Question
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
 
project report in C++ programming and SQL
project report in C++ programming and SQLproject report in C++ programming and SQL
project report in C++ programming and SQL
 
C Tutorials
C TutorialsC Tutorials
C Tutorials
 

Recently uploaded

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 

Recently uploaded (20)

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 

Lab # 1

  • 1. Introduction to Programming Lab No. 1 saqib.rasheed@mail.au.edu.pk Air University 1
  • 2. Platform Air University 2
  • 3. Tools of the trade • Editor • Interpreter and Compilers • Debuggers Air University 3
  • 4. Integrated Development Environment (IDE) It contains • Editor • Compilers • Debugger • Linkers • Loaders Air University 4
  • 5. Program is created in the Editor Disk editor and stored on disk. Preprocessor program Preprocessor Disk processes the code. Compiler creates Compiler Disk object code and stores it on disk. Linker Disk Linker links the object code with the libraries Primary Memory Loader Loader puts program in memory. Disk .. .. .. Primary Memory CPU takes each CPU instruction and executes it, possibly storing new data .. .. values as the program .. executes. Air University 5
  • 6. First Program No we are going to write first program in C++ Air University 6
  • 7. #include <iostream.h> main ( ) { cout << “ Welcome to Air University “; } Air University 7
  • 8. cout<< can be used with • Variable – cout<<num; • String – cout<<“Hello Word”; • Expression – cout<<a + b; • Constant – cout<<20; • Call of Function – cout<<pow(a);
  • 9. Escape Sequence a Bell (beep) b Backspace n New Line r Return t Tab (8 spaces) 9
  • 10. #include <iostream.h> main ( ) { cout << “nt Welcome to Air University n“; cout<<“ nSchool of Engineeringn”; } 10
  • 11. Practice Que 1 Write a program to display following output, ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ################################# ################################# ################################# Air University 11
  • 12. Practice Que 2 Write a program which prints following output, $******************************************$ $******************************************$ $* Welcome to Air University *$ $* School of Engineering *$ $* lslamabad. *$ $****************************************** $ $****************************************** $ Air University 12
  • 13. Variable Variable X Air University 13
  • 14. Pic of the memory Variable • 25 name • 10323 of the variable Air University 14
  • 15. Variable Rules to Write Variable. 1. First Letter Character 2. Underscore _ (Not Recommended) 3. Can’t use real numbers (Syntax Errorr) int num1; Air University 15
  • 16. Variable • Small post box X Air University 16
  • 17. Variable Variable is the name of a location in the memory e.g. x= 2; Air University 17
  • 18. Variable In a program a variable has: 1. Name 2. Type 3. Size 4. Value Air University 18
  • 19. Variable i.e int x = 2; float y = 3.6 Air University 19
  • 20. Assignment Operator = x=2 X 2 Air University 20
  • 21. Assignment Operator L.H.S = R.H.S. X+ 3 = y + 4 Wrong Z = x +4 x +4 = Z Wrong Air University 21
  • 22. X = 10 ; X 10 X = 30 ; X 30 Air University 22
  • 23. X = X + 1; 10 + 1 = 11 X Air University 23
  • 24. Example Of Assignment Operator #include <iostream.h> void main () { int a, b; a = 10; b = 4; a = b; b = 7; cout << "a :"; cout << a; cout << " b :"; cout << b; } Air University 24
  • 25. Data type • int i ; -> Declaration line i Air University 25
  • 26. #include <iostream.h> main ( ) { int x ; int y ; int z ; x = 10 ; y = 20 ; z=x+y; cout << " x = " ; cout << x ; cout<< " Y = " <<y; cout << " z =x + y " << x+y ; } Air University 26
  • 27. int x, y, z ; int x; int y; int z ; Air University 27
  • 28. Data Types 1. int 2. short 3. long 4. float 5. double 6. char Air University 28
  • 29. Arithmetic operators Plus + Minus - Multiply * Divide / Modulus % Air University 29
  • 30. Arithmetic operators i+j x*y a/b a%b Air University 30
  • 31. % = Remainder 5%2=1 2%2=0 Air University 31
  • 33. Precedence • Highest: () • Next: *,/,% • Lowest: +,- Air University 33
  • 34. Precedence 21.2 5 192 19.2 3 24 8 2 1 X = 2 + 4 * 6 ( 10 – 2 ) / 10 Y = 10 / 5 * 2 ( 8 - 2 ) + 6 Air University 34
  • 35. Quadratic Equation • In algebra y = ax2 + bx + c • In C y = a*x*x + b*x + c 35
  • 36. a*b%c +d 36
  • 38. Practice Que 3 Write a program in C++, which takes radius from the user and calculate the area of sphere i.e Area=4pr2 (Hint p = 3.1416 Area = 4 * 3.1416 * r * r) Air University 38
  • 39. Practice Que 4 Write a program to find the number of bytes occupied by various data types using the sizeof operator? Air University 39
  • 40. Practice Que 4 (Code) #include<iostream.h> void main () { int a; //Declaration of Variables for all data type char b; float c; long int d; bool e; short f; double g; unsigned char h; unsigned short i; unsigned int j; unsigned long k; Air University 40
  • 41. Practice Que 4 (Code) cout<<"nThe Size of Integer is = "<<sizeof(a); cout<<"nThe Size of Chacter is = "<<sizeof(b); cout<<"nThe Size of Float is = "<<sizeof(c); cout<<"nThe Size of Long Integer is = "<<sizeof(d); cout<<"nThe Size of Boolean is = "<<sizeof(e); cout<<"nThe Size of Short is = "<<sizeof(f); cout<<"nThe Size of Double is = "<<sizeof(g); cout<<"nThe Size of Unsigned char is = "<<sizeof(h); cout<<"nThe Size of Unsigned short is = "<<sizeof(i); cout<<"nThe Size of Unsigned int is = "<<sizeof(j); cout<<"nThe Size of Unsigned Long is = "<<sizeof(k)<<endl; } Air University 41
  • 42. Simple Program In C++ using 5 Arithmetic Operators 1) + (Plus) 2) - (Minus) 3) * (Multiply) 4) / (Divide) 5) % (Modulo) Air University 42
  • 43. Assignment No 1 Write a program that take two values from user and perform all arithmetic operation on them and display the result. Air University 43
  • 44. Instructions of Assignment • Take help from books • Take help from Internet • Do not copy paste • Copied assignments will be marked Zero • Viva will be conducted in next lab • Total Marks 15 • Last date Next Lab • Late assignment will not be considered 44
  • 45. Simple Program In C++ using 5 Arithmetic Operators #include<iostream.h> //Header File Used for Input/Output void main () //Mian Funcation Starting With Braces { int num1, num2, res; //Declaring Three Variables of type int cout<<"Enter the First Number= "; //Display the Statement cin>>num1; //Stores the value in memory cout<<"Enter the Second Number= "; cin>>num2; res = num1 + num2; //Adding two Integers cout<<"Addition = "<<res<<endl; res = num1 - num2; //Subtracting two Integers Air University 45
  • 46. Simple Program In C++ using 5 Arithmetic Operators cout<<"Subtraction ="<<res<<endl; res = num1 * num2; //Multiplication two Integers cout<<"Multiplication ="<<res<<endl; res = num1 / num2; //Dividing two Integers cout<<"Division = "<<res<<endl; res = num1 % num2; //Modulus of two Integers cout<<"Modulus = "<<res<<endl; } //End of Mian Funcation Air University 46