Computer Applications in Industrial Engg.-I: Lecture #08
Computer Applications in Industrial Engg.-I: Lecture #08
IE-322
Computer Applications
LECTURE #08 in Industrial Engg.-I
Computer Applications in
Industrial Engg.-I
IE322
Dr. Atif Shahzad
8/12/2018
…Recap
What we will see…
Files of the project in
A Random Review Solution Explorer
Windows explorer
Complete Example—
A quick Question Example2:
class Car
Classes
• Class vs Object: Calling a Method of an
Some built-in classes
Examples object
• Class vs Object:
A Bonus Topic
Adding a Class to a C# Instantiating an object • Look this example Project & Solution
project of a class • Conditional Operator
Dr. Atif Shahzad
8/12/2018
A Random Review
5
A Random Review
Data Types DefaultValue Minimum Value MaximumValue
- -
string null - -
6
A Random Review: Integer types
// Declare some variables
byte centuries = 20;
ushort years = 2000;
uint days = 730480;
ulong hours = 17531520;
// Print the result on the console
Console.WriteLine(centuries + " centuries are " + years +
" years, or " + days + " days, or " + hours + " hours.
");
// Console output:
// 20 centuries are 2000 years, or 730480 days, or 17531520
// hours.
7
A Random Review: Real types
// Declare some variables
float floatPI = 3.141592653589793238f;
double doublePI = 3.141592653589793238;
// Console output:
// Float PI is: 3.141593
// Double PI is: 3.14159265358979
Dr. Atif Shahzad
8
A quick Question
int age = 8;
if ( !(age >= 16) )
{
Console.Write("Your age is less than 16");
}
// What is the OUTPUT?
Dr. Atif Shahzad
8/12/2018 9
A quick Question
int age = 8;
if ( !(age >= 16) ) {
Console.Write("Your age is less than 16");
}
8/12/2018 10
Classes
IE322
Classes
Classes act as templates from which
an instance of an object is created at run time.
Dr. Atif Shahzad
8/12/2018 12
Classes
Classes act as templates
from which
an instance of an object is created
at run time.
Classes define the properties of the object
and the methods used to control the
object's behavior.
Dr. Atif Shahzad
8/12/2018 13
Class vs Object: Example 1
Drawing of House
House
Dr. Atif Shahzad
14
Class vs Object: Example 2
Engineering Drawing of a car
Car
Dr. Atif Shahzad
15
Class vs Object: Example 3
Bank Account class
Bank Account of a customer
Dr. Atif Shahzad
16
Class vs Object: Example 4
Student class
A particular student
Dr. Atif Shahzad
17
Class vs Object:You examples?
Class:
Object:
Attributes:
Methods:
Dr. Atif Shahzad
18
Class vs Object:
Class:
Object:
Attributes or States or Properties
these are the characteristics of the object which define it in a
way and describe it in general or in a specific moment
Methods or Behaviors
these are the specific distinctive actions, which can be done by
the object.
Dr. Atif Shahzad
Methods:
19
Adding a Class to a C# project
Dr. Atif Shahzad
20
Declaring a Class
Let us create a class named as Car
namespace CarApp
{
class Car
{
}
}
Dr. Atif Shahzad
21
Declaring a Class
Let us create a class named as Car
namespace CarApp
{
class Car
{
22
Adding a Method to the Class
namespace CarApp
{
class Car
{
public void Start()
{ // A method
Console.WriteLine("Car has been
started");
}
Dr. Atif Shahzad
24
Calling a Method of an object
Access or dot (.) operator
MyCar.Start();
Dr. Atif Shahzad
25
Complete Example—class Car
Dr. Atif Shahzad
26
Complete Example—class Program
Dr. Atif Shahzad
27
Solution Explorer
Dr. Atif Shahzad
28
Files of the project in Windows
explorer
Dr. Atif Shahzad
8/12/2018 29
Example2: public class Cat
{
public class Cat
{
// Field name
// Field name
private string name; private string name;
// Field color // Field color
private string color; private string color;
}
}
30
Some built-in classes
System.Console
System.String (string in C#)
System.Int32 (int in C#)
System.Array
System.Math
System.Random
Dr. Atif Shahzad
8/12/2018 31
A Bonus Topic
IE322
A Bonus Topic
Conditional Operator
Dr. Atif Shahzad
8/12/2018 33
Look at this example
int age = 42;
string msg;
if(age >= 18)
msg = "Welcome";
else
msg = "Sorry";
Console.WriteLine(msg);
Dr. Atif Shahzad
8/12/2018 34
Conditional Operator
int age = 42;
string msg;
msg = (age >= 18) ? "Welcome" :
"Sorry";
Console.WriteLine(msg);
Dr. Atif Shahzad
8/12/2018 35
Conditional Operator
What is the value of x after this code?
int x = 5;
int y = 3;
x = (x > y) ? y : x;
Dr. Atif Shahzad
8/12/2018 36
Annex-
A Quick random revision
IE322
What is a Visual Studio Project?
8/12/2018 38
What is a Visual Studio Project?
When you create an app, website, plug-in, etc.
in Visual Studio, you start with a project.
In a logical sense, a project contains all the
source code files, icons, images, data files, etc.
that are compiled into an executable, library, or
website.
A project also contains compiler settings and
other configuration files that might be needed
by various services or components that your
Dr. Atif Shahzad
8/12/2018 40
What is a Visual Studio Project?
In Visual Studio, the project file is used by
Solution Explorer to display the project
contents and settings.
When you compile your project, the
MSBuild engine consumes the project file
to create the executable. You can also
customize projects to produce other kinds
of output.
Dr. Atif Shahzad
8/12/2018 41
What is a Visual Studio Solution?
A project is contained within a solution. A
solution contains one or more related projects,
along with build information, Visual Studio
window settings, and any miscellaneous files
that aren't associated with a particular project.
A solution is described by a text file (extension
.sln) with its own unique format; it is generally
not intended to be edited by hand.
Dr. Atif Shahzad
8/12/2018 42
What is a Visual Studio Solution?
A solution has an associated .suo file that stores
settings, preferences and configuration
information for each user that has worked on
the project.
Dr. Atif Shahzad
8/12/2018 43
Project & Solution
Dr. Atif Shahzad
8/12/2018 44
NEVER hesitate to
contact should you
have any question
Dr. Atif Shahzad
Dr. Atif Shahzad
8/12/2018 46