Presentation is loading. Please wait.

Presentation is loading. Please wait.

Project on VB Control Structures Prepared By : Sudhir Kataria PGT Computer Sc. PGT Computer Sc. K V Chamera II K V Chamera II.

Similar presentations


Presentation on theme: "Project on VB Control Structures Prepared By : Sudhir Kataria PGT Computer Sc. PGT Computer Sc. K V Chamera II K V Chamera II."— Presentation transcript:

1 Project on VB Control Structures Prepared By : Sudhir Kataria PGT Computer Sc. PGT Computer Sc. K V Chamera II K V Chamera II

2 Detailed Lesson Plan

3 Project Summary This project named “Control Structure” is mainly focused on the working principle of various control Structures in VB and their implementation in Programming. This project named “Control Structure” is mainly focused on the working principle of various control Structures in VB and their implementation in Programming. Various Practical Examples have been included in this project relating to real life problems for the better understanding of the concepts. Various Practical Examples have been included in this project relating to real life problems for the better understanding of the concepts. Programming questions, Output related questions are formed so as to improve the logical & problem solving ability of the students. Programming questions, Output related questions are formed so as to improve the logical & problem solving ability of the students.

4 Learning Objectives Working principles of various types of control structures in VB. Working principles of various types of control structures in VB. Syntax & semantics of various statements in VB. Syntax & semantics of various statements in VB. Implementation of Control structures in Programming. Implementation of Control structures in Programming. Connecting real-world entities using control structures. Connecting real-world entities using control structures. Solving real-life problems using control structures. Solving real-life problems using control structures. Enhancement of Logical & Problem solving ability of the learner. Enhancement of Logical & Problem solving ability of the learner.

5 Assessment Procedures Students performance will be judged/assessed by inspecting the following factors : Students performance will be judged/assessed by inspecting the following factors : Logic in Programming. Logic in Programming. Efficiency & Effectiveness of Programs. Efficiency & Effectiveness of Programs. Usage of various control structures. Usage of various control structures. Correct syntax. Correct syntax. Correct code. Correct code. Following stylistic guidelines while programming i.e. object naming conventions, meaningful object names, proper indentation & spacing, prettyprinting style etc. Following stylistic guidelines while programming i.e. object naming conventions, meaningful object names, proper indentation & spacing, prettyprinting style etc.

6 Implementation Procedures Students will be explained about the working principle of individual statement with the help of its proper syntax and example. Students will be explained about the working principle of individual statement with the help of its proper syntax and example. After explaining working principle of every statement, students will be given Practical Examples, implemented using VB language on Computer. After explaining working principle of every statement, students will be given Practical Examples, implemented using VB language on Computer. Students will be demonstrated the usage and working of every statement in variety of ways, according to the options available in the syntax. Students will be demonstrated the usage and working of every statement in variety of ways, according to the options available in the syntax.

7 Implementation Procedures Students will be given practical questions to solve and implement using VB language. Students will be given practical questions to solve and implement using VB language. After implementing every type of control structure, students will be given a Home Assignment based on the statements studied. After implementing every type of control structure, students will be given a Home Assignment based on the statements studied. Students will be given a consolidated Assignment in the end of the chapter so as to test the logical ability of the children and their understanding about the different types of control structures and their implementation. Students will be given a consolidated Assignment in the end of the chapter so as to test the logical ability of the children and their understanding about the different types of control structures and their implementation.

8 Resources Used I am in teaching profession from last 12 years so this complete lesson plan, assessment procedure, programming questions, output related questions etc., are formed with my previous experience and knowledge. Still I would like to mention few resources I have used for the preparation of this Project : I am in teaching profession from last 12 years so this complete lesson plan, assessment procedure, programming questions, output related questions etc., are formed with my previous experience and knowledge. Still I would like to mention few resources I have used for the preparation of this Project : Text book of Informatics Practices by Sumita Arora. Text book of Informatics Practices by Sumita Arora. Previous year CBSE Board question papers. Previous year CBSE Board question papers. Computer. Computer.

