Computer Applications in Industrial Engg.-I: Lecture #03
Computer Applications in Industrial Engg.-I: Lecture #03
IE-322
Computer Applications
LECTURE #03 in Industrial Engg.-I
Computer Applications in
Industrial Engg.-I
IE322
Dr. Atif Shahzad
8/12/2018
…Recap
What will se see…
Dr. Atif Shahzad
8/12/2018
What we will see…
Comparison and Logical Operators
The if Statement
Nested if Statements
8/12/2018
Console.Read()
Console.ReadLine()
Console.Write()
Console.WriteLine()
Dr. Atif Shahzad
8/12/2018 6
Formatting Text with WriteLine
Console.WriteLine(“{0}\n{1}”, “This is
my another Program”, “in C#”)
Dr. Atif Shahzad
8/12/2018 7
Escape Sequence
\ is an escape character
\n
\t
\r
\\
\”
Dr. Atif Shahzad
8/12/2018 8
Reading some numeric data
Console.Write(“Enter first number”);
Num1=Convert.ToInt32(Console.ReadLine())
Dr. Atif Shahzad
8/12/2018 9
Data Conversion
Convert.ToInt32()
Convert.ToDouble()
Dr. Atif Shahzad
8/12/2018 10
Arithmetic Operators
* /
% +
-
Dr. Atif Shahzad
8/12/2018 11
Operators Precedence Example
z=pr%q + w/x-y
Dr. Atif Shahzad
8/12/2018 12
Increment (Decrement) Operator
x=6;
x = x + 1;
x = x++;
x += 1; //Compound Assignment
x /= 4; // equivalent to x=x/4;
x *= 8; // equivalent to x=x*8;
x %= 2; // equivalent to x=x%2;
Dr. Atif Shahzad
8/12/2018 13
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.
Dr. Atif Shahzad
8/12/2018 14
Relational Operators
Operator Notation in C#
Equals ==
Not Equals !=
Greater Than >
Greater Than or Equals >=
Less Than <
Less Than or Equals <=
Dr. Atif Shahzad
8/12/2018 16
Increment (Decrement) Operator
x=6;
x = x + 1;
x = x++;
x += 1; //Compound Assignment
x /= 4; // equivalent to x=x/4;
x *= 8; // equivalent to x=x*8;
x %= 2; // equivalent to x=x%2;
Dr. Atif Shahzad
8/12/2018 17
Prefix & Postfix form
++x; //prefix
x++; //postfix
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
Dr. Atif Shahzad
8/12/2018 18
Prefix & Postfix form
++x; //prefix
x++; //postfix
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
Dr. Atif Shahzad
8/12/2018 19
Comparison Operators
Operator Notation in C#
Equals ==
Not Equals !=
Greater Than >
Greater Than or Equals >=
Less Than <
Less Than or Equals <=
Console.WriteLine(result); // True
8/12/2018 20
Logical Operators
Operator Notation in C#
Logical NOT !
Logical AND &&
Logical OR ||
Logical Exclusive OR (XOR) ^
Dr. Atif Shahzad
8/12/2018 21
if statement
if (condition)
{
statements;
}
if (number % 2 == 0)
{
Console.WriteLine("This number is even.");
}
else
{
Dr. Atif Shahzad
8/12/2018 24
if else if statements
int ch = 'X';
if (ch == 'A' || ch == 'a')
{
Console.WriteLine("Vowel [ei]");
}
else if (ch == 'E' || ch == 'e')
{
Console.WriteLine("Vowel [i:]");
}
Dr. Atif Shahzad
else if …
else …
8/12/2018 25
Switch case statement
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;
Dr. Atif Shahzad
8/12/2018 26
Switch case statement
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!");
Dr. Atif Shahzad
break;
}
8/12/2018 27
NEVER hesitate to
contact should you
have any question
Dr. Atif Shahzad
Dr. Atif Shahzad
8/12/2018 29