KENDRIYA VIDYALAYA ALIGANJ SHIFT-II HOLIDAY HOME WORK- 2018-19 XII COMPUTER SCIENCE ARRAY AND STRUCTURES 1. Write a function which will take a string and returns the word count. Each word is separated by a single space. 2. Write a program to count the occurrence of each digit, white spaces, char (blank, tab, newline) & all other characters in a given string. 3. Write a program to search an entered character in the string. 4. Write a program to check whether the given string is palindrome or not. 5. Write a program to check whether the entered two strings are equal or not. 6. Write a program to convert a given the given string into Upper case &Lower case 7. Write a program to search an entered word in a given string. 8. Write a program to eliminate the extra spaces from a given string. 9. Write a program to convert ; into, in a given string. 10. Write a program to enter a string and count the number of Upper case, Lower case and special characters. 11. Write a program to enter a string and count the number of blank spaces. 12. Write a program to enter a string and print every word in a new line. 13. Write a program to enter integers into 2D array (3X3) and display the array s mirror image. 14. Write a program to enter n integers into an array of integers and multiply all even position s number by 2 and all odd position s integers by 3 and display the result(note :-array starting from index number 0). 15. Write a program to use define directive in program. 16. Write a program to perform sum of upper and lower diagonal elements given below: 0 1 2 0 1 2 3 4 5 3 4 5 6 7 8 6 7 8 17. Write a program to double every element of a 2D array of integers. 18. Write a program to print all the elements of 2D array except diagonal elements. 19. Write a program to exchange first row and last row of a 2D array of integers. 20. Write a program to display each row s characters of a 2D string in reverse order. 21. Write a program to find the frequency of a person s name in a 2D string array. ----------------------------------------------------------------------------------------- 22. Name the Header file(s) that shall be needed for successful compilation of the following C++ code int a[10]; for (int i=0;i<10;i++) cin>>a[i]; if(a[i]%2==0) a[i]=pow(a[i],3); else a[i]=sqrt(a[i]); if(a[i]>32767) exit(0); getch(); 23. Name the header files that shall be needed for the following void main( ) char String[ ] = Peace ; cout << setw(2)<<string; Find the output of the following program :
#include<iostream.h> struct MyBox int length, breadth, height; ; void Dimension(MyBox M) cout<<m.length<< x <<M.breadth<< x <<M.height; MyBox B1=10,15,5,B2,B3; ++B1.height; Dimension(B1); B3=B1; ++B3.lenght; B3.breadth++; Dimension(B3); B2=B3; B2.height+=5; B2.lenght--; Dimension(B2); 24. Find the correct possible output from the option: #include<stdlib.h> #include<iostream.h> Randomize(); Char Area[][10]= North, South, East, West ; int ToGo; for(int i=0;i<3;;i++) ToGo=random(2)+1; Cout<<Area[ToGo]<< : ; Outputs: South : East : South : North : South : East : South : East : West: South : East : East : 25. Suppose a class is defined as follows answer the following questions below: class animal Private: char name[15]; int legs; Public: animal(int l) leg=l; Void input() cin>>name>>legs; animal() cout<< Animal ; ~animal() cout<<~animal int num_of_legs() i. What features of OOPS are implemented in the program? ii. Write statement to execute constructor and destructor of the program
; return legs; 26. Define a class serial in C++ with the following specifications: Private members of class serial Serialcode integer Title 20 character Duration float Noofepisodes integer Public member function of class serial A constructor to initialize duration as 30 and noofepisodes as 10. Newserial() function to accept values for Serialcode and Title. Otherentries () function to assign the values of Duration and Noofepisodes with the help of corresponding values passed as parameters to this function. Dispdata() function to display all the data members on the screen. --------------------------------------------------------------------------------------------------- OBJECT ORIENTED PROGRAMMING 27. What is abstraction? 28. How is data hiding implemented in C++? 29. What is polymorphism? How does function overloading implement polymorphism? 30. What is Function Overloading? Explain with example. 31. What do you mean by Data Encapsulation, Inheritance? 32. Define Class and Object. 33. Differentiate between Object based programming and Object Oriented programming. 34. Enlist some advantages of OOP CLASSES AND OBJECTS 35. Define a class TravelPlan in C++ with the following descriptions: Private Members: PlanCode of type long Place of type character array (string) Number_of_travellers of type integer Number_of_buses of type integer Public Members: A constructor to assign initial values of Plan Code as 1001, Place as Agra, Number_of_travellers as 5, Number_of_buses as 1 A function NewPlan( ) which allows user to enter PlanCode, Place and Number_of_travellers. Also, assign the value of Number_of_buses as per the following conditions : Number_of_travellers Number_of_buses Less than 20 1 Equal to or more than 20 and less than 40 2 Equal to 40 or more than 40 3 A function ShowPlan( ) to display the content of all the data members on screen. 36. Define a class Tour in C++ with the description given below : Private Members : TCode of type string NoofAdults of type integer NoofKids of type integer Kilometres of type integer TotalFare of type float Public Members : A constructor to assign initial values as follows : TCode with the word NULL
NoofAdults as 0 NoofKids as 0 Kilometres as 0 TotalFare as 0 A function AssignFare () which calculates and assigns the value of the data member TotalFare as follows For each Adult Fare(Rs) For Kilometres 500 >=1000 300 <1000 & >=500 200 <500 For each Kid the above Fare will be 50% of the Fare mentioned in the above table For example : If Kilometres is 850, NoofAdults = 2 and NoofKids = 3 Then TotalFare should be calculated as NumofAdults * 300 + NoofKids * 150 i.e. 2*300 + 3*150=1050 A function EnterTour( ) to input the values of the data members TCode, NoofAdults, NoofKids and Kilometres; and invoke the Assign Fare( ) function. A function ShowTour( ) which displays the content of all the data members for a Tour. FIND-OUTPUT 37. #include <iostream.h> struct Game int Score, Bonus;; void Calculate(Game &P, int N = 10) P.Score++; P.Bonus+=N; Game PL=7, 12; Calculate(PL, 5); cout << PL.Score << ":" << PL.Bonus << endl; Calculate(PL); cout << PL.Score << ":" << PL.Bonus << endl; Calculate(PL, 15); cout << PL.Score << ":" << PL.Bonus << endl; 38. #include<iostream.h> int i = 20; void abc () static int i = 4; i = i + 4; cout << "first = " << i; void main( ) int i = 2;abc( ); cout << " second = " << i << endl; abc(); cout << " Third = " << ::i << endl; 39. #include<stdlib.h> #include<iostream.h> randomize(); int Num, Rndnum; cin >> Num; Rndnum = random(num) + 5; for (int N = 1; N<=Rndnum-1; N++) cout << N << ""; 40. #include <iostream.h> // Function prototype for general function void try(); class abc
int x; public: // Class member function void try() cout << "Hello"; ; // Function body of general function void try() cout << "How are you?"; abc A; A.try(); try(); 41. #include <iostream.h> #include <conio.h> int Function(int p) if(p == 1 p == 0) return 1; if(p%2 == 0) return Function(p / 2) + 4; else return Function(p - 1) + 5; clrscr(); int A = Function(6); cout << A; 42. #include<iostream.h> void Execute(int &B, int C = 100) int TEMP = B+C; B += TEMP; if(c!= 200) cout << TEMP << B << C << endl; int M = 90, N = 10; Execute(M); cout << M << N << endl; Execute(M, N); cout << M << N << endl; 43. #include<stdio.h> #include<iostream.h> int s1,s2, num; s1 = s2 = 0; for(int x=0; x<11; x++) cin >> num; if (num > 0) s1 += num; else s2 /= num; cout<<s1<<s2; 44. #include<iostream.h> int func(int &x, int y = 10) if ( x % y == 0) return ++x; else return y--; int p = 20, q = 23; q = func(p,q); cout << p << q << endl; p = func(q); cout << p << q << endl;
q = func(p); cout << p << q << endl; 45. # include<iostream.h> main() int x, sum = 0; int n; cin >> n; for (x = 1; x < 100; x+=2) if( x%2 == 0) sum += x; cout << "SUM = " << sum; 46. #include <iostream.h> int max(int &x, int &y, int &z) if (x > y && y > z) y++; z++; return x; else if (y > x) return y; else return z; int a = 10, b = 13, c = 8; a = max(a, b, c); cout << a << b << c << endl; b = max(a, b, c); cout << ++a << ++b << ++c << endl; c = max(a, b, c); cout << a++ << ++b << +++c << endl;