9 VB Control Structures Created By : Sudhir Kataria PGT Computer Sc. PGT Computer Sc. K V Chamera II K V Chamera II

10 Control Flow In a program, statements may be executed sequentially, selectively or iteratively. Every programming language provides constructs to support sequence, selection or iteration. So there are three types of programming constructs : In a program, statements may be executed sequentially, selectively or iteratively. Every programming language provides constructs to support sequence, selection or iteration. So there are three types of programming constructs : Sequential Constructs Sequential Constructs Selection Constructs Selection Constructs Iterative Constructs Iterative Constructs

11 Sequential Construct The sequential construct means the statements are being executed sequentially. This represents the default flow of statements. The sequential construct means the statements are being executed sequentially. This represents the default flow of statements. Stament 1 Stament 2 Stament 3

12 Selection Construct The selection construct means the execution of statement(s) depending upon the condition- test. If a condition evaluates to true, a course- of-action (a set of statements) is followed otherwise another course-of-action is followed. This construct is also called decision construct as it helps in decision making. The selection construct means the execution of statement(s) depending upon the condition- test. If a condition evaluates to true, a course- of-action (a set of statements) is followed otherwise another course-of-action is followed. This construct is also called decision construct as it helps in decision making.

13 Selection Construct Condition ? Statement 1Statement 2 Statement 1 One course-of-action Another course- of-action true false

14 Iterative Constructs The iterative or repetitive constructs means repetition of a set-of-statements depending upon a condition-test. A set- of-statements are repeated again and again till the condition or Boolean Expression evaluates to true. The iteration constructs are also called as looping constructs. The iterative or repetitive constructs means repetition of a set-of-statements depending upon a condition-test. A set- of-statements are repeated again and again till the condition or Boolean Expression evaluates to true. The iteration constructs are also called as looping constructs.

15 Iterative Construct Condition ? Statement 2 Statement 1 The loop body false The exit condition True

16 Selection Constructs VB provides two types of selection construct : VB provides two types of selection construct :  1) If statement  2) Select Case statement The If Statement : If statement of VB comes in various forms & are given below: The If Statement : If statement of VB comes in various forms & are given below:  1) If..Then Statement  2) If..Then..Else Statement  3) If..Then..ElseIf Statement  4) Nested Ifs

17 If..Then Statement Def. : An If..Then statement tests a particular condition; if the condition evaluates to true, a course-of-action is followed otherwise it is ignored. Def. : An If..Then statement tests a particular condition; if the condition evaluates to true, a course-of-action is followed otherwise it is ignored. Syntax : Syntax : If (boolean expression) Then statements statements End If

18 If..Then Statement Example 1. : Example 1. : If (Num>0) Then Print “It is a positive number” Print “It is a positive number” End if Example 2 : Example 2 : If txtAge.Text>=18 Then Print “You are eligible to vote” Print “You are eligible to vote” End if

19 If..Then..Else Statement If..Then..Else statement provides an alternate choice to the user i.e. if the condition is true then a set of statements are executed otherwise another set of statements are executed. If..Then..Else statement provides an alternate choice to the user i.e. if the condition is true then a set of statements are executed otherwise another set of statements are executed. Syntax : Syntax : If (boolean Expression) Then VB Statement(s) VB Statement(s)Else End If

20 Examples of If..Then..Else Example 1 : Example 1 : If txtAge.Text>=18 Then Print “You are eligible to vote” Print “You are eligible to vote”Else Print “Sorry, You are not eligible to vote” Print “Sorry, You are not eligible to vote” End If Example 2 : Example 2 : If Num Mod 2=0 Then Print “It is an Even Number” Print “It is an Even Number”Else Print “It is an Odd Number” Print “It is an Odd Number” End If

