ASSIGNMENT CLASS : XII (2015-16) COMPUTER SCIENCE Short answer typequestions: 1.(a)What is the difference between logical error and runtime error? Give suitable example for the same. (b) What is the difference between Global Variable and Local Variable? (c)differentiate between type casting and type promotion with suitable example. (d) What is the difference between call by value and call by reference? Give an example in C++ to illustrate both. (e)what is the difference between Object Oriented Programming and Procedural Programming? (f)what do you understand by Polymorphism? Give a suitable example of the same. (g)what do you understand by Data Encapsulation and Data Hiding? (h) Differentiate between public and private visibility modes in context of Object Oriented Programming using a suitable example illustrating each. (i) How are data abstraction and data encapsulation inter-related? (j) Differentiate between a runtime error and syntax error. Also give suitable example of each in c++. Find Header Files For The Following 2.(a) Write the names of the header files to which the following belong: (i) setw() (ii) sqrt() (b) Name the header files that shall be needed for the following code. char str*+= air force schools ; cout<<setw(20)<<str; (c) Write the names of the header files to which the following belong: (i) setw() (ii) toupper() (d) Write the names of the header files to which the following belong : (i) frexp() (ii) isalnum() (e) Name the header file required for the following functions: (i) sqrt() (ii) setw() (iii) pow() (iv)clrscr()
Find Out Errors 3. (a) Rewrite the following program after removing the syntactical errors (if any). #include <iostream.h> struct Pixels intcolor,style; voidshowpoint(pixels P) cout<<p.color,p.style<<endl; Pixels Point1=(5,3); ShowPoint(Point1); Pixels Point2=Point1; Color.Point1+=2; ShowPoint(Point2); (b) #include<iostream.h> int x, sum=0; cin<<n; for(x=1,x<100,x+=2) if x % 2 ==0 sum +=x; cout<< sum = >>sum; (c ) #include [iostream.h] class PAYITNOW int Charge; PUBLIC: void Raise()cin>>Charge; void Showcout<<Charge;
; PAYITNOW P; P.Raise(); Show(); (d ) #include<iostream.h> int x, sum=0; cin<<n; for(x=1,x<100,x+=2) if x % 2 ==0 sum +=x; cout<< sum = >>sum; (e ) #include<iostream.h> #define num=10 class MEMBER int Mno; float fees=0; PUBLIC: void Register()cin>>Mno>>fees; void Display()cout<<Mno<< : <<fees<<endl; ; 4. Find the outputs (a) Give the output of the following program #include<iostream.h> int a=3; void demo(int x,int y,int &z) a+= x+y ; z= a+y; y+=x; cout<<x<<y<<z<<endl; int a=2, b=5; demo(::a,a,b); cout<<::a<<a<<b<<endl; demo(::a,a,b); (b)write the output of the following program. # include <iostream.h> void execute (int &x, int y=200)
int temp = x + y; x += temp; if( y!=200) cout<<temp<<x<<y<<endl; int a=50, b=0; execute(b); cout<<a<<b<<endl; execute(a,b); cout<<a<<b<<end; (c) Find the output of the following program # include<iostream.h> struct play int score, bonus; ; void calculate ( play &p, int n=10) p.score ++ ; p.bonus +=n; play pl=10,15; 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; (d) #include <iostream.h> void Changethecontent(int Arr[], int Count) for (int C=1;C<Count;C++) Arr[C-1]+=Arr[C]; int A[]=3,4,5,B[]=10,20,30,40,C[]=900,1200; Changethecontent(A,3); Changethecontent(B,4); Changethecontent(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] << # ; (e) Find the output of the following program: #include <iostream.h>
struct Game char Magic[20];int Score; ; Game M= Tiger,500; char *Choice; Choice=M.Magic; Choice[4]= P ; Choice[2]= L ; M.Score+=50; cout<<m.magic<<m.score<<endl; Game N=M; N.Magic[0]= A ;N.Magic[3]= J ; N.Score-=120; cout<<n.magic<<n.score<<endl; (f) #include<iostream.h> void main( ) long NUM=1234543; int F=0,S=0; do int R=NUM % 10; if (R %2!= 0) F += R; else S += R; NUM / = 10; while (NUM>0); cout<<f-s; (g) Find the output of the following program. #include<iostream.h> #include<ctype.h> void Mycode(char Msg[],char ch) for(int cnt=0;msg[cnt]!='\0';cnt++) if(msg[cnt]>='b'&& Msg[cnt]<='G') Msg[cnt]=tolower(Msg[cnt]); else if(msg[cnt]=='a' Msg[cnt]=='a') Msg[cnt]=ch; else if(cnt%2==0) Msg[cnt]=toupper(Msg[cnt]); else Msg[cnt]=Msg[cnt-1]; char MyText[]="ApEACeDriVE"; Mycode(MyText,'@'); cout<<"new TEXT: "<<MyText<<" "<<endl;
(h) Find the output of the following program. #include<iostream.h> struct POINT int X, Y, Z; ; void StepIn( POINT & P, int Step = 1) P.X += Step; P.Y -= Step; P.Z += Step; void StepOut ( POINT & P, int Step = 1) P.X -= Step; P.Y += Step; P.Z -= Step; POINT P1 = 15, 25, 5, P2 = 10, 30, 20; StepIn(P1); StepOut(P2, 4); cout<<p1.x<<, <<P1.Y<<, <<P1.Z<<endl; cout<<p2.x<<, <<P2.Y<<, <<P2.Z<<endl; StepIn (P2, 12); cout<<p2.x<<, <<P2.Y<<, <<P2.Z<<endl; (i) Find the correct possible output(s) of the following program from the options given below. #include<iostream.h> #include<stdlib.h> randomize(); char color*+*10+=, RED, BLUE, PINK, BLACK -; int p; for( int i=1; i<=3; i++) p=random(2) +1; cout<<color*p+<< : ; Outputs: (i) BLUE:PINK:BLUE (ii) RED:BLUE:PINK (iii) BLUE:PINK:BLACK (iv) BLUE:PINK:PINK (j) Find the output of the following program. #include<iostream.h> #include<string.h> #include<ctype.h> void main ( )
char str[]= Good@luck10! ; for( int c=0; c<strlen(str); c++) if(islower(str[c])) str[c]=toupper(str[c]); else if(isupper(str[c])) str[c]=tolower(str[c]); else if(isdigit(str[c])) str[c]=str[c] + 1; else str[c]= * ; cout<<str; 5. Class Completion Questions: (a) Define a class STUDENT with following specifications private members rollno integer name character array of size 20 clas character array of size 5 marks integer array of size 5 per float // percentage calculate() // calculates overall percentage & returns the percentage public member/member functions readmark() to read the required input & invoke calculate() function displaymark() to display all details (b) Define a class in C++ with following description: Private Members A data member Flight number of type integer A data member Destination of type string A data member Distance of type float A data member Fuel of type float A member function CALFUEL() to calculate the value of Fuel as per the following criteria Distance Fuel <=1000 500 more than 1000 and <=2000 1100 more than 2000 2200 Public Members A function FEEDINFO() to allow user to enter values for Flight Number, Destination, Distance & call the function CALFUEL() to calculate the quantity of Fuel A function SHOWINFO() to allow user to view the content of all the data members
(c ) Define a class batsman with the following specifications: Private members: bcode bname 4 digits code number 20 characters innings, notout, runs integer type batavg, batavg =runs/(innings-notout) calcavg() Public members: readdata() it is calculated according to the formula Function to compute batavg Function to accept value from bcode, name, innings, notout and invoke the function calcavg() displaydata() Function to display the data members on the screen. (d ) Define a class Clothing in C++ with the following descriptions : Private members : Code of type string Type of type string Size of type integer Material of type string Price of type float A function CalcPrice() which calculates and assigns the value of Price as follows : For the value of Material as Cotton Type Price (Rs.) Trouser 1500 Shirt 1200 For material other than Cotton the above mentioned Price gets reduced by 15%. Public Members : A constructor to assign initial values of Code, Type and Material with the word NOT ASSIGNED and Size and Price with 0. A function Enter() to input the values of the data members Code, Type, Size and Material and invoke the CalcPrice() function. A function Show() which displays the content of all the data members of Clothing. 5. (a) What is the difference between get() and read(). (b) What is the difference between app and ate mode of opening a file. (c) Name two member functions of ofstream class. (except open and close) (d) What is the output if the file content before the execution of the program is the string ABC ( Note that are not part of the file) char ch= a ; fstream fileout( data.dat,ios::out); fileout<<ch; int p = fileout.tellg(); cout<<p;
(e) Consider the following class declaration: class employee int code; char name[20]; float salary; public: void input() cin>>code>>name>>salary; void show() cout<<code<<name<<salary; float retsal() return salary ; ; Give function definitions to do the following: (i)write the objects of employee to a binary file. (ii)read the objects of employee from the binary file and display all the objects on the screen whose salary is between Rs. 10000 and Rs. 20000. (f) Observe the program segment given below carefully and fill the blanks marked as Statement 1 and Statement 2 using seekg() and tellg() functions for performing the required task. #include <fstream.h> class Employee int Eno;char Ename[20]; public: //Function to count the total number of records int Countrec(); ; int Employee::Countrec() fstream File; File.open( EMP.DAT,ios::binary ios::in); //Statement 1 int Bytes = //Statement 2 int Count = Bytes / sizeof(employee); File.close(); return Count; (g) Write a function in C++ to count the words this and these present in a text file NOTES.TX (h) Write a function in C++ to add new objects at the bottom of a binary file STUDENT.DAT, assuming the binary file is containing the objects of the following class. class STUD int Rno; char Name[20]; public: void Enter()cin>>Rno;gets(Name); void Display()cout<<Rno<<Name<<endl; int Return_Rno() return Rno; ;
(i)write a function in C++ to delete an object from a binary file STUDENT.DAT, assuming the binary file is containing the objects of the class STUD whose definition is given in Q. 6(c). The Rno of the object to be deleted will be passed as an argument.