0% found this document useful (0 votes)
9 views121 pages

1 DotNet

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views121 pages

1 DotNet

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 121

TASK # 1 – Find VS and Open it p

Worksho

1) Locate Visual Studio in your computer  Open it


2) Discuss the various sections in the program window
3) Close VS.  Reopen it
Visual C#Windows
Console App

The App and its


support file names

Solution Folder Name


and Solution File(.sln)
Name
TASK # 2 – Create a new Console Application p
Worksho

1) Create a New Console App Project


2) Name the App Name as “MyApps” and Solution Folder
Name as “MySolutionFolder”  Specify the project location
on a drive other than C drive.  SAVE
3) Close the Solution  Reopen it.
TASK # 3 – Typing in Console App p
Worksho

1) Type the following code

Discuss
se”
“Intellisen
2) Run the app by “Start” or F5 i th
feature w
r
3) Discuss the code statements. the traine
TASK # 4 – Noticing the Errors p
Worksho

1) Type the following code

2) Run the app by “Start” or F5


3) Discuss the output (Errors)
TASK # 5 – Typing in Console App p
Worksho

1) Type the following code

2) Run the app by “Start” or F5


3) Discuss the code statements.
TASK # 6 – Getting an input from the user. p
Worksho
1) Type the following code

2) Run the app by “Start” or F5


3) Discuss “Convert.ToInt32()”, “WriteLine()”
4) Remove the “Convert.ToInt32” part  Run Discuss the
Output
TASK # 7– Adding two integers p
Worksho
1) Type the following code

2) Run the app by “Start” or F5


3) Discuss the new code statements.
TASK # 8 – Multiplying two floating point numbers from user Workshop
1) Type the following code

2) Run the app by “Start” or F5


3) Discuss the new code statements.
TASK # 9 – Converting decimal number to integer p
Worksho

1) Type the following code

2) Run the app by “Start” or F5  Discuss the output


3) Discuss the new code statements.
TASK # 10 – Multiplying 2 floating points in C# Console p
Worksho

1) Type the following code

2) Run the app by “Start” or F5  Discuss the output


3) Run the program with add “f” suffix in floating point
numbers. Discuss the ERROR
Float and Double
Float and Double
Float and Double
TASK # 11 – Compute quotient and remainder p
Worksho
1) Type the following code

2) Run the app by “Start” or F5  Discuss the output


3) Discuss the “%” sign (Mod operator).
C# code is case sensitive
TASK # 12 – Calculating Simple Interest p
Worksho

1) Accept principal, time and rate of interest from the user.


2) Calculate simple interest.
Formula : p * r * t / 100
3) Display the result on the screen.

Solution on the next slide


Solution # 12 – Calculating Simple Interest p
Worksho
TASK # 13 – Calculating average of 3 numbers p
Worksho

1) Accept 3 numbers from the user.


2) Calculate average.
Formula : (num1 * num2 * num3) / 3
3) Display the result on the screen.

Solution on the next slide


Solution # 13 – Calculating Simple Interest p
Worksho
TASK # 14 – Calculating power using Math.Pow() p
Worksho

1) Accept base number and power number from the user.


2) Calculate power using the Math.Pow().
Math.Pow(3, 4)
3) Display the result on the screen.

Solution on the next slide


Solution # 14 – Calculating power using Math.Pow() p
Worksho
TASK # 15 – Count number of words in a String Worksho
p
1) Type the following code

2) Run the app by “Start” or F5


3) Discuss the new code statements.
TASK # 16 – Convert Dollar to Cents
Wo r ks h o p
1) Read the two programs for the same problem. Discuss

o e s the
D eth od
dm
secon e any
hav ge ?
nta
adva
Integer types in C#
TASK # 17 – Integer values in C# Worksho
p
1) Declare few variables of the data types of your choice from
the list below.  Initialize them with values. Print

2) Now, store values greater than the permitted ones  Run


the program  Notice Errors  DISCUSS
Floating-point types in C#
Are these variable names fine ?
OPERATORS
OPERATORS

•Tools to work, transform,


process data.
OPERATORS

•Used to
• do arithmetic calculations
• take decisions
• assign data to memory areas
Types of OPERATORS