21 If..Then..ElseIf Statement If..Then..ElseIf statement is used to test a number of mutually exclusive cases and only executes one set of statements for the case that is true first. If..Then..ElseIf statement is used to test a number of mutually exclusive cases and only executes one set of statements for the case that is true first. Syntax : Syntax : If (Boolean Expression) Then Statement(s) Statement(s) ElseIf (Boolean Expression 2) Then Statement(s) Statement(s) ElseIf (Boolean Expression 3) Then Statement(s) Statement(s): [ Else Statement(s) Statement(s) End If

22 Example of If..Then..ElseIf If (Age<=4) Then Print “Your rate is free.” Print “Your rate is free.” ElseIf (Age<=12) Then Print “You qualify for the children’s rate.” Print “You qualify for the children’s rate.” ElseIf (Age<65) Then Print “You must pay full rate” Print “You must pay full rate”Else Print “You qualify for the seniors’ rate.” Print “You qualify for the seniors’ rate.” End If

23 Nested Ifs A nested If is an if that has another If in its if’s body or in its else’s body. The nested if can have one of the following three forms : A nested If is an if that has another If in its if’s body or in its else’s body. The nested if can have one of the following three forms : 1. If (expresssion 1) Then If (expression 2 ) Then If (expression 2 ) Then Statement 1 Statement 1 [Else [Else Statement 2 Statement 2 End If End If Else Else body-of-else] body-of-else] End If End If

24 Nested Ifs 2. If (expression 1) Then body-of-if body-of-if Else Else : If (expression 2) Then If (expression 2) Then Statement-1 Statement-1 [Else [Else Statement-2] Statement-2] End If End If

25 Nested If’s 3) If (expression 1) Then 3) If (expression 1) Then : If (expression 2) Then If (expression 2) Then Statement-1 Statement-1 [Else [Else Statement-2] Statement-2] End If End If Else Else If (expression 3) Then If (expression 3) Then Statement-3 Statement-3 [Else [Else Statement-4] Statement-4] : End If End If

26 Example of Nested If’s If Num>0 Then Print “It is a positive number” Print “It is a positive number”Else If Num<0 Then If Num<0 Then Print “It is a negative number” Print “It is a negative number” Else Else Print “The number is equal to zero” Print “The number is equal to zero” End If End If End If

27 Select-Case Statement Select-Case is a multiple branching statement and is used to executed a set of statements depending upon the value of the expression. It is better to use Select-Case statement in comparison to If..Then..ElseIf Statement when the number of checks are more. There are 3 different forms of using Select-Case statements and are given below : Select-Case is a multiple branching statement and is used to executed a set of statements depending upon the value of the expression. It is better to use Select-Case statement in comparison to If..Then..ElseIf Statement when the number of checks are more. There are 3 different forms of using Select-Case statements and are given below :

28 Different forms of Select-Case 1. Select Case : Simplest Form [Exact match] Select Case Expression Case Value ’one or more visual basic statements ’one or more visual basic statements Case Value ’one or more visual basic statements ’one or more visual basic statements Case Else : ’one or more visual basic statements ’one or more visual basic statements End Select

29 Example of Form 1 Select Case byMonth Case 1,3,5,7,8,10,12 Case 1,3,5,7,8,10,12 number_of_days=31 number_of_days=31 Case 2 Case 2 number_of_days=28 number_of_days=28 Case 4,6,9,11 Case 4,6,9,11 number_of_days=30 number_of_days=30 End Select

