Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Lab Session-VII CSIT-121 Fall 2000 4 Revising Previous Lab and performing ASCII chart printing experiment (DEMO) 4 Visual Studio Features 4 The While.

Similar presentations


Presentation on theme: "1 Lab Session-VII CSIT-121 Fall 2000 4 Revising Previous Lab and performing ASCII chart printing experiment (DEMO) 4 Visual Studio Features 4 The While."— Presentation transcript:

1

2 1 Lab Session-VII CSIT-121 Fall 2000 4 Revising Previous Lab and performing ASCII chart printing experiment (DEMO) 4 Visual Studio Features 4 The While Loop variations 4 Lab Exercises

3 2 Revising Structured Choice 4 Structured choice can be implemented with switch~case construct. When should we prefer switch-case over if-else? 4 Why is a default case added at the end? 4 Is it ok to use floating point values in switch-case statements?

4 3 The counter-controlled loop 4 The for loop is best for implementing a counter controlled loop. 4 For example, we can convert a given while loop into for loop to show how it works

5 4 The for loop 4 int count=0; 4 while (count<20) { 4 cout >thisID; count++;} 4 Changed to: 4 int count=0; 4 for (count=0; count<20; count++) 4 {cout >thisID; }

6 5 Lab Exercises Review 4 Library catalogue menu selection with beeps on wrong input 4 Beeps can be generated by printing “\a” 4 List of upper and lower case letters 4 The for loop has multiple increment expressions 4 The for loop can also have null expressions 4 e.g. for (; ;){cout<<“Will it end?\n”;}

7 6 Visual Studio Debugger 4 Debugging is quite flexible in Visual Studio 4 You can start debugging by first deciding about the breakpoints in your program 4 Once breakpoints are inserted, you can choose Build==>start debug==>go or step-into 4 This causes a new menu option Debug to appear in your main menu 4 Once the program is halted at a breakpoint, you can choose several options

8 7 Visual Studio Debugger 4 From a break point: 4 You can step-into functions(i.e. execute even the standard C++ library functions) 4 You can step-over functions(i.e. skip the standard functions and just go to your code) 4 You can step-out of a function 4 Instead of single stepping, it is advised to set breakpoints and use go option

9 8 While Loop Design 4 Design While loop with care else the program will be stuck in INFINITE LOOP. 4 Check for these three conditions 4 INITIALIZATION (The loop control variable should be initialized before starting the loop) 4 TESTING While(test) {…..} 4 UPDATE Loop control variable should be updated within the loop

10 9 While Loop Design 4 Lab Exercise: HiLo Game (Demo needed) 4 What type of loop is needed? 4 Get User input 4 (if user input is not equal to key) 4 { display hints 4 get user input again} 4 A starting example follows:

11 10 An Example 4 #include 4 using namespace std; 4 #define MAX_LIMIT 99 4 void main() { 4 int key; 4 int seed=0; 4 while (seed<254) 4{4{ 4 srand(seed++); 4 key = rand()%MAX_LIMIT; 4 cout<<key<<endl; 4 }}

12 11 Do-While Loop 4 In the Hi-Lo algorithm, we have some redundant statements. Can you identify? 4 To get rid of the same, we can use the do{}- while loop instead of while{} 4 do-while loop makes sure that the loop is executed at least once. 4 It is recommended where it is necessary to run the loop at least once

13 12 Lab Exercises 4 Design a program that: 4 prompts the user to input the salary for tax computation 4 Checks the user input to see if it is within the given salary range (2000-5000) 4 If not, it gives a warning beep and re- displays the prompt on a clean screen. 4 Use do-while{} loop and see how the screen can be cleared between menu displays


Download ppt "1 Lab Session-VII CSIT-121 Fall 2000 4 Revising Previous Lab and performing ASCII chart printing experiment (DEMO) 4 Visual Studio Features 4 The While."

Similar presentations


Ads by Google