•Arithmetic Operators
• Binary
• Unary
•Assignment Operators
•Relational Operators
•Logical Operators
Binary
Arithmetic
Operators
Binary
Arithmetic
Operators are
symbols used to
perform
mathematical
operations on
numbers.
Binary
Arithmetic
Operators
require two
operands to
function.
Operator Description Example Result
+ Addition x=2 4
x+2
- Subtraction x=2 3
5-x
* Multiplication x=4 20
x*5
/ Division 15/5 3
5/2 2.5
% Modulus 5%2 1
(division 10%8 2
remainder) 10%2 0
TASK # 18 - Learning about Arithmetic Operators Workshop

Declare “x” and “y” variables with some values.


Perform the following calculations. Discuss results
Unary
Arithmetic
Operators
Unary
Arithmetic
Operators
require single
operand to
function
Unary Operator
can be specified
before or after
the operand.
These operators
are of 3 types :
•Negation
•Increment
•Decrement
Negation Operator (-)

Example 1 :
int x ;
x = -3 ;
Negation Operator (-)

Example 2 :
int new, old = 5 ;
new = -old ;
Increment (++) and Decrement (--)

Example 1 :
stdNo = stdNo + 1 ; //can also be
written as
stdNo++ ; //Or
++stdNo ;
//Same applicable for decrement
Pre-fixing and Post-fixing Operators

//Prefixing operator
++StdNo ;
--StdNo ;
//PostFixing Operator
StdNo++ ;
StdNo-- ;
Pre-fixing
and
Post-fixing
Operators
In case of Pre-Fixing Operator, the
increment or decrement takes place
first, followed by the Operand value
being used.

Example 1 :
a = 10 ; b = 5 ;
c = a * ++b ;
//C will be 60
In case of Post fixing Operator, the
increment or decrement takes place
later after the Operand is used.

Example 1 :
a = 10 ; b = 5 ;
c = a * b++ ;
//C will be 50 and b will be 6
TASK # 19- Learning about Pre-fixing and post-fixing operators
1. Type the following code. Workshop
2. Discuss the result
WORD
Assignment
Operator
Used to assign
values to
variables.
Used with any valid C expression.
•Syntax is :
•variable name = expression ;
•Here, the expression can be a simple
constant or a complex expression
Assignment Operator

Examples :
var = 1 // simple constant
var = another_var // assigning a
variable
var = value1 + value2 + var1 / var2 //
arithmetic expression
Negation Operator (-)

Example 2 :
int new, old = 5 ;
new = -old ;
Increment (++) and Decrement (--)

Example 1 :
stdNo = stdNo + 1 ; //can also be
written as
stdNo++ ; //Or
++stdNo ;
//Same applicable for decrement
TASK # 20- Learning about Assignment Operators Worksho
p

Declare x and y variables with some values.


Perform the following calculations. Discuss results
Relation
Operators
Relation Operators

•Used to compare different sets of data.


E.g Evaluating whether the value of a
variable is greater than or less than the
value.
Relation Operators

Used in Decision making


Used to control the flow of a
program
There are six relation Operatros :

Operator Meaning
== Equal to
> Greater Than
< Less Than
!= Not Equal to
>= Greater Than or Equal to
<= Less than or Equal to
TASK # 21- Learning about Relational Operator Worksho
p
Type the program.  Discuss

the
What does )
== b
express (a
return ?
TASK # 22- Learning about Relational Operator Worksho
p
Type the program.  Discuss

the
What does
!=b)
express (a
return ?
TASK # 23 - Learning about Relational Operator Worksho
p

1) Accept two numbers from the user.


2) Compare the numbers and show appropriate
message
Logical
Operators
Logical Operators

Used in Decision making


Used to control the flow of a
program
TASK # 24 – Understanding Logical Operators Worksho
p
Type the program.  Discuss
TASK # 25-- Understanding Logical Operators Worksho
p
Use Logical AND operator to find the largest number out of 3
numbers.

Hint : Understand and use the following statements

Solution on next slide


TASK # 25 – SOLUTION
TASK # 26– Operator Precedence Worksho
p
1) Type the following code
2) Why is “a” giving different results ? DISCUSS
TASK # 27 Workshop

1. Write a program to accept two numbers


from the user and swap values of two
variables using a third variable.

2. Print the swapped values with proper


message
TASK # 28 Workshop

1. Write a program to accept a number from


the user and check whether it is even or odd.

2. Show proper message


TASK # 29 Workshop

1. Accept marks from the user  Follow the


following slab to judge grade.

If marks >= 75, give A grade