30 Syntax of Form 2 Select Case : Second Form [Relational Test] Select Case Expression Case is relation : ’one or more visual basic statements ’one or more visual basic statements Case is relation : ’one or more visual basic statements ’one or more visual basic statements [Case Else : ’one or more visual basic statements ’one or more visual basic statements End Select

31 Example of Form 2 Select Case marks Case Is < 50 Case Is < 50 Result = “Fail” Result = “Fail” Case Is < 60 Case Is < 60 Result = “Grade B” Result = “Grade B” Case Is < 75 Case Is < 75 Result = “Grade A” Result = “Grade A” Case Else Case Else Result = “Grade A+” Result = “Grade A+” End Select

32 Third Form of Select Case Select Case : Third Format [Range Check] Select Case Expression Case exp1 To exp2: ’one or more visual basic statements ’one or more visual basic statements Case exp1 To exp2: ’one or more visual basic statements ’one or more visual basic statements [Case Else: ’one or more visual basic statements ’one or more visual basic statements End Select

33 Example of Form 3 Select Case Age Case 2 to 4 : Print “PreNursery” Case 2 to 4 : Print “PreNursery” Case 4 to 6 : Print “Kindergarden” Case 4 to 6 : Print “Kindergarden” Case 6 to 10 : Print “Primary” Case 6 to 10 : Print “Primary” Case Else : Print “Others” Case Else : Print “Others” End Select

34 Home Assignment 1 Write a program in VB to compare three no’s and print the smallest number among these no’s. Write a program in VB to compare three no’s and print the smallest number among these no’s. Write a program in VB to check the eligibilty of a person to vote. Display a message “You are eligible to vote” if the age of the person is greater than or equal to 18 otherwise print “Sorry! You are not eligible to vote” Write a program in VB to check the eligibilty of a person to vote. Display a message “You are eligible to vote” if the age of the person is greater than or equal to 18 otherwise print “Sorry! You are not eligible to vote” Write a program to compare two no’s and then print the square and cube of the larger number among these no’s. Write a program to compare two no’s and then print the square and cube of the larger number among these no’s.

35 Home Assignment Write a program to display the grade obtained by the child according to the marks obtained by him/her. Criteria for assigning the grades is given below : If marks are Write a program to display the grade obtained by the child according to the marks obtained by him/her. Criteria for assigning the grades is given below : If marks are >=90 - Grade is A >=90 - Grade is A 80 – Grade is B 80 – Grade is B =70 – Grade is C =70 – Grade is C =60 – Grade is D =60 – Grade is D <60 – Grade is E <60 – Grade is E

36 Iterative Constructs (Looping Structures) Loop : A loop is said to be the set of instructions which are repeated again and again in a program. Loop : A loop is said to be the set of instructions which are repeated again and again in a program. Types of Loops in VB : Types of Loops in VB : 1) Sentinel-controlled Loop Structures : repeat statements until a special value called sentinel value (or the terminating value) is reached. 2) Counter-controlled Loop Structures : repeat the set of statements until the value specified by the counter variable is reached.

37 Looping Structures VB offers broadly following three types of looping structures : VB offers broadly following three types of looping structures : 1. For..Next 2. Do Loop a) Do While..Loop b) Do..Loop While c) Do Until..Loop d) Do..Loop Until 3. While..Wend

38 For..Next Statement This type of statement is used when the user knows in advance how many times the loop is going to be executed. This type of statement is used when the user knows in advance how many times the loop is going to be executed. Syntax : Syntax : For = To Step For = To Step ‘ One or more VB Statements ‘ One or more VB Statements Next Next

39 Examples  Example 1 : Generate natural no’s from 1 to 100 For I = 1 To 100 Print I Print I Next I  Example 2 : Generate first 20 even no’s. For E = 2 to 40 Step 2 Print E Print E Next E

40 More Examples  Example 3 : Generate odd no’s from 100 to 30 in a list box. For O = 99 to 31 Step -2 ListO.AddItem(O) ListO.AddItem(O) Next O  Example 4 : Generate table of any number N. For T = 1 To N Print N; “*”; T; “=”; N*T Print N; “*”; T; “=”; N*T Next T

41 More Examples Example 5 : Find factorial of a given number N. Example 5 : Find factorial of a given number N.:Fact=1 For I= 1 to N Fact = Fact * I Fact = Fact * I Next I Print “Factorial of ”; N; “=”; Fact :

42 Home Assignment 2 Write Programs for the following problems : Write Programs for the following problems : 1) To Generate all the natural no’s from 200 to 500. 2) To Generate the table of 10. 3) To Generate all the even no’s from 200 to 400 in reverse order. 4) To Print first 20 multiples of the number input by the user.

43 Do..Loop Structures Do While..Loop : Do While loop is an entry controlled loop in which the condition is placed at the entry point. This statement executes the statements specified in the body of the loop till the condition evaluates to true. The loop may not be executed at all the if the condition is initially false. Do While..Loop : Do While loop is an entry controlled loop in which the condition is placed at the entry point. This statement executes the statements specified in the body of the loop till the condition evaluates to true. The loop may not be executed at all the if the condition is initially false. Syntax : Syntax : Do While Do While ‘ One or more VB Statements ‘ One or more VB StatementsLoop

