SlideShare a Scribd company logo
1 of 41
Download to read offline
1
Programming Language with
C_Sharp
Object-Oriented-Programming
Lec: Renas R. Rekany
2017/2018
2
 object oriented
 Class
 Constructor & destructor
 Accessibility keywords
 Inheritance
 Polymorphism
 Operator overloading
3
Class: is an abstraction model used to define a new Data Type
Which May Contain a Combination of encapsulating Data
(Member Variable) Operation That Can Be Perform On Data
(Member Function) And Accessory to Data (properties).
Member Variable = Field
Member Function = Method
Properties = Attributes
4
Class Class_name
{
[Properties] Member Variable;
[Properties] Member Function;
.
.
.
}
5
Class_name var = new Class_name ();
1. Class can declared before or after main
method
2. Or can be declared before class program.
3. we can change class program to any name
6
// Define Class point
class point
{
public int x;
public int y;
public void setx(int a)
{ x = a; }
public void sety(int b)
{ y = b; }
public int getx()
{ return (x); }
public int gety()
{ return (y); }
}
7
// Calling the Class
private void button1_Click(object sender, EventArgs e)
{
point p = new point();
// p.x = 10;
// p.y = 5;
p.setx(6);
p.sety(7);
textBox1.Text = Convert.ToString(p.getx());
textBox2.Text = Convert.ToString(p.gety());
}
8
// Define Class circle
class circle
{
double radius;
double pi = 3.141;
public double area()
{ return (radius * radius * pi); }
public void set_r(double b)
{ radius = b; }
}
9
// Calling the Class
private void button1_Click(object sender, EventArgs e)
{
circle c = new circle();
double x = Convert.ToDouble(textBox1.Text);
c.set_r(x);
textBox2.Text=Convert.ToString( c.area());
}
10
1. Data Abstraction – it is the act of representing the essential
features without including the background details. Data
Hiding- it is a related concept of data abstraction. Unessential
features are hidden from the world.
2. Data Encapsulation – it is the wrapping of data and associated
functions in one single unit.
3. Inheritance – it is the capability of one class to inherit
properties from other class.
4. Polymorphism – it is the ability for data to be processed in
more than one form.
5. Modularity – it is the concept of breaking down the program
into several module. E.g. : Classes, Structure, etc.
11
// Define Class math
class math
{
public int factorial(int x)
{ int f=1;
for( int i=1; i<=x;i++)
f=f*i; return f;
}
public double pow(double a, double b)
{
double p=Math.pow(a,b);
return p;
}
}
12
// Calling the Class
private void button1_Click(object sender, EventArgs e)
{
math m = new math();
double x = Convert.ToDouble(textBox1.Text);
double y = Convert.ToDouble(textBox2.Text);
int z = Convert.ToInt32(textBox3.Text);
textBox4.Text=Convert.ToString( m.factorial(z));
textBox5.Text=Convert.ToString( m.pow(x,y));
}
13
// Class array Define and Sort // Passing array
class sort
{
int[] ar = new int[10];
public void set_array(int[] a)
{
ar = a;
}
public int[] get_array()
{
Array.Sort(ar); return ((ar));
}
}
14
// Calling the Class
private void button1_Click(object sender, EventArgs e)
{
sort s = new sort();
int[] b = new int[10] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
s.set_array(b);
b=s.get_array();
for (int i = 0; i < 10; i++)
{
textBox1.Text = textBox1.Text + b[i];
}
}
15class stage2
{
public double rnd( double x)
{
double d=Math.Round(x); // to greater than
return(d);
}
public double flor( double y)
{
double f = Math.Floor(y); // to less than
return (f);
}
public string str_up(string a)
{
return (a.ToUpper());
}
16
public string str_dn(string a)
{
return (a.ToLower());
}
public string get_s;
public string set_s;
public void find_array(string[,] s)
{
for (int j = 0; j < 5; j++)
if (get_s == s[0, j])
{
set_s =s[0,j]+":"+s[1,j]+" = "+ s[2, j];
break;
}
}
}
17
private void button1_Click(object sender, EventArgs e)
{
string[,] st = new string[3, 5] { {ID},{NAME},{AVERAGE}};
stage2 s2 = new stage2();
if (comboBox1.Text == “round")
{
double x = Convert.ToDouble(textBox1.Text);
textBox2.Text = Convert.ToString(s2.rnd(x));
}
else if (comboBox1.Text == “floor")
{
double y = Convert.ToDouble(textBox1.Text);
textBox2.Text = Convert.ToString(s2.flor(y));
}
else if (comboBox1.Text == "upper")
{
string s = textBox1.Text;
textBox2.Text = s2.str_up(s);
}
18
else if (comboBox1.Text == "lower")
{
string s = textBox1.Text;
textBox2.Text = s2.str_dn(s);
}
else if (comboBox1.Text == "find")
{
s2.get_s = textBox3.Text;
s2.find_array(st);
textBox4.Text = s2.set_s;
}
}
19
1. Searching According to (ID, Name, Code).
2. List of requests and Total Price.
3. Show Expiration Date of products.
ID Product Price Expired Code
101 Paracetamol 3$ 12/1/2019 0x001
102 Panadol 5$ 20/1/2019 0x002
103 Aspirin 4$ 22/1/2019 0x003
104 Flu Out 2$ 18/1/2019 0x004
20
Suppose that we have a school management system, and
we have to build a system to manage students
information and deal with it. According to the following:
1. The school management system contains 100 students.
2. Suppose, there are only three courses.
Find the average of each student depending on Std_ID.
Hint: Store students info. On one array like a table has shown
below:
Std_ID Std_Name Course1 Course2 Course3
1 AA 67 77 92
2 BB 87 90 55
3 CC 75 57 79
21
Homework :: ??? ???
1. Find summation in array[3,3] using class.
2. Print even numbers and odd numbers in array[3,3].
3. Find summation of even numbers and odd numbers
in array[3,3].
4. Exchange even numbers with odd numbers, keep
using same sequence.
5. Find power value of each elements of array[3,3].
6. Find factorial for each elements of array[10].
Hint: Use only one program to do the above questions.!!!
22
Constructor: Is a special method used when an object of class
is created (used to initialize the data member)
Constructor properties
‽ Constructor has the same name of the class.
‽ Constructor do not return value.
‽ Constructor can be overloaded.
‽ Constructor has public access.
23
➢ Default Construction: has no parameters list.
➢ Parameter Construction: has parameters list.
➢ Copy Construction: has object parameter type.
24
class car
{ string model;
double speed;
public car() // Default Construction
{ model = ""; speed = 0; }
public car(string s, double d) // Parameter Construction
{ model = s; speed = d; }
public car(car k) // Copy Construction
{ model = k.model; speed = k.speed; }
}
private void button1_Click(object sender, EventArgs e)
{ car c1 = new car(); // Default Construction
car c2 = new car("toyota", 220); // Parameter Construction
car c3 = new car(c2); // Copy Construction }
25
class home
{
public string floor;
public double price;
public int garanty;
public home()
{ floor = "One"; price = 20000; }
public home(string s, double d, int g)
{ floor = s; price = d; garanty = g; }
public home(home k)
{ floor = k.floor; price = k.price; garanty = k.garanty; }
}
26
home h1 = new home();
home h2 = new home("Two", 60000, 3);
home h = new home("Three", 100000, 5);
home h3 = new home(h);
textBox1.Text = "Floor: " + h1.floor + " Price:" + h1.price + "
Garanty:" + h1.garanty+" Years";
textBox2.Text = "Floor: " + h2.floor + " Price:" + h2.price + "
Garanty:" + h2.garanty+" Years";
textBox3.Text = "Floor: " + h3.floor + " Price:" + h3.price + "
Garanty:" + h3.garanty+" Years";
27
28
comboBox1_SelectedIndexChanged
cafe caffe = new cafe(1000, 250, 3000, 1500, 8000);
if (comboBox1.Text == "Tea")
{
textBox1.Text = textBox1.Text + comboBox1.Text + Environment.NewLine;
textBox2.Text = Convert.ToString(Convert.ToInt32(textBox2.Text) + caffe.tea);
}
else if(comboBox1.Text=="Water")
{
textBox1.Text = textBox1.Text + comboBox1.Text + Environment.NewLine;
textBox2.Text =Convert.ToString(Convert.ToInt32(textBox2.Text) + caffe.water );
}
29
else if (comboBox1.Text=="Nescafe")
{
textBox1.Text = textBox1.Text + comboBox1.Text + Environment.NewLine;
textBox2.Text = Convert.ToString(Convert.ToInt32(textBox2.Text) + caffe.nescafe );
}
else if(comboBox1.Text=="Pepsi")
{
textBox1.Text = textBox1.Text + comboBox1.Text + Environment.NewLine;
textBox2.Text = Convert.ToString(Convert.ToInt32(textBox2.Text) + caffe.pepsi );
}
else if(comboBox1.Text=="Nargila")
{
textBox1.Text = textBox1.Text + comboBox1.Text + Environment.NewLine;
textBox2.Text = Convert.ToString(Convert.ToInt32(textBox2.Text) + caffe.nargila );
}
30
class cafe
{
public int tea;
public int water;
public int nescafe;
public int pepsi;
public int nargila;
public cafe (int a, int b, int c, int d, int e)
{
tea = a; water = b; nescafe = c; pepsi = d; nargila = e;
}
}
31
32
➢ Is a method called once an object is disposed, can be used to
cleanup recourse used by the object.
➢ Destructors only used with classes.
➢ A class can only have one destructor.
➢ Destructor cannot be inherited or overloaded.
➢ Destructor cannot be called, They are invoked automatically.
➢ Destructors cannot take a modifiers or have parameters.
~car ()
{
MessageBox.Show("car object is dead");
}
33
All types and members have an accessibility level, which controls
whether they can be used from other code in your assembly or
other assemblies. You can use the following access modifiers to
specify the accessibility of a type or member when you declare it:
Public: The type or member can be accessed by any other code in the
same assembly or another assembly that references it.
Private: The type or member can be accessed only by code in the same
class or structure.
Protected: The type or member can be accessed only by code in the
same class or structure, or in a class that is derived from that class.
Internal: The type or member can be accessed by any code in the same
assembly, but not from another assembly.
34
The public keyword is an access modifier for types and type
members. Public access is the most permissive access level.
There are no restrictions on accessing public members.
Accessibility:
1. Can be accessed by objects of the class
2. Can be accessed by derived classes
Example: In the following example num1 is direct access.
35
Private access is the least permissive access level.
Private members are accessible only within the body of the class or the
structure in which they are declared.
Accessibility:
1. Cannot be accessed by object
2. Cannot be accessed by derived classes
Example: In the following example num2 is not accessible outside the
class.
36
using System;
namespace AccessModifiers
{ class Program
{ class AccessMod
{ public int num1;
int num2; }
private void button1_Click(object sender, EventArgs e)
{ AccessMod ob1 = new AccessMod();
//Direct access to public members
ob1.num1 = 100;
//Access to private member is not permitted
ob1.num2 = 20;
Console.WriteLine("Number one value in main {0}",
ob1.num1);
Console.ReadLine(); } } }
The above program will give compilation error, as access to private is
not permissible. In the below figure you can see the private member
num2 is not available.
37
38
A protected member is accessible from within the class in which it
is declared, and from within any class derived from the class that
declared this member.
A protected member of a base class is accessible in a derived class
only if the access takes place through the derived class type.
Accessibility:
Cannot be accessed by object
Only by derived classes
39
class Base
{ protected int num1; }
class Derived : Base
{ public int num2; }
private void button1_Click(object sender, EventArgs e)
{
Base ob1 = new Base();
Derived ob2 = new Derived();
ob2.num1 = 20;
// Access to protected member as it is inherited by the Derived class
ob2.num2 = 90;
} } }
In the above program we try to access protected member in main it
is not available as shown in the picture below that num1 is not
listed.
40
41
Access in child ClassParent Class Access Modifier
AccessiblePublic
AccessibleProtected
Not AccessiblePrivate

More Related Content

What's hot

Virtual base class
Virtual base classVirtual base class
Virtual base classTech_MX
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++Saket Pathak
 
Mpl 9 oop
Mpl 9 oopMpl 9 oop
Mpl 9 oopAHHAAH
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6sotlsoc
 
Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objectsRai University
 
14. Java defining classes
14. Java defining classes14. Java defining classes
14. Java defining classesIntro C# Book
 
Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++Liju Thomas
 
Ifi7184.DT lesson 2
Ifi7184.DT lesson 2Ifi7184.DT lesson 2
Ifi7184.DT lesson 2Sónia
 
June 05 P2
June 05 P2June 05 P2
June 05 P2Samimvez
 
Chapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classChapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classDeepak Singh
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsFALLEE31188
 
DITEC - Programming with C#.NET
DITEC - Programming with C#.NETDITEC - Programming with C#.NET
DITEC - Programming with C#.NETRasan Samarasinghe
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2rohassanie
 

What's hot (20)

Virtual base class
Virtual base classVirtual base class
Virtual base class
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
java tutorial 3
 java tutorial 3 java tutorial 3
java tutorial 3
 
Qno 2 (a)
Qno 2 (a)Qno 2 (a)
Qno 2 (a)
 
Mpl 9 oop
Mpl 9 oopMpl 9 oop
Mpl 9 oop
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6
 
Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objects
 
14 Defining Classes
14 Defining Classes14 Defining Classes
14 Defining Classes
 
14. Java defining classes
14. Java defining classes14. Java defining classes
14. Java defining classes
 
Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++
 
Inheritance
InheritanceInheritance
Inheritance
 
Ifi7184.DT lesson 2
Ifi7184.DT lesson 2Ifi7184.DT lesson 2
Ifi7184.DT lesson 2
 
June 05 P2
June 05 P2June 05 P2
June 05 P2
 
Chapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classChapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-class
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Class and object
Class and objectClass and object
Class and object
 
C++ Notes
C++ NotesC++ Notes
C++ Notes
 
DITEC - Programming with C#.NET
DITEC - Programming with C#.NETDITEC - Programming with C#.NET
DITEC - Programming with C#.NET
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2
 

Similar to C# Programming Language with Object-Oriented-Programming

Application package
Application packageApplication package
Application packageJAYAARC
 
Microsoft dynamics ax 2012 development introduction part 2/3
Microsoft dynamics ax 2012 development introduction part 2/3Microsoft dynamics ax 2012 development introduction part 2/3
Microsoft dynamics ax 2012 development introduction part 2/3Ali Raza Zaidi
 
C# (This keyword, Properties, Inheritance, Base Keyword)
C# (This keyword, Properties, Inheritance, Base Keyword)C# (This keyword, Properties, Inheritance, Base Keyword)
C# (This keyword, Properties, Inheritance, Base Keyword)Umar Farooq
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIEduardo Bergavera
 
Getting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingGetting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingHock Leng PUAH
 
SPF Getting Started - Console Program
SPF Getting Started - Console ProgramSPF Getting Started - Console Program
SPF Getting Started - Console ProgramHock Leng PUAH
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7Vince Vo
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)Jay Patel
 
