Академический Документы
Профессиональный Документы
Культура Документы
Programming Language
KGiSL
Programming Language
2
is
KGiSL
Programming languages
High-level languages
E.g. add overtime to base pay and store result in gross pay
grossPay = basePay + overtimePay
KGiSL
Elementary
Advanced
Procedural
Procedural
Structure Oriented
Object
Advanced
Oriented
Object
Oriented
Eiffel
Fortran
Algol 68
C++
C#
Cobol
PL/I
Pascal
Ada 95
Java
Ada 83
KGiSL
What is C++?
5
KGiSL
Introduction to C++
6
Variables
7
KGiSL
Identifiers
8
a letter
the underscore character
KGiSL
letters
numbers
underscore character
Keywords
9
KGiSL
Types of C Constants
10
categories
Primary Constants
Secondary Constants
C Constants
Primary Constants
Integer Constant
Real Constant
Character Constant
KGiSL
Secondary constants
Array, Pointer
Structure, Union
enum
Data Types
11
KGiSL
short int
int
long int
float
double
long double
char
bool
Include files
Global variable and
function declaration/
Function Definition
main function
Function or subprogram
KGiSL
Comment
m
ty ain
pe r
in etu
te rn
ge s
r of
Includin
Fun
ctio
nm
g h eade
r files
ain
Insertion operator
Statement terminated
with ;
KGiSL
Phase 1
Editor
Program edited in
Disk
Phase 2
Preprocessor
Disk
program processes
the code
Phase 3
Phase 4
KGiSL
Compiler
Linker
Disk
Disk
Phase 5
Puts program in
Loader
memory
Primary memory
Phase 6
CPU
KGiSL
Comment
16
*/
program.
Comment cannot be nested.
It can be split over more than one line
KGiSL
Operators in C++
17
KGiSL
Types
18
1.
2.
3.
4.
5.
6.
7.
8.
KGiSL
Arithmetic operators
Relational operators
Logical operators
Assignment operators
Increment and decrement operators
Conditional operators
Bitwise operators
Special operators
Control Structures
19
KGiSL
Conditional Statements
Iteration Statements
Selective Statements
Jump Statements
ARRAYS
20
locations.
KGiSL
FUNCTIONS
21
programming.
The process of dividing a large program into small
Structure of Function
22
Typically originates
at the keyboard
at a file
Destination is typically
KGiSL
the monitor
a file
KGiSL
KGiSL
pressed
Example:
cin >> v1 >> v2 >> v3;
Requires three space separated values
User might type
34 45 12 <enter key>
KGiSL
KGiSL
KGiSL
An object is like a
black box.
The internal details
are hidden.
KGiSL
assigning responsibilities to
these objects.
Objects communicate to other
objects by sending messages.
Messages are received by the
methods of an object
What is an object?
30
Tangible Things
Roles
Incidents
Interactions
Specifications
KGiSL
KGiSL
KGiSL
Classes
33
KGiSL
34
class A
{
private:
data member1;
data member2;
data member(n);
public:
method1();
method2();
};
KGiSL
#include<string.h>
#include<iostream.h>
class Person{
char name[20];
int yearOfBirth;
public:
void displayDetails() {
cout << name << " born in "
<< yearOfBirth << endl;
}
//...
};
KGiSL
private
data
public
processes
=
KGiSL
KGiSL
KGiSL
Basic Terminology
39
KGiSL
Example
#include <iostream.h>
#include <cstring.h>
40
class employee {
char name[80]; // private by default
public:
void putname(char *n); // these are public
void getname(char *n);
private:
double wage; // now, private again
public:
void putwage(double w); // back to public
double getwage();
};
KGiSL
KGiSL
42
int main()
{
employee ted;
char name[80];
ted.putname("Ted Jones");
ted.putwage(75000);
ted.getname(name);
cout << name << " makes $";
cout << ted.getwage() << " per year.";
return 0;
}
KGiSL
Friend
43
Friend function
Friend Class
KGiSL
Example
44
#include <iostream>
using namespace std;
class myclass {
int a, b;
public:
friend int sum(myclass x);
void set_ab(int i, int j);
};
void myclass::set_ab(int i, int j)
{
a = i;
b = j;
}
KGiSL
KGiSL
Polymorphism
46
Overloading
Operator
Overloading
KGiSL
Example
47
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#define pi 3.14
class fn
{
public:
void area(int); //circle
void area(int,int); //rectangle
void area(float ,int,int); //triangle
};
void fn::area(int a)
{
cout<<"Area of Circle:"<<pi*a*a;
}
KGiSL
48
49
cout<<"\n\t\tFunction Overloading";
cout<<"\n1.Area of Circle\n2.Area of
Rectangle\n3.Area of Triangle\n4.Exit\n:;
cout<<Enter your Choice:";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter Radious of the Circle:";
cin>>r;
obj.area(r);
break;
KGiSL
50
case 2:
cout<<"Enter Sides of the Rectangle:";
cin>>a>>b;
obj.area(a,b);
break;
case 3:
cout<<"Enter Sides of the Triangle:";
cin>>a>>b;
obj.area(0.5,a,b);
break;
case 4:
exit(0);
}
getch();
}
KGiSL
Inheritance
51
KGiSL
52
Orange
KGiSL
Yellow
Blue
Green
Violet
Example
53
#include <iostream>
using namespace std;
// Base class
class Shape
{
public:
void setWidth(int w) { width = w; }
void setHeight(int h) { height = h; }
protected:
int width;
int height;
};
KGiSL
54
// Derived class
class Rectangle: public Shape
{
public:
int getArea()
{
return (width * height);
}
};
KGiSL
55
int main(void)
{
Rectangle Rect;
Rect.setWidth(5);
Rect.setHeight(7);
// Print the area of the object.
cout << "Total area: " << Rect.getArea();
return 0;
}
KGiSL
Types of Inheritance
56
Single
Multi Level
A
B
Hierarchal
Multiple
A
Hybrid
A
C
B
D
THANK
57
U
KGiSL