44 Examples of Do While..Loop  Example 1 : Never executes loop Dim A as Byte A=10 Do While A>10 A=A-1 A=A-1Loop  Example 2 : Executes loop Dim P as Byte P=20 Do While P>5 P=P-2 P=P-2Loop

45 Do..Loop While Do Loop While is an exit controlled loop as the condition is placed at exit point. The body of the loop is going to be executed at least once whether the condition evaluates to true or false. Loop is executed as long as the result of the condition remains true. Do Loop While is an exit controlled loop as the condition is placed at exit point. The body of the loop is going to be executed at least once whether the condition evaluates to true or false. Loop is executed as long as the result of the condition remains true. Syntax : Syntax :Do One or more VB Statements One or more VB Statements Loop While Loop While

46 Examples Example 1 : Example 1 :Do num = InputBox (“Enter a number”) num = InputBox (“Enter a number”) sum = sum + num sum = sum + num Loop While num 0 Here the statements inside the loop will be executed once no matter what the comparison test evaluates to. Here the statements inside the loop will be executed once no matter what the comparison test evaluates to.

47 Do..Until Loop Do Until loop is an entry controlled loop in which the condition is placed at the entry point. This statement executes the statements specified in the body of the loop till the condition evaluates to false. The loop may not be executed at all the if the condition is initially true. Do Until loop is an entry controlled loop in which the condition is placed at the entry point. This statement executes the statements specified in the body of the loop till the condition evaluates to false. The loop may not be executed at all the if the condition is initially true. Syntax : Syntax : Do Until Do Until ‘ One or more VB Statements ‘ One or more VB StatementsLoop

48 Examples of Do Until..Loop  Example 1 : Never executes loop Dim A as Byte A=10 Do Until A<10 A=A-1 A=A-1Loop  Example 2 : Executes loop Dim P as Byte P=20 Do Until P<5 P=P-2 P=P-2Loop

49 Do..Loop Until Do Loop Until is an exit controlled loop as the condition is placed at exit point. The body of the loop is going to be executed at least once whether the condition evaluates to true or false. Loop is executed as long as the result of the condition remains false. Do Loop Until is an exit controlled loop as the condition is placed at exit point. The body of the loop is going to be executed at least once whether the condition evaluates to true or false. Loop is executed as long as the result of the condition remains false. Syntax : Syntax :Do One or more VB Statements One or more VB Statements Loop Until Loop Until

50 Examples Example 1 : Example 1 :Do num = InputBox (“Enter a number”) num = InputBox (“Enter a number”) sum = sum + num sum = sum + num Loop Until num = 0 Here the statements inside the loop will be executed once no matter what the comparison test evaluates to. Here the statements inside the loop will be executed once no matter what the comparison test evaluates to.

51 While..Wend While..Wend loop is functionally equivalent to the Do While..Loop. It executes a set of VB statements till the condition evaluates to true. While..Wend loop is functionally equivalent to the Do While..Loop. It executes a set of VB statements till the condition evaluates to true. Syntax : Syntax : While While one or more vb statements one or more vb statementsWend

52 Examples Example 1 : Generate the sum of first 10 natural no’s Example 1 : Generate the sum of first 10 natural no’s I = 1 While I<=10 Sum = Sum + I Sum = Sum + I I = I + 1 I = I + 1Wend Print “Sum of 10 natural no’s = ” ; Sum

53 Nested Loops A loop within another loop is called as Nested Loop. A loop within another loop is called as Nested Loop. Example : Example : For I = 1 to 5 For J = 1 To 3 For J = 1 To 3 Print J Print J Next J Next JPrint Next I Inner Loop Outer Loop