If marks >= 55, give B grade
Else, give C grade

2. Show proper message


Nested IF…Else
TASK # 30 Workshop

1) Find if a number is even or odd.


2) and then if it is even, whether it is
divisible by 4 or not,
3) and if it is odd, whether it is
divisible by 3

Solution on next slide


SOLUTION # 30– to be continued Workshop
SOLUTION # 30 Workshop
The SWITCH
statement
A switch loop in C# allows a
variable or an expression to be
tested against a list of values or
multiple matches.
Substitutes well a long series of
nested if-else statements.

The condition in the switch can be


“an expression” or “a variable”.
The syntax of
SWITCH
switch(expression)
{
case value :
//Statements
break; //optional
case value :
//Statements
break; //optional
//You can have any number of case
statements.
default : //Optional
//Statements
}
Switch statement:

You can have any number of case


statements within a switch.

The value for a case must be the same


data type as the variable in the switch
and it must be a constant or a literal.
Switch statement:

•When the variable being switched on is


equal to a case, the statements following
that case will execute until a break
statement is reached.
Switch statement:

•When a break statement is


reached, the switch terminates, and
the flow of control jumps to the next
line following the switch statement.
Switch statement:

•Not every case needs to contain a


break. If no break appears, the flow of
control will fall through to subsequent
cases until a break is reached.
Switch statement:
•A switch statement can have an
optional default case. The default case
can be used for performing a task when
none of the cases is true. No break is
needed in the default case.

•The default can appear anywhere in the


switch statement
TASK # 31 - Switch statement Workshop

1) Accept a number representing day of


the week from the user.
2) Using “Switch..case”, show the
appropriate day name.

Solution on next slide


SOLUTION # 31 - Switch statement Workshop
TASK # 32 - Switch statement Workshop

1) Accept a letter from the user.


2) Check if the entered character is a Vowel,
Consonant or a Space.
3) Show appropriate message.
4) Use “Switch”

Solution on next slide


SOLUTION # 32 - Switch statement Workshop
Program Control
Statements II
LOOPS

-- ITERATION
CONSTRUCTS --
A loop is a mechanism that
enables you to execute the
same sequence of statements
repeatedly until a condition is
met.
The statements inside a loop
are sometimes called
ITERATION statements.

The looping constructs, C#


supports are ;
•while
•do…..while
•For
•Foreach
Basics
of
Loop
There are two essential
elements to a loop.
The block of statements to be
executed repeatedly

A condition that determines


when to start, continue or
stop the loop.
Every loop construct follows a
standard algorithm.

1)Initialize a counter variable.


2)Evaluate condition
3)Increment / decrement the
value of counter variable.
The WHILE loop

Known as “repetitive loop” or


“Iteration Loop”

Executed as long as the test


condition evaluates to true.
Syntax

while (test condition)


{
statement 1 ;
statement n ;
}
The WHILE loop

No need for curly braces if


there is only one statement in
the loop.
The WHILE loop

In case of more than one


statements in the loop, use curly
braces. Otherwise, only first
statement is executed, rest of
the statements ignored.
TASK # 33 - While..Loop Workshop

Type a program to print a list of


10 numbers using “while…”
TASK # 34 - While..Loop Workshop

1) Type a program to accept a number


from the user.
2) Print a table of a given number. Use
“while…”

Solution on next slide


The DO WHILE loop

Same as the WHILE loop with the


following difference.
Difference between WHILE and DO-
WHLE loop

In WHILE loop, the test condition


is evaluated first, followed by the
execution of the statement.
The syntax of DO WHILE loop

do
{
statement 1;
statement n ;
}while (test condition)
TASK # 33 - do..while Workshop

Type the program  discuss


The FOR loop

A compact form of WHILE loop.


The FOR loop

The FOR loop combines all following


the three ingredients for a loop in one
statement
Initialization of a variable.

Condition Checking

Incrementing or Decrementing of a
variable for iteration
Syntax of FOR loop

for (int num=1 ; num<=10 ; num++)

Part 1 Part 2
(Initialization) (condition) Part 3
Declaration and (iteration
Initialization expression)
allowed together (No semi-colon)
TASK # 34 - For….Loop Workshop

1. Type the program  discuss

Check same example on next slide with “foreach” loop


TASK # 35 - Foreach loop Workshop

1. Type the program  discuss


TASK # 35 - Foreach loop Workshop

1. Type the program  discuss

You might also like