Introduction To Programming Fundamentals: Prepared By: Mehak Riaz
Introduction To Programming Fundamentals: Prepared By: Mehak Riaz
Fundamentals
1-Lecture
Date:11/09/2017 Prepared By : Mehak Riaz
The essence of Programming
• input: get data from the keyboard or from some file or other device
• output: write
• math: perform some simple calculation, like addition and multiplication
• conditional execution: check some condition and execute one sequence of statements or
another
• repetition: repeat some sequence of operations, usually with some variation
Sample Program
class Program
{
static void Main(string[] args)
{ int x;
int y;
int result;
Console.Write(" Enter the first number to be added: ");
x=Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the second number to be added: ");
y = Convert.ToInt32(Console.ReadLine());
result = x + y;
Console.Write("The sum of two numbers is: "+result);
Console.ReadLine();
}
}
Oo Concepts in c#
Object Oriented Programming:
• It is a type of programming in which programmers define not only
the data type of a data structure, but also the types of operations
(functions) that can be applied to the data structure. In this way, the
data structure becomes an object that includes both data and
functions. In addition, programmers can create relationships
between one object and another. For example, objects can inherit
characteristics from other objects.
• One of the principal advantages of object-oriented programming
techniques over procedural programming techniques is that they
enable programmers to create modules that do not need to be
changed when a new type of object is added. A programmer can
simply create a new object that inherits many of its features from
existing objects. This makes object-oriented programs easier to
modify.
Oo concepts
Object
• Objects are the basic run-time entities in an object-
oriented system. Programming problem is analyzed in
terms of objects and nature of communication
between them. When a program is executed, objects
interact with each other .Different objects can also
interact with each other without knowing the details of
their data or code.
• An object is an instance of a class. A class must be
instantiated into an object before it can be used in the
software. More than one instance of the same class
can be in existence at any one time.
Oo concepts in c#
Class
• A class is a collection of objects of a similar type. Once a class is defined,
any number of objects can be created which belong to that class. A class is
a blueprint, or prototype, that defines the variables and the methods
common to all objects of a certain kind.
Instance
• The instance is the actual object created at runtime. One can have an
instance of a class or a particular object.
State
• The set of values of the attributes of a particular object is called its state.
The object consists of state and the behaviour that's defined in the
object's class.
Method
• Method describes the object’s abilities. A Dog has the ability to bark.
So bark() is one of the methods of the Dog class.
Example Code
Public class PF
{
Console.WriteLine(“First Class Of PF”);
}
//calling Pf Class InMain
Console.WriteLine("Streering of Car");
}
//unnecessary
private void CarEngine()
{
Console.WriteLine("CarEngine of Car");
}
Oo concepts
Encapsulation
• It is the mechanism that binds together code and data in
manipulates, and keeps both safe from outside interference
and misuse. In short, it isolates a particular code and data
from all other codes and data. A well-defined interface
controls the access to that particular code and data.</p. />
The act of placing data and the operations that perform on
that data in the same class. The class then becomes the
'capsule' or container for the data and operations.
• Storing data and functions in a single unit (class) is
encapsulation. Data cannot be accessible to the outside
world and only those functions which are stored in the
class can access it.
Example Code
public class Account {
private string accoutName;
// get methods
public string GetAccount()
{
return accoutName; }
// Set method
public void SetAccount(string name)
{ accoutName = name; }
} static void Main()
{
string name ="SAVING_ACCOUNT";
Account account = new Account();
account.SetAccount(name);
name = string.Empty;
name = account.GetAccount();
}