3 functions and class
3   functions and class3   functions and class
3 functions and classtrixiacruz
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsRai University
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming conceptsGanesh Karthik
 
C# Summer course - Lecture 3
C# Summer course - Lecture 3C# Summer course - Lecture 3
C# Summer course - Lecture 3mohamedsamyali
 

Similar to C# Programming Language with Object-Oriented-Programming (20)

Intake 38 4
Intake 38 4Intake 38 4
Intake 38 4
 
Application package
Application packageApplication package
Application package
 
Microsoft dynamics ax 2012 development introduction part 2/3
Microsoft dynamics ax 2012 development introduction part 2/3Microsoft dynamics ax 2012 development introduction part 2/3
Microsoft dynamics ax 2012 development introduction part 2/3
 
CS3391 -OOP -UNIT – II NOTES FINAL.pdf
CS3391 -OOP -UNIT – II  NOTES FINAL.pdfCS3391 -OOP -UNIT – II  NOTES FINAL.pdf
CS3391 -OOP -UNIT – II NOTES FINAL.pdf
 
C# (This keyword, Properties, Inheritance, Base Keyword)
C# (This keyword, Properties, Inheritance, Base Keyword)C# (This keyword, Properties, Inheritance, Base Keyword)
C# (This keyword, Properties, Inheritance, Base Keyword)
 
