Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter: 01 C++ Revision Tour

Similar presentations


Presentation on theme: "Chapter: 01 C++ Revision Tour"— Presentation transcript:

1 Chapter: 01 C++ Revision Tour

2 HEADER FILE Name the header file to be included for the use of following built-in functions: frexp() toupper() getc() strcat() isupper() setw() exp() strcmp() isdigit() log() scanf() system() getchar() clrscr() strcpy() getxy() puts() gets() cos() gotoxy() isalnum() fabs() strlen() exit()

3 HEADER FILE Answers: frexp() math.h toupper() ctype.h getc() stdio.h
strcat() string.h isupper() ctype.h setw() iomanip.h exp() math.h strcmp() string.h isdigit() ctype.h log() math.h scanf() stdio.h system() stdlib.h getchar() stdio.h clrscr() conio.h strcpy() string.h getxy() conio.h puts() stdio.h gets() stdio.h cos() math.h gotoxy() conio.h isalnum() ctype.h fabs() math.h strlen() string.h exit() process.h

4 Differentiation What is the difference between Local Variable and Global Variable? Also, give a suitable C++ code to illustrate both. Local Variable Global Variable 1. It is a variable which is declared within a function or within a block. 1. It is variable which is declared outside all the functions 2. It is accessible only with in a function/block in which it is declared 2. It is accessible throughout the program

5 Differentiation What is the difference between #define and const? Explain with suitable example. #define const 1. It can only define simple constants. 1. It can define any type of C++ constant including class, structure constant 2. Values assigned before compilation. 2. Values assigned while program starts running. 3. Example: #define MAX 10 const int MAX = 10

6 Differentiation What is the difference between call by value and call by reference? Also, give a suitable C++ code to illustrate both. Distinguish between an object and a class Reusability of classes is one of the major properties of OOP. How is it implemented in C++ Differentiate between Data Hiding and Encapsulation. What is the purpose of header file in a program? Differentiate between the post-increment and pre- increment

7 Differentiation Differentiate between a Run Time and Syntax Error. Also give suitable examples of each in C++. Differentiate between a Logical Error and Syntax Error. Also give suitable examples of each in C++. How is an entry controlled loop different from exit controlled loop? What is the difference between Actual Parameter and Formal Parameter? Also, give a suitable C++ code to illustrate both.

8 QUESTIONS RELATED TO ERRORS
Q1. Rewrite the following program after removing the syntactical errors (if any). Underline each correction. #include[iostream.h] typedef char Text(80); void main() { Text T= “Indian”; int Count = strlen(T); cout<< T << ’has’ << Count << ‘characters’ <<endl; }

9 QUESTIONS RELATED TO ERRORS
Q2. Rewrite the following program after removing the syntactical errors (if any). Underline each correction. #include<iostream.h> void main() { first = 4, second =6; show(first ; second); show(first); } void show(int a, int b = 30) a = a + b; cout<< a >> b;

10 QUESTIONS RELATED TO ERRORS
Q3. Rewrite the following program after removing the syntactical errors (if any). Underline each correction. #include<iostream.h> #define SIZE =10 void main( ) { int a[SIZE]={10,20,30,40,50}; float x=2; SIZE=5; for(i=0, i<SIZE; i++) cout<<a[i]%x ; }

11 QUESTIONS RELATED TO ERRORS
Q4. Rewrite the following program after removing the syntactical errors (if any). Underline each correction. #include [iostream.h] class PAYITNOW { int Charge; PUBLIC: void Raise(){cin>>Charge;} void Show{cout<<Charge;} }; void main() PAYITNOW P; P.Raise(); Show(); }

