際際滷

際際滷Share a Scribd company logo
DR ATIF SHAHZAD
Computer Applications
in Industrial Engg.-I
IE-322
LECTURE #03
Computer Applications in
Industrial Engg.-I
IE322
Recap
1/21/2019
Dr.AtifShahzad
What we will see
1/21/2019
Dr.AtifShahzad
Arithmetic Operators & Precedence
Relational Operators
Increment Operator
Prefix & Postfix Notations
Comparison and Logical Operators
The if Statement
The if-else Statement
Nested if Statements
The switch-case Statement
A random review
IE322
Floating point numbers
float
 4 Bytes
 7 digit precision
double
 8 Bytes
 15-16 digit precision
decimal
 16 Bytes
 28-29 digit precision
1/21/2019
Dr.AtifShahzad
6
賊1.510-45 賊3.41038
賊5.010-324 賊1.710308
賊1.010-28 賊7.91028
Floating point numbers
1/21/2019
Dr.AtifShahzad
7
static void Main(string[] args)
{
float f_no = 0.0f;
double d_no = 0.0d;
decimal m_no = 0.0m;
f_no = 1 / 3f;
d_no = 1 / 3d;
m_no = 1 / 3m;
//place holder
Console.WriteLine("Float no. is {0}", f_no);
Console.WriteLine("Double no. is {0}", d_no);
Console.WriteLine("Decimal no. is {0}", m_no);
}
ReadLine()
1/21/2019
Dr.AtifShahzad
8
Console.WriteLine("What is your name?");
string name = Console.ReadLine();
Console.WriteLine("Welcome " + name + ", welcome back!");
Arithmetic Operators
IE322
Arithmetic Operators
* /
% +
-
1/21/2019
Dr.AtifShahzad
10
Operators Precedence Example
1/21/2019
Dr.AtifShahzad
11
Write the expression in c#
z=pr%q + w/x-y
 =    % +
Problem
Write a program that enters the
coefficients a, b and c of a quadratic
equation
2
+  +  = 0
and calculates and prints its real roots.
Note that quadratic equations may have 0, 1 or
2 real roots.
1/21/2019
Dr.AtifShahzad
12
Math Library
1/21/2019
Dr.AtifShahzad
13
Math.Sqrt(56);
Math.Pow(b,2);// for 2
Math.Sqrt(Math.Pow(b,2)-4*a*c); // Discriminant
Other Operators
IE322
Relational Operators
1/21/2019
Dr.AtifShahzad
15
Operator Notation in C#
Equals ==
Not Equals !=
GreaterThan >
GreaterThan or Equals >=
LessThan <
LessThan or Equals <=
bool result = 5 <= 6;
Console.WriteLine(result); //True
Increment (Decrement) Operator
x=6;
x = x + 1;
x = x++;
x += 1; //CompoundAssignment
1/21/2019
Dr.AtifShahzad
16
x /= 4; // equivalent to x=x/4;
x *= 8; // equivalent to x=x*8;
x %= 2; // equivalent to x=x%2;
Prefix & Postfix form
++x; //prefix
x++; //postfix
1/21/2019
Dr.AtifShahzad
17
int x = 3;
int y = ++x;
// x is 4 and y is 4
int x = 3;
int y = x++;
// x is 4 and y is 3
Prefix & Postfix form
++x; //prefix
x++; //postfix
1/21/2019
Dr.AtifShahzad
18
int x = 3;
int y = ++x;
// x is 4 and y is 4
int x = 3;
int y = x++;
// x is 4 and y is 3
Logical Operators
1/21/2019
Dr.AtifShahzad
19
Operator Notation in C#
Logical NOT !
LogicalAND &&
Logical OR ||
Logical Exclusive OR (XOR) ^
Decision Structures
IE322
if statement
1/21/2019
Dr.AtifShahzad
21
if (condition)
{
statements;
}
static void Main()
{
Console.WriteLine("Enter two numbers.");
int biggerNumber = int.Parse(Console.ReadLine());
int smallerNumber = int.Parse(Console.ReadLine());
if (smallerNumber > biggerNumber)
{
biggerNumber = smallerNumber;
}
Console.WriteLine("The greater number is: {0}",
biggerNumber);
}
if else statement
1/21/2019
Dr.AtifShahzad
22
if (expression)
{
statement1;
}
else
{
statement2;
} string s = Console.ReadLine();
int number = int.Parse(s);
if (number % 2 == 0)
{
Console.WriteLine("This number is even.");
}
else
{
Console.WriteLine("This number is odd.");
}
Nested if else statements
1/21/2019
Dr.AtifShahzad
23
if (expression)
{
if (expression)
{
statement;
}
else
{
statement;
}
}
else
statement;
if (first == second)
{
Console.WriteLine(
"These two numbers are equal.");
}
else
{
if (first > second)
{
Console.WriteLine(
"The first number is bigger.");
}
else
{
Console.WriteLine("The second is bigger.");
}
}
if else if statements
1/21/2019
Dr.AtifShahzad
24
int ch = 'X';
if (ch == 'A' || ch == 'a')
{
Console.WriteLine("Vowel [ei]");
}
else if (ch == 'E' || ch == 'e')
{
Console.WriteLine("Vowel [i:]");
}
else if 
else
Switch case statement
1/21/2019
Dr.AtifShahzad
25
switch (day)
{
case 1: Console.WriteLine("Monday"); break;
case 2: Console.WriteLine("Tuesday"); break;
case 3: Console.WriteLine("Wednesday"); break;
case 4: Console.WriteLine("Thursday"); break;
case 5: Console.WriteLine("Friday"); break;
case 6: Console.WriteLine("Saturday"); break;
case 7: Console.WriteLine("Sunday"); break;
default: Console.WriteLine("Error!"); break;
}
Switch case statement
1/21/2019
Dr.AtifShahzad
26
switch (animal)
{
case "dog" :
Console.WriteLine("MAMMAL");
break;
case "crocodile" :
case "tortoise" :
case "snake" :
Console.WriteLine("REPTILE");
break;
default :
Console.WriteLine("There is no such animal!");
break;
}
Practice the programming
Practice is a habit.
Practice is a routine.
Practice does not need to remember.
Practice comes by practicing.
Practice needs dedication and commitment.
1/21/2019
Dr.AtifShahzad
27
Lecture03 computer applicationsie1_dratifshahzad
1/21/2019
Dr.AtifShahzad
29
NEVER hesitate to
contact should you
have any question
Dr.Atif Shahzad

More Related Content

Lecture03 computer applicationsie1_dratifshahzad