The document summarizes key concepts from a lecture on computer applications in industrial engineering, including:
- Floating point numbers have limited precision that varies by type (e.g. float has 7 digits, double has 15-16 digits).
- Arithmetic operators in C# include addition, subtraction, multiplication, division, and modulus.
- Relational operators compare values and return true or false, while logical operators combine conditional tests.
- Decision structures like if, else if, else and switch statements allow conditionally executing blocks of code.
4. 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
12. 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
16. 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;
17. 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
18. 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
21. 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);
}
22. 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.");
}
23. 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.");
}
}
24. 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
25. 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;
}
26. 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;
}
27. 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