12 QUESTIONS RELATED TO ERRORS
class code { int num; char branch; static int count; code (int i =0, char b); public: code (code A) { num = A.num; branch = A.branch; } ~ code ( ) { cout<< “Destroying Object” << --count <<endl; } }; code (int i, char b) { num = i; branch = b; void main( ) { code x1, x2; }

13 QUESTIONS RELATED TO ERRORS
#include <iostream.h> struct Value { int Color,Style; } void main() Value Point1=(5,3); Displayelements(Point1); Value Point2=Point1; Color.Point1+=2; Displayelements(Point2); void Displayelements(Value P) cout<<P.Color<<P.Style<<endl;

14 QUESTIONS RELATED TO ERRORS
#include<iostream.h> void main( ) { struct test char test_name[20]; char type; int tickets=10; } object; gets(test_name); puts(test_name); }

15 QUESTIONS RELATED TO OUTPUTS
Q1. Give the output of the following Program: #include <iostream.h> int g=20; void func(int &x ,int y) { x=x-y; y=x*10; cout<<x<<“,”<<y<<“\n”; } void main( ) int g=7; func(g,::g); cout<<g<“,”<<::g<<“\n”; func(::g,g);

16 QUESTIONS RELATED TO OUTPUTS
Q2. Give the output of the following Program: #include<iostream.h> int a = 3; void demo (int &x, int y, int *z) { a + = x; y * = a; *z = a + y; cout<<a<<”, “<<x<< “,”<<y<<”,“<<*z<<endl; } void main( ) int a = 2, b=5; demo(::a,a,&b); cout<<::a<<”,”<<a<<”,”<<b;

17 QUESTIONS RELATED TO OUTPUTS
Q3. Give the output of the following Program: #include <iostream.h> #include<conio.h> void Updatevalues(int Arr[ ], int Count) { for (int C=1;C<Count;C++) Arr[C-1]+=Arr[C]; } void main() clrscr(); int A[]={8,9,10},B[]={100,200,300,400},C[]={90,120}; Updatevalues(A,3); Updatevalues(B,4); Updatevalues(C,2); for(int L=0 ; L<3 ; L++) cout<<A[L]<<'#'; cout<<endl; for(L=0 ; L<4 ; L++) cout<<B[L] <<'#'; for(L=0 ; L<2 ; L++) cout<<C[L] <<'#'; }

18 QUESTIONS RELATED TO OUTPUTS
Q4. Give the output of the following Program: #define i 5 class TEMP { static int a; float b; public: TEMP( ) { b=10; } void INTEMP( ) { a++; b=a+10; } void OUTTEMP( ) cout<<a*i<<"$"<<b-3<<endl; }; int TEMP::a=2; void main() { TEMP ob[5]; for(int x=1;x<5;x++) ob[x].INTEMP( ); for(x=1;x<5;x++) ob[x].OUTTEMP( ); }

19 QUESTIONS RELATED TO OUTPUTS
Q5. Give the output of the following Program: #include<iostream.h> #include<stdio.h> #include<conio.h> void TRANSFER(char *s1,char *s2) { int n,j=0; for(int i=0;*(s1+i)!='\0';i++) n=*(s1+i); if(n%2==0) *(s2+j++)=*(s1+i); } *(s2+j) = ‘\0’; void main() { char *p="ChaRlesBabBaGe",q[80]; TRANSFER(p,q); cout<<q<<endl; }

20 QUESTIONS RELATED TO OUTPUTS
Q6. Give the output of the following Program: #include<iostream.h> void withdef ( int HisNum = 30) { for ( int I = 20 ; I<= HisNum; I+= 5) cout<< I <<”,”; cout<<endl; } void Control( int &MyNum ) { MyNum + = 10; withdef(MyNum); void main( ) { int YourNum = 30; Control(YourNum ); withdef( ); cout<< “Number=”<<YourNum<<endl;

21 QUESTIONS RELATED TO OUTPUTS
Q7. Give the output of the following Program: void main( ) { char * NAME = “inForMATion”; for( int x=0;x<strlen(NAME);x++) if(islower(NAME[x]) NAME[x] = toupper(NAME[x]); else if(isupper (NAME[x])) if(x%2==0) NAME[x] = NAME[x -1]; NAME[x]--; cout<<NAME <<endl; }

22 QUESTIONS RELATED TO OUTPUTS
Q8. Give the output of the following Program: #include<iostream.h> void change(int &a, int b=10) { if(b%10==0) a+=5; for(int i=5; i<=a; i++) cout<< b++ <<‘:’; cout<<endl; } void Disp(int x) if(x%3==0) change(x); else change(x, 3); void main() { Disp(3); Disp(4); change(2,20); }

23 QUESTIONS RELATED TO RANDOM NUMBERS
Q1. Study the following program and select the possible output from it: #inlude<iostream.h> #include<conio.h> #include<stdlib.h> const int LIMIT = 4; void main( ) { randomize( ); int Points; Points = random(LIMIT); for ( int p = Points; p>=100; p--) cout<<p<<”#”; cout<<endl; } 103#102#101#100# 103#102#101#100 101#102#103#104# 104#103#102#101#100#

24 QUESTIONS RELATED TO RANDOM NUMBERS
Q2. Observe the following program carefully, choose the possible incorrect output(s) from the options from(i) to (iv), and justify your option: #include<iostream.h> #include<stdlib.h> const int LOW=100; void main() { randomize( ); int POINT=10, Number; for(int i=1;i<=4;i++) Number=LOW+random(POINT); cout<<Number<<“ " ; POINT--; } (i) (ii) (iii) (iv)

25 QUESTIONS RELATED TO RANDOM NUMBERS
Q3. Observe the following program carefully & choose the correct possible output from the options (i) to (iv) justifying your answer: #include<iostream.h> #include<conio.h> #include<stdlib.h> void main( ) { clrscr( ); randomize( ); int RN; RN=random(4)+5; for(int i=1; i<=RN; i++) cout<<i<<' '; getch(); } 0 1 2

26 QUESTIONS RELATED TO RANDOM NUMBERS
Q4. Observe the following program carefully & choose the correct possible output from the options (i) to (iv) justifying your answer: #include<iostream.h> #include<stdlib.h> void main( ) { randomize( ); int G,H=5; G=random(H)+30; for(int i=35; i>G; i--) cout<<i<<’$’; cout<<i; } i) 35$34$33$32$31$30$ ii) 35$34$33$32$31 iii) 30$31$32$33$34$35$36 iv) 35$34$33$32$31$30

27 QUESTIONS RELATED TO RANDOM NUMBERS
Q5. In the following program , find the correct possible output(s) from the options: #include<stdlib.h> #include<iostream.h> void main() { randomize( ); Char Weekdays[][5]={”Sun”,”Mon”,”Tue”,”Wed”,”Thu”,”Fri”,”Sat”}; int Num; for(int I=0;I<3;I++) { Num =random(3)+1; cout<<Weekdays[Num]<<” : ”; } } Outputs: Wed : Thu : Fri : Tue : Wed : Tue : Sun : Mon : Tue : Tue : Wed : Mon :

28 QUESTIONS RELATED TO RANDOM NUMBERS
Q6. If the value of VAL entered by the user is 10, choose the correct possible output(s) from the options from i) to iv) and justify your option. #include<iostream.h> #include<stdlib.h> void main() { randomize(); int VAL, Rnd; int n=random(2); Rnd=8 + random(sizeof(VAL)) * 1; while(n<Rnd) cout<<n<< “\t”; n++; } Output options: i) ii) iii) iv)

29 QUESTIONS RELATED TO RANDOM NUMBERS
Q7. Observe the following program and find out, which option or options out of (i) to (iv) will not be expected output(s) from the program? What will be the minimum and maximum value assigned to the variable Sequence. #include<iostream.h> #include<stdlib.h> void main( ) { int sequence, select[4] = {25, 90, 30, 45}; randomize( ); for ( int c= 0; c < 4 ; c++) sequence = random( 4 - c); cout<< select[sequence] << } Outputs:

30

31


Download ppt "Chapter: 01 C++ Revision Tour"

Similar presentations


Ads by Google