54 Working of Nested Loops In nested loops the inner loop is executed completely for one time execution of the outer loop. In the Previous example the Inner Loop will be executed three times for every execution of the outer loop. In nested loops the inner loop is executed completely for one time execution of the outer loop. In the Previous example the Inner Loop will be executed three times for every execution of the outer loop. Nested loops are very useful when there is a requirement to generate different kind of patterns as output. Nested loops are very useful when there is a requirement to generate different kind of patterns as output.

55 Examples Example : Program to generate the output given below : Example : Program to generate the output given below :1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 Sol : Sol : For I = 1 To 5 For J = 1 To I For J = 1 To I Print I; Print I; Next J Next JPrint Next I

56 Home Assignment 3 – Nested Loops Write programs to generate the following patterns : Write programs to generate the following patterns : 1) 12) 1 2 3 4 5 1 2 1 2 3 4 1 2 3 1 2 3 1 2 3 4 1 2 1 2 3 4 5 1 3) A A B A B C A B C D

57 Home Assignment 4 – Output Related Questions Specify the output of the following output related questions, assume that variables are declared : Specify the output of the following output related questions, assume that variables are declared : 1) sum=02) sum = 0 For I = 1 To 4p=2 : q=4 For J = 1 To 3Do While p<=10 For J = 1 To 3Do While p<=10 sum = sum + JIf p Mod 2 = 0 Then sum = sum + JIf p Mod 2 = 0 Then Next Jsum = sum + p Next Jsum = sum + p Print “Sum = ”;sumEnd If Next Ip=p+1 Loop Print sum Print sum

58 Output related questions 3) R=5 : S=34) M=2 : N=4 DoDo Until M>12 Print R, SN = N + M Print R, SN = N + M R = R + 1If M Mod 3 = 0 Then R = R + 1If M Mod 3 = 0 Then If R = 7 Then N = N - M If R = 7 Then N = N - M Exit DoElse Exit DoElse End IfN = N + M End IfN = N + M S = S + REnd If S = S + REnd If Loop While R <=10M=M+1 Loop Print M, N Print M, N

59 Home Assignment - 5 Programming Questions : Develop programs for the followings : Programming Questions : Develop programs for the followings : To generate the mirror image of the number entered by the user. To generate the mirror image of the number entered by the user. To generate the prime numbers between 100 and 700. To generate the prime numbers between 100 and 700. To Check whether the number entered by the user is a prime number or not. To Check whether the number entered by the user is a prime number or not. To print first 30 multiples of the number entered by the user. To print first 30 multiples of the number entered by the user. To generate the factorial of the number input by the user. To generate the factorial of the number input by the user.

60 Home Assignment - 5 To generate the Fibonacci series upto first 15 terms i.e. 0 1 1 2 3 5 8………….. To generate the Fibonacci series upto first 15 terms i.e. 0 1 1 2 3 5 8………….. To find the sum of all the numbers divisible by 7 from 100 to 200. To find the sum of all the numbers divisible by 7 from 100 to 200. To check whether the year entered by the user is leap year or not. To check whether the year entered by the user is leap year or not. To find and print the sum of digits of the number entered by the user. To find and print the sum of digits of the number entered by the user. To find and print the product of digits of the number accepted from the user. To find and print the product of digits of the number accepted from the user.

61 Assessment Tools Students will be given Programming problems, output and error finding questions to test whether they understood the various concepts taught through this presentation. Students will be given Programming problems, output and error finding questions to test whether they understood the various concepts taught through this presentation. Various parameters are used to check the understanding of the concept and its implementation in Programming. Various parameters are used to check the understanding of the concept and its implementation in Programming. All the parameters mention in the next slide have their own importance, so all these parameters needs to be checked by the Teacher teaching Programming. All the parameters mention in the next slide have their own importance, so all these parameters needs to be checked by the Teacher teaching Programming.

62 Assessment Tool Parameter Specify whether Remark LogicCorrect/Incorrect EffectiveYes/No EfficientYes/No CodingCorrect/Incorrect SyntaxCorrect/Incorrect Following Naming Conventions Yes/No


Download ppt "Project on VB Control Structures Prepared By : Sudhir Kataria PGT Computer Sc. PGT Computer Sc. K V Chamera II K V Chamera II."

Similar presentations


Ads by Google