1 / 31

Chapter: 01 C++ Revision Tour

Chapter: 01 C++ Revision Tour. 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()

rea
Download Presentation

Chapter: 01 C++ Revision Tour

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 • 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 Answers:

  4. Differentiation • What is the difference between Local Variable and Global Variable? Also, give a suitable C++ code to illustrate both.

  5. Differentiation • What is the difference between #define and const? Explain with suitable example.

  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( ) { inta[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 Q5. 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 Q6. • #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 Q7. • #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); cout<<g<“,”<<::g<<“\n”; }

  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] <<'#'; cout<<endl; 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]; • else • 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 = 100 + 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) 109 101 104 104 (ii) 106 107 105 102 (iii) 107 106 108 106 (iv) 101 104 104 105

  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 • 1 2 3 4 5 6 7 8 • 4 5 6 7 8 9 • 5 6 7 8 9 10 11 12

  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: 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. Output options: i) 1 2 3 4 5 6 7 8 9 10 11 12 13 ii) 0 1 2 3 4 5 6 7 8 iii) 1 2 3 4 5 iv) 1 2 3 4 5 6 7 8

  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. Outputs: 45@90@30@25@ 90@25@90@25@ 30@30@25@25@ 30@30@90@25@

More Related