The document provides an introduction to programming in C++. It discusses tools used for programming like editors, compilers, debuggers and integrated development environments. It explains the steps involved in creating a program from writing code in an editor to compiling, linking and executing it. The document also covers basic C++ concepts like variables, data types, operators and arithmetic expressions. It includes examples of simple C++ programs and practice problems for readers.
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
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
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
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
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
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