Intake 37 4
Intake 37 4Intake 37 4
Intake 37 4
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part II
 
Getting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingGetting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem Solving
 
SPF Getting Started - Console Program
SPF Getting Started - Console ProgramSPF Getting Started - Console Program
SPF Getting Started - Console Program
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
3 functions and class
3   functions and class3   functions and class
3 functions and class
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objects
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming concepts
 
C# Summer course - Lecture 3
C# Summer course - Lecture 3C# Summer course - Lecture 3
C# Summer course - Lecture 3
 
C sharp chap5
C sharp chap5C sharp chap5
C sharp chap5
 
Java class
Java classJava class
Java class
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 

More from Renas Rekany (20)

decision making
decision makingdecision making
decision making
 
Artificial Neural Network
Artificial Neural NetworkArtificial Neural Network
Artificial Neural Network
 
AI heuristic search
AI heuristic searchAI heuristic search
AI heuristic search
 
AI local search
AI local searchAI local search
AI local search
 
AI simple search strategies
AI simple search strategiesAI simple search strategies
AI simple search strategies
 
C# p9
C# p9C# p9
C# p9
 
C# p8
C# p8C# p8
C# p8
 
C# p7
C# p7C# p7
C# p7
 
C# p6
C# p6C# p6
C# p6
 
