Review of Class Xi

Total Page:16

File Type:pdf, Size:1020Kb

Review of Class Xi

REVIEW OF CLASS XI Short questions: PART- I(SOLVED) a.i.1. What are literals in C++.How many types of literals you know in C++. Ans Literals (also known as constants) are expressions with a fixed value. These are the data items whose value never change during execution of the program. It is often referred as literals. Five types of literals are there in C++ Integer literals , Floating point literals, character literal, string literals, Boolean values . a.i.2. What is the difference between ‘a’ and “a”? Ans ‘a’ is simply a character constant that occupies one byte in memory while “a” is string literal that stores a+ \0 character in memory that means it stores 2bytes in memory. a.i.3. What is the size of the following :’\n’, ”hello\t”, ”Saima”, ’ \’. Ans ’\n’ : 1 byte ,it is an escape sequence ”hello\t” : 7bytes (hello takes 5 bytes ,\t is an esacpe sequence takes 1byte , one for null character) ”Saima” : 6bytes( 5 bytes for saima and one for null charcter ) ’ \’ : 1 byte ,it is character constant . a.i.4. Predict the output or error(s) for the following:

void main() { int const p=5; p = p+1 ; cout<

a.i.9. What do you understand by the term type casting? Ans Converting an expression of a given type into another type is known as type-casting. Example int x=9 Float y= float (x) ;//now x is float not int 1. What is the difference between while and do while. Ans while do while It is an entry controlled loop It is an exit controlled loop. If the condition is true then only it If the condition is false then also it executes the body of the loop. gets executed at least once. while loop : Do

while (condition) {

{ Statements;

Statements; }while(condition); }

2. What is the difference between exit() and break. Ans exit() brings the control out of the program It is mainly used in menu driven programs and for error checking condition where we don’t want to check for any other condition if the invalid input is entered . break : is used in loops and so on, and stops the current code block before running onto the next portion of code. (If used in a for loop that is to run 20 times for example, if break is used on the 8th iteration, the for loops ends and moves on to run whatever code comes next).

3. What is the wrong with the following code #include int main () { int n; for (n=1 ; n<9; n++) { cout << n << ", "; if (n==3) { cout << "countdown aborted!"; } break; } return 0; } Ans break cannot come outside the loop therefore it is an error in C++ as misplaced break. 4. Underline the error and rewrite the corrected code : int k = 10; do ; { cout << k++; while k < 50 ; } Ans Correction:

wrong code corrected code int k = 10; int k = 10; do ; do //semicolon is removed { { cout << cout << k++; while ( k < 50) ; while k < 50 ; // while must have braces } }

5. Name the header file(s) that shall be needed for successful compilation of the following C++ code : void main( ) { char Text[40]; strcpy(Text,”AISSCE”); puts(Text); }

Ans strcpy() is defined in and puts() is defined in 6. In the following program, if the value of N given by the user is 15, what maximum and minimum values the program could possibly display? 2

#include #include void main() { int N,Guessme; randomize(); cin>>N; Guessme=random(N)+10; cout<

7. In the following program, if the value of N given by the user is 20, what maximum and minimum values the program could possibly display? 2 #include #include void main() { int N,Guessnum; randomize(); cin>>N; Guessnum=random(N-10)+10; cout<

8. In the following C++ program what is the expected value of Myscore from Options (i) to (iv) given below. Justify your answer. #include #include void main( ) { randomize(); int Score[] = {25,20,34,56, 72, 63}, Myscore; Myscore = Score[2 + random(2)]; cout<

12. Declare a structure customer to store the following data : Customer name ( string), phoneno(integer),age(integer) and use address in the structure. Ans struct customer { char name[20]; int phoneno; int age; address a; }cust; 13. Find the syntax error in the following code: Main()

{ Struct employee { int empno; char Ename[20]; float Basic,hra,da ; double Netpay; } ; emp1,emp2 } Ans Terminator should come after emp1 and emp2 i.e main() { struct employee { int empno; char ename[20]; float basic,hra,da ; double netpay; } emp1,emp2; } 14. write a macro for finding maximum number and print the maxvalue . Ans // function macro #include #define getmax(a,b) ((a)>(b)?(a):(b))

int main() { int x=10, y; y= getmax(x,2); cout << y << endl; cout << getmax(70,x) << endl; return 0; }

Output:

10 70

15. Write a program to create a function to accept student data and pass this structure by reference to function where student is the structure with the fields as name and class[4](characterarray),age and rollno as an integer.

Ans. #include #include struct student {

char name [20]; int age; int roll; char clas[4]; }; void getdata(student &st); void main() { student stud; clrscr(); getdata(stud); cout<<”\nname is “<

void getdata( student & st) { cout<<”name “; cin>> st.name; cout<<”age “; cin>> st.age; cout<<”roll “; cin>> st.roll; cout<<”class “; cin>> st.clas; } //end of function

PART -II HOTS (HIGH ORDER THINKING QUESTIONS): a.i.1. What would be contents of following after array initialization? int A[5]={3,8 ,9} Ans: 3 8 9 0 0 a.i.2. Suggest storage class for following variables ½ each 1. a normal variable. 2. very heavily used variable. 3. a variable that should retain its value after function is over. 4. a variable that spanes multiple files. 5. a variable global in one & not available in another file. a.i.3. Find the output of the following code: main( ) { int n[3][3] = { 2, 4, 3, 6, 8, 5, 3, 5, 1 } ; cout<< n[2][1] ;

} a.i.4. Find the output of the following code: main( ) { int twod[ ][ ] = { 2, 4, 6, 8 } ; cout<< twod ; } a.i.5. Point out the errors, if any, in the following program segments: (a) /* mixed has some char and some int values */ int char mixed[100] ; main( ) { int a[10], i ; for ( i = 1 ; i <= 10 ; i++ ) { cin>> a[i] ; cin>> a[i] ; } } a.i.6. What is the difference between Object Oriented Programming and Procedural Programming?

Ans:

a.i.7. Write the names of the header files to which the following belong: (i) frexp() (ii) isalnum() a.i.8. Write the names of the header files to which the following belong: 1 (i) strcmp() (ii) fabs() a.i.9. Find the output of the following program: #include void Changethecontent(int Arr[], int Count) { for (int C=1;C struct PLAY { int Score, Bonus;}; void Calculate(PLAY &P, int N=10) { P.Score++;P.Bonus+=N; } void main() { PLAY PL={10,15}; Calculate(PL,5); cout<

#include void main() { char mat[3][2]={‘b’ ,’a’ ,’n’ ,’g’ ,’h’ ,’i’ }; cout<< mat[2]; } Ans : Output is : hi ( it starts reading from 2row and 2 column) a.i.13. What is difference between getch and getche()? Ans getch() : waits for the user to input a character and displays the output till the user enters a character.As soon as the user enters a character it transfers the control back to the main function, without displaying what character was entered. getche() : does the same thing but it displays the character entered. Here e stands for echo. a.i.14. What is the difference between strcmp() and strcmpi()? a.i.15. What is purpose of including while generating random numbers. a.i.16. In the following program, if the value of N given by the user is 30, what maximum and minimum values the program could possibly display? 2 #include #include void main() { int N,Guessnum; randomize(); cin>>N; Guessnum=random(N-10)+10; cout<

#include void main(void) { int base,height,area; cout<<"Enter the base and height of the triangle:"; cin>>base>>height; area=0.5*base*height; cout< struct Package { int Length, Breadth, Height; }; void Occupies(Package M) { cout< #include #include void Change(char Msg[],int Len) { for (int Count =0; Count #include void main() { randomize(); int Num, Rndnum; cin>>Num; Rndnum = random (Num) + 7; for (int N = 1; N<=Rndnum ; N++) cout< const int Size 5; void main() { int Array[Size]; Array = {50,40,30,20,10}; for(Ctr=0; Ctr>Array[Ctr]; } a.i.27. Rewrite the following program after removing all the syntax error(s),if any. Underline each correction. #include struct Pixels { int Color, Style ; } void ShowPoint(Pixels P) { cout<>Mno>>Fees;} void Display{cout< class MEMBER { int Mno;float Fees; public: void Register(){cin>>Mno>>Fees;} void Display(){cout< void Secret(char Str[ ]) { for (int L=0;Str[L]!='\0';L++); for (int C=0;C

#agaSbarr

(d) In the following program, if the value of Guess entered by the user is 65, what will be the expected output(s) from the following options (i), (ii), (iii) and (iv)? #include #include void main() { int Guess; randomize(); cin>>Guess; for (int I=1;I<=4;I++) { New=Guess+random(I); cout<<(char)New; } } (i) ABBC (ii) ACBA (iii) BCDA (iv) CABD Ans (i) ABBC a.i.30. (a) What is the difference between Actual Parameter and Formal Parameters? Also, give a suitable C++ code to illustrate both . Ans Actual Parameter Fromal parameter It is a parameter, which is used in function It is a parameter, which is used in function call to send the value to function header header, to receive the value from the parameters that is formal parameters calling environment that is from actual parameters #include void Calc(int T) //T is formal parameter { cout<<5*T; } void main() { int A=45; Calc(A); //A is actual parameter }

(b) Write the names of the header files to which the following belong: (i) frexp() (ii) isalnum() Ans (i) math.h (ii) ctype.h (c) Find the output of the following program: #include struct Game { char Magic[20];int Score; }; void main() { Game M={"Tiger",500}; char *Choice; Choice=M.Magic; Choice[4]='P'; Choice[2]='L'; M.Score+=50; cout<

(c) Rewrite the following program after removing the syntactical errors (if any). Underline each correction.

#include [iostream.h] #include [stdio.h] class Employee { int EmpId=901; char EName [20] ; public Employee(){} void Joining() {cin>>EmpId; gets (EName);} void List () {cout< #include void Encode (char Info [ ], int N) ; void main ( ) { char Memo [ ] = “Justnow” ; Encode (Memo, 2) ; cout< #include const int LIMIT = 4 ; void main ( ) { randomize( ) ; int Points; Points = 100 + random(LIMIT) ; for (int P=Points ; P>=100 ; P– –) cout< #include const int MAX=3 ; void main ( ) { randomize( ) ; int Number ; Number = 50 + random{MAX) ; for (int P=Number; P>=50; P– –) cout<>Charge;} void Show{cout< #include void Encrypt(char T[]) { for (int i=0;T[i]!='\0';i+=2) if (T[i]=='A' || T[i]=='E') T[i]='#'; else if (islower(T[i])) T[i]=toupper(T[i]); else T[i]='@'; } void main() { char Text[]="SaVE EArtH";//The two words in the string Text //are separated by single space Encrypt(Text); cout< #include #include void Convert(char Str[],int Len) { for (int Count =0; Count

Recommended publications