Chapter: 01 C++ Revision Tour

Slides:



Advertisements
Similar presentations
Modular Programming With Functions
Advertisements

Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
Chapter 8 Scope, Lifetime and More on Functions. Definitions Scope –The region of program code where it is legal to reference (use) an identifier Three.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 7: User-Defined Functions II.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 7: User-Defined Functions II.
Chapter 7: User-Defined Functions II
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
Chapter 7: User-Defined Functions II Instructor: Mohammad Mojaddam.
True or false A variable of type char can hold the value 301. ( F )
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 6 Functions.
1 Chapter 8 Scope, Lifetime, and More on Functions Dale/Weems/Headington.
CECS 121 EXAM 1. /* C Programming for the Absolute Beginner */ // by Michael Vine #include main() { printf(“\nC you later\n”); system(“pause”); }
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
1 Chapter 9 Scope, Lifetime, and More on Functions.
1 Arrays Chapter 13 Especially read 13.1 – 13.2 Text introduces vectors, which we will not cover, in 13.3.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
M. Taimoor Khan #include void main() { //This is my first C++ Program /* This program will display a string message on.
XII CBSE Previous Year Question Paper QUESTION NO 1 (a) 1 OR 2 Marks.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
1 Chapter 9 Additional Control Structures Dale/Weems.
Chapter 4: Subprograms Functions for Problem Solving Mr. Dave Clausen La Cañada High School.
Chapter 05 (Part III) Control Statements: Part II.
1 Announcements Note from admins: Edit.cshrc.solaris instead of.tcshrc Note from admins: Do not use delta.ece.
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 6 Functions.
Control Structures RepetitionorIterationorLooping Part I.
Manish K Parmar PGT (CS) K V VVNagar Thursday, December 24, 2015 Lesson on USER DEFINED FUNCTION IN C++ Presented by Manish K Parmar PGT Computer Science.
More Array Access Examples Here is an example showing array access logic: const int MAXSTUDENTS = 100; int Test[MAXSTUDENTS]; int numStudents = 0;... //
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Brief Edition Chapter 6 Functions.
Function User defined function is a code segment (block) that perform an specific action. Function Definition: Function Definition: Return_DT F_name (
C++ Programming Lecture 13 Functions – Part V The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
 Templates enable us to define generic classes and functions and thus provides support for generic programming. Generic types are used as parameters.
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
CSC141- Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 12.
XII CBSE Previous Year Question Paper QUESTION NO 1 (F) 2 or 3 Marks.
April 11, 2005 More about Functions. 1.Is the following a function call or a function header? calcTotal(); 2.Is the following a function call or a function.
1 Programming in C++ Dale/Weems/Headington Chapter 9 Additional Control Structures (Switch, Do..While, For statements)
EEL 3801 C++ as an Enhancement of C. EEL 3801 – Lotzi Bölöni Comments  Can be done with // at the start of the commented line.  The end-of-line terminates.
1 Scope Lifetime Functions (the Sequel) Chapter 8.
Programming Languages -2 C++ Lecture 3 Method Passing Function Recursion Function Overloading Global and Local variables.
© Janice Regan, CMPT 128, January CMPT 128: Introduction to Computing Science for Engineering Students Introduction to Arrays.
Chapter 6 Functions. 6-2 Topics 6.1 Modular Programming 6.2 Defining and Calling Functions 6.3 Function Prototypes 6.4 Sending Data into a Function 6.5.
CS1201: Programming Language 2 Function I By: Nouf Aljaffan Edited by : Nouf Almunyif.
1 Chapter 8 Scope, Lifetime, and More on Functions CS185/09 - Introduction to Programming Caldwell College.
C++ Programming Lecture 13 Functions – Part V By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
arithmetic operator & cin I.Mona Alshehri The output formatting functions setw(width) setw(n) - output the value of the next expression in n columns.
XII CBSE Previous Year Question Paper QUESTION NO 1 (D) 2 or 3 Marks.
REEM ALAMER REVISION FOR C LANGUAGE COURSE. OUTPUTS int main (void) { int C1, C2; int *p1, *p2; C1 = 8; p1 = &C1; C2 = *p1 / 2 + 5; p2 = &C2; printf ("C1.
T/F  The following code will compile without error. int x = 3, y = 4, z = 5; double k = 3.4; cout
-Neelima Singh PGT(CS) KV Sec-3 Rohini
Chapter 7: User-Defined Functions II
Functions prototypes arguments overloading return values part I.
Suppose we want to print out the word MISSISSIPPI in big letters.
Chapter 5 Functions.
Chapter 5 Function Basics
Function User defined function is a code segment (block) that perform an specific action. Function Definition: Return_DT F_name ( list of formal parameters)
Value returning Functions
Chapter 7 Additional Control Structures
OBJECTIVE QUESTIONS.
Counting Loops.
Lec 14 Oct 23, 02.
Chapter 7: User-Defined Functions II
The Function Prototype
Programming fundamentals 2 Chapter 1: Functions (Sub-Algorithms)
Scope of Identifier The Scope of an identifier (or named constant) means the region of program where it is legal to use that.
CS-161 Computer Programming Lecture 15 & 16: Arrays II
Course Outcomes of Programming In C (PIC) (17212, C203):
Functions Chapter No. 5.
Presentation transcript:

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() gets() cos() gotoxy() isalnum() fabs() strlen() exit()

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

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

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

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

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.

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; }

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;

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 ; }

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(); }

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; }

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;

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); }

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);

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;

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] <<'#'; }

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( ); }

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; }

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;

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; }

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); }

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#

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

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

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

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 :

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) 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

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