C# p5
C# p5C# p5
C# p5
 
C# p4
C# p4C# p4
C# p4
 
C# p3
C# p3C# p3
C# p3
 
C# p2
C# p2C# p2
C# p2
 
C# p1
C# p1C# p1
C# p1
 
C# with Renas
C# with RenasC# with Renas
C# with Renas
 
Object oriented programming inheritance
Object oriented programming inheritanceObject oriented programming inheritance
Object oriented programming inheritance
 
Renas Rajab Asaad
Renas Rajab Asaad Renas Rajab Asaad
Renas Rajab Asaad
 
Renas Rajab Asaad
Renas Rajab AsaadRenas Rajab Asaad
Renas Rajab Asaad
 
Renas Rajab Asaad
Renas Rajab Asaad Renas Rajab Asaad
Renas Rajab Asaad
 
Renas Rajab Asaad
Renas Rajab Asaad Renas Rajab Asaad
Renas Rajab Asaad
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 

C# Programming Language with Object-Oriented-Programming

  • 2. 2  object oriented  Class  Constructor & destructor  Accessibility keywords  Inheritance  Polymorphism  Operator overloading
  • 3. 3 Class: is an abstraction model used to define a new Data Type Which May Contain a Combination of encapsulating Data (Member Variable) Operation That Can Be Perform On Data (Member Function) And Accessory to Data (properties). Member Variable = Field Member Function = Method Properties = Attributes
  • 4. 4 Class Class_name { [Properties] Member Variable; [Properties] Member Function; . . . }
  • 5. 5 Class_name var = new Class_name (); 1. Class can declared before or after main method 2. Or can be declared before class program. 3. we can change class program to any name
  • 6. 6 // Define Class point class point { public int x; public int y; public void setx(int a) { x = a; } public void sety(int b) { y = b; } public int getx() { return (x); } public int gety() { return (y); } }
  • 7. 7 // Calling the Class private void button1_Click(object sender, EventArgs e) { point p = new point(); // p.x = 10; // p.y = 5; p.setx(6); p.sety(7); textBox1.Text = Convert.ToString(p.getx()); textBox2.Text = Convert.ToString(p.gety()); }
  • 8. 8 // Define Class circle class circle { double radius; double pi = 3.141; public double area() { return (radius * radius * pi); } public void set_r(double b) { radius = b; } }
  • 9. 9 // Calling the Class private void button1_Click(object sender, EventArgs e) { circle c = new circle(); double x = Convert.ToDouble(textBox1.Text); c.set_r(x); textBox2.Text=Convert.ToString( c.area()); }
  • 10. 10 1. Data Abstraction – it is the act of representing the essential features without including the background details. Data Hiding- it is a related concept of data abstraction. Unessential features are hidden from the world. 2. Data Encapsulation – it is the wrapping of data and associated functions in one single unit. 3. Inheritance – it is the capability of one class to inherit properties from other class. 4. Polymorphism – it is the ability for data to be processed in more than one form. 5. Modularity – it is the concept of breaking down the program into several module. E.g. : Classes, Structure, etc.
  • 11. 11 // Define Class math class math { public int factorial(int x) { int f=1; for( int i=1; i<=x;i++) f=f*i; return f; } public double pow(double a, double b) { double p=Math.pow(a,b); return p; } }
  • 12. 12 // Calling the Class private void button1_Click(object sender, EventArgs e) { math m = new math(); double x = Convert.ToDouble(textBox1.Text); double y = Convert.ToDouble(textBox2.Text); int z = Convert.ToInt32(textBox3.Text); textBox4.Text=Convert.ToString( m.factorial(z)); textBox5.Text=Convert.ToString( m.pow(x,y)); }
  • 13. 13 // Class array Define and Sort // Passing array class sort { int[] ar = new int[10]; public void set_array(int[] a) { ar = a; } public int[] get_array() { Array.Sort(ar); return ((ar)); } }
  • 14. 14 // Calling the Class private void button1_Click(object sender, EventArgs e) { sort s = new sort(); int[] b = new int[10] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; s.set_array(b); b=s.get_array(); for (int i = 0; i < 10; i++) { textBox1.Text = textBox1.Text + b[i]; } }
  • 15. 15class stage2 { public double rnd( double x) { double d=Math.Round(x); // to greater than return(d); } public double flor( double y) { double f = Math.Floor(y); // to less than return (f); } public string str_up(string a) { return (a.ToUpper()); }
  • 16. 16 public string str_dn(string a) { return (a.ToLower()); } public string get_s; public string set_s; public void find_array(string[,] s) { for (int j = 0; j < 5; j++) if (get_s == s[0, j]) { set_s =s[0,j]+":"+s[1,j]+" = "+ s[2, j]; break; } } }
  • 17. 17 private void button1_Click(object sender, EventArgs e) { string[,] st = new string[3, 5] { {ID},{NAME},{AVERAGE}}; stage2 s2 = new stage2(); if (comboBox1.Text == “round") { double x = Convert.ToDouble(textBox1.Text); textBox2.Text = Convert.ToString(s2.rnd(x)); } else if (comboBox1.Text == “floor") { double y = Convert.ToDouble(textBox1.Text); textBox2.Text = Convert.ToString(s2.flor(y)); } else if (comboBox1.Text == "upper") { string s = textBox1.Text; textBox2.Text = s2.str_up(s); }
  • 18. 18 else if (comboBox1.Text == "lower") { string s = textBox1.Text; textBox2.Text = s2.str_dn(s); } else if (comboBox1.Text == "find") { s2.get_s = textBox3.Text; s2.find_array(st); textBox4.Text = s2.set_s; } }
  • 19. 19 1. Searching According to (ID, Name, Code). 2. List of requests and Total Price. 3. Show Expiration Date of products. ID Product Price Expired Code 101 Paracetamol 3$ 12/1/2019 0x001 102 Panadol 5$ 20/1/2019 0x002 103 Aspirin 4$ 22/1/2019 0x003 104 Flu Out 2$ 18/1/2019 0x004
  • 20. 20 Suppose that we have a school management system, and we have to build a system to manage students information and deal with it. According to the following: 1. The school management system contains 100 students. 2. Suppose, there are only three courses. Find the average of each student depending on Std_ID. Hint: Store students info. On one array like a table has shown below: Std_ID Std_Name Course1 Course2 Course3 1 AA 67 77 92 2 BB 87 90 55 3 CC 75 57 79
  • 21. 21 Homework :: ??? ??? 1. Find summation in array[3,3] using class. 2. Print even numbers and odd numbers in array[3,3]. 3. Find summation of even numbers and odd numbers in array[3,3]. 4. Exchange even numbers with odd numbers, keep using same sequence. 5. Find power value of each elements of array[3,3]. 6. Find factorial for each elements of array[10]. Hint: Use only one program to do the above questions.!!!
  • 22. 22 Constructor: Is a special method used when an object of class is created (used to initialize the data member) Constructor properties ‽ Constructor has the same name of the class. ‽ Constructor do not return value. ‽ Constructor can be overloaded. ‽ Constructor has public access.
  • 23. 23 ➢ Default Construction: has no parameters list. ➢ Parameter Construction: has parameters list. ➢ Copy Construction: has object parameter type.
  • 24. 24 class car { string model; double speed; public car() // Default Construction { model = ""; speed = 0; } public car(string s, double d) // Parameter Construction { model = s; speed = d; } public car(car k) // Copy Construction { model = k.model; speed = k.speed; } } private void button1_Click(object sender, EventArgs e) { car c1 = new car(); // Default Construction car c2 = new car("toyota", 220); // Parameter Construction car c3 = new car(c2); // Copy Construction }
  • 25. 25 class home { public string floor; public double price; public int garanty; public home() { floor = "One"; price = 20000; } public home(string s, double d, int g) { floor = s; price = d; garanty = g; } public home(home k) { floor = k.floor; price = k.price; garanty = k.garanty; } }
  • 26. 26 home h1 = new home(); home h2 = new home("Two", 60000, 3); home h = new home("Three", 100000, 5); home h3 = new home(h); textBox1.Text = "Floor: " + h1.floor + " Price:" + h1.price + " Garanty:" + h1.garanty+" Years"; textBox2.Text = "Floor: " + h2.floor + " Price:" + h2.price + " Garanty:" + h2.garanty+" Years"; textBox3.Text = "Floor: " + h3.floor + " Price:" + h3.price + " Garanty:" + h3.garanty+" Years";
  • 27. 27
  • 28. 28 comboBox1_SelectedIndexChanged cafe caffe = new cafe(1000, 250, 3000, 1500, 8000); if (comboBox1.Text == "Tea") { textBox1.Text = textBox1.Text + comboBox1.Text + Environment.NewLine; textBox2.Text = Convert.ToString(Convert.ToInt32(textBox2.Text) + caffe.tea); } else if(comboBox1.Text=="Water") { textBox1.Text = textBox1.Text + comboBox1.Text + Environment.NewLine; textBox2.Text =Convert.ToString(Convert.ToInt32(textBox2.Text) + caffe.water ); }
  • 29. 29 else if (comboBox1.Text=="Nescafe") { textBox1.Text = textBox1.Text + comboBox1.Text + Environment.NewLine; textBox2.Text = Convert.ToString(Convert.ToInt32(textBox2.Text) + caffe.nescafe ); } else if(comboBox1.Text=="Pepsi") { textBox1.Text = textBox1.Text + comboBox1.Text + Environment.NewLine; textBox2.Text = Convert.ToString(Convert.ToInt32(textBox2.Text) + caffe.pepsi ); } else if(comboBox1.Text=="Nargila") { textBox1.Text = textBox1.Text + comboBox1.Text + Environment.NewLine; textBox2.Text = Convert.ToString(Convert.ToInt32(textBox2.Text) + caffe.nargila ); }
  • 30. 30 class cafe { public int tea; public int water; public int nescafe; public int pepsi; public int nargila; public cafe (int a, int b, int c, int d, int e) { tea = a; water = b; nescafe = c; pepsi = d; nargila = e; } }
  • 31. 31
  • 32. 32 ➢ Is a method called once an object is disposed, can be used to cleanup recourse used by the object. ➢ Destructors only used with classes. ➢ A class can only have one destructor. ➢ Destructor cannot be inherited or overloaded. ➢ Destructor cannot be called, They are invoked automatically. ➢ Destructors cannot take a modifiers or have parameters. ~car () { MessageBox.Show("car object is dead"); }
  • 33. 33 All types and members have an accessibility level, which controls whether they can be used from other code in your assembly or other assemblies. You can use the following access modifiers to specify the accessibility of a type or member when you declare it: Public: The type or member can be accessed by any other code in the same assembly or another assembly that references it. Private: The type or member can be accessed only by code in the same class or structure. Protected: The type or member can be accessed only by code in the same class or structure, or in a class that is derived from that class. Internal: The type or member can be accessed by any code in the same assembly, but not from another assembly.
  • 34. 34 The public keyword is an access modifier for types and type members. Public access is the most permissive access level. There are no restrictions on accessing public members. Accessibility: 1. Can be accessed by objects of the class 2. Can be accessed by derived classes Example: In the following example num1 is direct access.
  • 35. 35 Private access is the least permissive access level. Private members are accessible only within the body of the class or the structure in which they are declared. Accessibility: 1. Cannot be accessed by object 2. Cannot be accessed by derived classes Example: In the following example num2 is not accessible outside the class.
  • 36. 36 using System; namespace AccessModifiers { class Program { class AccessMod { public int num1; int num2; } private void button1_Click(object sender, EventArgs e) { AccessMod ob1 = new AccessMod(); //Direct access to public members ob1.num1 = 100; //Access to private member is not permitted ob1.num2 = 20; Console.WriteLine("Number one value in main {0}", ob1.num1); Console.ReadLine(); } } } The above program will give compilation error, as access to private is not permissible. In the below figure you can see the private member num2 is not available.
  • 37. 37
  • 38. 38 A protected member is accessible from within the class in which it is declared, and from within any class derived from the class that declared this member. A protected member of a base class is accessible in a derived class only if the access takes place through the derived class type. Accessibility: Cannot be accessed by object Only by derived classes
  • 39. 39 class Base { protected int num1; } class Derived : Base { public int num2; } private void button1_Click(object sender, EventArgs e) { Base ob1 = new Base(); Derived ob2 = new Derived(); ob2.num1 = 20; // Access to protected member as it is inherited by the Derived class ob2.num2 = 90; } } } In the above program we try to access protected member in main it is not available as shown in the picture below that num1 is not listed.
  • 40. 40
  • 41. 41 Access in child ClassParent Class Access Modifier AccessiblePublic AccessibleProtected Not AccessiblePrivate