Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Lab Session-3 CSIT121 Fall 2003 Some Questions Scope of Variables Top Down Design Problem The Solution Lab Exercise for Demo.

Similar presentations


Presentation on theme: "1 Lab Session-3 CSIT121 Fall 2003 Some Questions Scope of Variables Top Down Design Problem The Solution Lab Exercise for Demo."— Presentation transcript:

1

2 1 Lab Session-3 CSIT121 Fall 2003 Some Questions Scope of Variables Top Down Design Problem The Solution Lab Exercise for Demo

3 2 Some Questions What will be the result? 15/12 and 15.0/12.0 What is the order of execution? A * B - E / C What is a function prototype? What is the output of the following program and why?

4 3 Sample Code #include using namespace std; void main() { int candies; int kids; int myshare, kidshare; candies=29; kids=5; kidshare = candies/kids; cout<<"Each kid gets "<<kidshare<<endl; cout<<"I keep "<<candies - kidshare*kids<<endl; cout<<"Now I act mean"<<endl; kidshare = candies++/kids; cout<<"Each kid gets "<<kidshare<<endl; cout<<"And I keep "<<candies - kidshare*kids<<endl; }

5 4 Scope of Global Variables #include using namespace std; void prettyprint(); int length; void main() { length=24;

6 5 Scope of Global Variables cout << "I can refer to length here" << length<<endl; prettyprint(); } void prettyprint () {length=26; cout << "I can also refer to length here"<<length<<endl; }

7 6 Scope of Variables Declared in Main Function #include using namespace std; void prettyprint(); void main() { int length=24; cout << "I can refer to length here" << length<<endl;

8 7 Scope of Variables Declared in Main Function prettyprint(); } void prettyprint () { cout << "I cannot refer to length here"<<endl; length=26; }

9 8 Scope of Variables Declared in Any Function Except Main #include using namespace std; void prettyprint(); void main() { cout << "I cannot refer to length here" <<endl; length=24;

10 9 Scope of Variables Declared in Any Function Except Main prettyprint(); } void prettyprint () { int length; cout << "I can only refer to length here"<<length<<endl; length=26; }

11 10 Lab Exercise for Demo Develop a program using top down design approach that accepts 5 values from the user and then calls a function to determine and print the odd numbers from this list. Use the if clause as shown below for determining odd numbers: if ((number%2)!= 0) cout<<“odd”; Make sure that all the variables are declared as global variables


Download ppt "1 Lab Session-3 CSIT121 Fall 2003 Some Questions Scope of Variables Top Down Design Problem The Solution Lab Exercise for Demo."

Similar presentations


Ads by Google