Professional Documents
Culture Documents
©ationale
c
c
Object-Oriented Programming Using C#
Objectives
c
c
Object-Oriented Programming Using C#
Object-Oriented Methodology
c
c
Object-Oriented Programming Using C#
Object-Oriented Methodology (Contd.)
Car
Obj
c
c
Object-Oriented Programming Using C#
he Foundation of Object Orientation
c
c
Object-Oriented Programming Using C#
he Foundation of Object Orientation (Contd.)
c
c
c
Object-Oriented Programming Using C#
he Foundation of Object Orientation (Contd.)
c
c #
Object-Oriented Programming Using C#
Just a minute
Solution:
1. States of a cell phone: Off, Ring, Vibrate, and Call
2. States of a stereo: Play, Pause, Rewind, and Forward
c
c $
Object-Oriented Programming Using C#
Just a minute
Dr. James and Mr. Hyde went to the railway station to book
tickets for 3rd December. At the railway station, they
requested the clerk at the ticket counter to book two tickets
for the Flying Express in the first class. Àdentify the following:
1. The possible receiver of the message in this situation.
2. The possible method that the receiver can use.
Solution:
1. The receiver of the message in this case will be the clerk at
the ticket counter.
2. The clerk will check if two tickets are available on the
requested train in the desired class and for the desired date. Àf
the tickets are available, the clerk will enter the details (name,
age, departure date, and seat), confirm the reservation, and
collect the required fare.
c
c %
Object-Oriented Programming Using C#
Characteristics of the Object-Oriented Approach
Realistic modeling
Reusability
Resilience to change
Existence as different forms
c
c
Object-Oriented Programming Using C#
Just a minute
Solution:
1. Àt does not represent reusability because the unusable paper
is destroyed before paper is recycled for use. The unusable
paper loses its identity and cannot be considered the same as
recycled paper.
2. Àt represents reusability because a pump can be used for
suction of water as well as petrol. Àt is not necessary to use
the same pump in both the cases. Two separate machines
can be used because both belong to the µPump¶ class.
c
c
Object-Oriented Programming Using C#
Phases of Object Orientation
c
c
Object-Oriented Programming Using C#
Just a minute
Solution:
As per the problem statement, the class required is:
Customer
The class should have the methods to:
Accept customer details
Display customer details
c
c
Object-Oriented Programming Using C#
Àntroducing C#
c
c
Object-Oriented Programming Using C#
Àntroducing C# (Contd.)
c
c
Object-Oriented Programming Using C#
Classes in C#
Ã
!"
#
#
c
c
Object-Oriented Programming Using C#
Classes in C# (Contd.)
Ã
&"
Às used to declare a
Ã
class
!"
#
#
c
c #
Object-Oriented Programming Using C#
Classes in C# (Contd.)
Ã
'
Às used as an identifier
Ã
for a class
!"
#
#
c
c $
Object-Oriented Programming Using C#
Classes in C# (Contd.)
Ã
()*
Às the entry point of an
Ã
application
Às used to create
objects and invoke
member functions
!"
#
#
c
c %
Object-Oriented Programming Using C#
Classes in C# (Contd.)
Ã
c"
+
,()
Displays the enclosed text on
Ã
the screen
!"
#
#
c
c
Object-Oriented Programming Using C#
Classes in C# (Contd.)
Ã
-
Displays New line
Ã
character. Other special
characters can also be
displayed such as \t, \b
and \r
!"
#
#
c
c
Object-Oriented Programming Using C#
Demo: Creating Classes
Problem Statement:
As a member of a team that is developing toys for JoyToys,
Ànc., you have been assigned the task of creating a bike
module that accepts and displays bike details. Declare the
Bike class and its member functions. The member function that
accepts bike details should display the message ³Accepting
Bike Details´. Similarly, the member function to display bike
details on the screen should display the message ³Displaying
Bike Details´.
c
c
Object-Oriented Programming Using C#
Declaring Variables
c
c
Object-Oriented Programming Using C#
Declaring and Ànitializing Variables
c
c
Object-Oriented Programming Using C#
Declaring and Ànitializing Variables (Contd.)
c
c
Object-Oriented Programming Using C#
Data ypes in C#
Let us now understand the various data types with the help
of examples.
c
c
Object-Oriented Programming Using C#
Data ypes in C# (Contd.)
c
c #
Object-Oriented Programming Using C#
Data ypes in C# (Contd.)
Ñ Ñ
Ñ
{
c
c $
Object-Oriented Programming Using C#
Declaring and Ànitializing Variables
#
! ! "
{
c
c %
Object-Oriented Programming Using C#
Declaring and Ànitializing Variables (Contd.)
c
c
Object-Oriented Programming Using C#
Declaring and Ànitializing Variables (Contd.)
initializing a variable:
Name
$'&("
#Score
Age
2Strank
Family_Size
Gender
c
c
Object-Oriented Programming Using C#
Declaring and Ànitializing Variables (Contd.)
c
c
Object-Oriented Programming Using C#
Accepting and Storing Values in Member Variables
c
c
Object-Oriented Programming Using C#
Accepting and Storing Values in Member Variables (Contd.)
c
c
Object-Oriented Programming Using C#
Jriting and Executing a C# Program
c
c
Object-Oriented Programming Using C#
Creating a Sample C# Program
c
c
Object-Oriented Programming Using C#
Creating a Sample C# Program (Contd.)
/ 2 /
"
/ &
- "
/ 2
12 "
)
012 &
*
+,(
- "
#
Ã
4Ã4
*2 /
56#
/ "
*2
172
56#)
012 "
#
#
c
c #
Object-Oriented Programming Using C#
Creating a Sample C# Program (Contd.)
..
2
/8 The Execute class is used as a class from
where the Car class can be instantiated.
Ã
& 7"
3 Ã4 "
4Ã4 "
#
#
c
c $
Object-Oriented Programming Using C#
Compiling and Executing C# Program
c
c %
Object-Oriented Programming Using C#
Compiling and Executing C# Program (Contd.)
c
c
Object-Oriented Programming Using C#
Demo: Creating a C# Program
Problem Statement:
David is the member of a team that is developing the
Automatic Ranking software for a tennis tournament. ou have
been assigned the task of creating a program. The program
should accept the following details of a tennis player and
display it:
Name, containing a maximum of 25 characters
Rank as an integer
Winning average as a decimal value
Help David to create the program.
c
c
Object-Oriented Programming Using C#
Summary
c
c
Object-Oriented Programming Using C#
Summary (Contd.)
c
c
Object-Oriented Programming Using C#
Summary (Contd.)
c
c
Object-Oriented Programming Using C#
Summary (Contd.)
c
c