Top Banner
Subject:Computer Home work No. Questions Marks 1. (a) (b) (c) (d) What is the difference between Actual Parameter and Formal Parameters? Also, give a suitable C++ code to illustrate both Write the names of the header files to which the following belong: (i) frexp() (ii) isalnum() Rewrite the following program after removing the syntactical errors (if any). Underline each correction. #include <iostream.h> struct Pixels { int Color,Style;} void ShowPoint(Pixels P) { cout<<P.Color,P.Style<<endl;} void main() { Pixels Point1=(5,3); ShowPoint(Point1); Pixels Point2=Point1; Color.Point1+=2; ShowPoint(Point2); } Find the output of the following program: 2 1 2 3 1 HOLIDAY HOMEWORK CLASS-XII SUBJECT COMPUTER SCIENCE
13

€¦  · Web viewi)Which category of constructor - Function 4 belongs to and what is the purpose of using it?

Jun 28, 2019

Download

Documents

doankiet
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: €¦  · Web viewi)Which category of constructor - Function 4 belongs to and what is the purpose of using it?

Subject:Computer Home work

No. Questions Marks

1.

(a)

(b)

(c)

(d)

What is the difference between Actual Parameter and Formal Parameters? Also, give a suitable C++ code to illustrate both

Write the names of the header files to which the following belong:

(i) frexp() (ii) isalnum()

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

#include <iostream.h>

struct Pixels

{ int Color,Style;}

void ShowPoint(Pixels P)

{ cout<<P.Color,P.Style<<endl;}

void main()

{

Pixels Point1=(5,3);

ShowPoint(Point1);

Pixels Point2=Point1;

Color.Point1+=2;

ShowPoint(Point2);

}

Find the output of the following program:

#include <iostream.h>

void Changethecontent(int Arr[ ], int Count)

{

for (int C=1;C<Count;C++)

2

1

2

3

1

HOLIDAY HOMEWORK

CLASS-XII SUBJECT COMPUTER SCIENCE

Page 2: €¦  · Web viewi)Which category of constructor - Function 4 belongs to and what is the purpose of using it?

No. Questions Marks

(e)

Arr[C-1]+=Arr[C];

}

void main()

{

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

}

Find the output of the following program:

#include <iostream.h>

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<<M.Magic<<M.Score<<endl;

2

2

Page 3: €¦  · Web viewi)Which category of constructor - Function 4 belongs to and what is the purpose of using it?

No. Questions Marks

(f)

2.

(a)

(b)

Game N=M;

N.Magic[0]='A';N.Magic[3]='J';

N.Score-=120;

cout<<N.Magic<<N.Score<<endl;

}

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?

#include <iostream.h>

#include <stdlib.h>

void main()

{

int N,Guessnum;

randomize();

cin>>N;

Guessnum=random(N-10)+10;

cout<<Guessnum<<endl;

}

What do you understand by Polymorphism? Give a suitable example of the same.

Answer the questions (i) and (ii) after going through the following program:

class Match

{

int Time;

public:

Match() //Function 1

{

Time=0;

cout<<"Match commences"<<end1;

2

2

2

3

Page 4: €¦  · Web viewi)Which category of constructor - Function 4 belongs to and what is the purpose of using it?

No. Questions Marks

(c)

}

void Details() //Function 2

{

cout<<"Inter Section Basketball Match"<<end1;

}

Match(int Duration) //Function 3

{

Time=Duration;

cout<<"Another Match begins now"<<end1;

}

Match(Match &M) //Function 4

{

Time=M.Duration;

cout<<"Like Previous Match "<<end1;

} };

i) Which category of constructor - Function 4 belongs to and what is the purpose of using it?

ii) Write statements that would call the member Functions 1 and 3

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

4

4

Page 5: €¦  · Web viewi)Which category of constructor - Function 4 belongs to and what is the purpose of using it?

No. Questions Marks

more than 2000 2200

Public Members

" A function FEEDINFO() to allow user to enter values for Flight Number, Destination, Distance & call function CALFUEL() to calculate the quantity of Fuel

" A function SHOWINFO() to allow user to view the content of all the data members

……………X…………..X……………..X………………….

Page 6: €¦  · Web viewi)Which category of constructor - Function 4 belongs to and what is the purpose of using it?

Q1.

a. What is Inheritance? Give an example. 1

b. Write the names of the header files to which the following belong: 2

i) sqrt() ii) isalpha iii) puts() iv)strcpy()

c. Rewrite the corrected code for the following program .Underline each correction

(if any) 2

# include<iostream.h>

Structure Swimmingclub

{

int memnumber;

char memname[20];

char memtype[ ] = “LIG”;

};

void main( )

{

Swimmingclub per1,per2;

cin>>”Member number”;

cin >>memnumber.per1:”;

cout<< “ Member name:”;

cin>>per1. Member name;

per1.memtype=”HIG”;

Page 7: €¦  · Web viewi)Which category of constructor - Function 4 belongs to and what is the purpose of using it?

per2=per1;

cin>> “Member number: “<<per2.memnumber:”;

cin>>”Member name:”<<”per2.memname;

cin>>” Member number :”<< per2.memtype:”;

}

d. What will be the output of the following program: 1

# include <iostream.h>

# include<ctype.h>

# include<conio.h>

# include< string.h>

void Newtext(char String[ ], int &Position)

{

char *pointer = String;

int Length =strlen(String);

for(; Position<Length-2;Position+=2;

{

*(Pointer Position)=toupper(*(Pointer Position));

}

}

e. What will be the output of the following program:1

#include<iostream.h>

void main( )

Page 8: €¦  · Web viewi)Which category of constructor - Function 4 belongs to and what is the purpose of using it?

{ clrscr( );

int v1=5, v2=10;

for(int x =1; x<=2; x++)

{

cout<<” ++ v1<<”\t”<<v2 -- <<endl;

cout<< “ - - v2<<”\t” <<v1++<<endl;

}

}

f. Write the definition for a function Sumseries ( ) in c++ with two 4

Arguments/parameters double x and int n .The function should return a value

of type double and it should perform sum of the following series.

x- x2 /3!+ x3 /5!- x4/ 71+x5/9!-……..n.

Q2. a. Given the following C++ code answer the questions (i) to (ii).2

class TestMeOut

{

Public:

~ TestMeOut( ) //Function 1

{ cout<<” Leaving the examination hall:”<<endl;}

TestMeOut () // Function2

cout<< appearing for the examination :”<<endl;}

void MyWork( ) // Function3

{ cout<,” Attempting the Question:”; }

};

Page 9: €¦  · Web viewi)Which category of constructor - Function 4 belongs to and what is the purpose of using it?

i. In object Oriented programming what is Function 1 referred as and when does it get

invoked / called?

ii. In OOP’s what is Function 2 referred as and when does it get invoked / called?

b. Define a class TravelPlan in C++ with the following descriptions: 4Private Members:

PlanCode of type longPlace of type character array (string)Number of travellers of type integerNumber_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 1A function NewPlan( ) which allows user to enter PlanCode, Place andNumber_of_travellers. Also, assign the value of Number_of_buses as per the

Following conditions:Number_of_travellers Number_of_busesLess than 20 1Equal to or more than 20 and less than 40 2Equal to 40 or more than 40 3A function ShowPlan ( ) to display the content of all the data members on screen.

c. Define the term Data Hiding in the context of Object Oriented Programming. Give a suitable example using a C++ code to illustrate the same.

2

1.(a) What are the differences between a data type struct and a data type class in c++ ? 2(b) Write the names of header files, which are NOT necessary to run the following program:

1 #include <iostream.h>#include <stdio.h> #include <string.h> #include <math.h>

void main(){

Page 10: €¦  · Web viewi)Which category of constructor - Function 4 belongs to and what is the purpose of using it?

char STR[80]; gets(STR); puts(strrev(STR));

}(c) Gunjan has just started working as programmer in the ZEE WORLD SOFTWARE company. In the company, he has got his first assignment to develop a small C++ module to find the biggest number out of a given set of numbers stored in a one dimensional array. Somehow he has committed a few logical mistakes while writing this code and so he is not getting the desired result from the code. Find out the mistakes and correct this C++ code so that it provides the desired result (do not add any new statement in the code). Underline each correction made: 2

int BIGFIND(int ARR[],int Size){

int BIG=ARR[1]; //Statement 1for (int C=2;C<Size;C++) //Statement 2

if (ARR[C]<BIG) //Statement 3ARR[C]=BIG; //Statement 4

return BIG; //Statement 5}

(d) Observe the following program & Find out the correct possible outputs from the options .( Assuming that all required header files are included in the program) 2

void main(){

char serial[ ] = {‘E’, ‘X’,’A’,’M’};int number [ ]= { 69,66,67,68};

randomize();cout<<number[random(3)];

for( int i=0;i<4;i++)cout<<serial[sizeof(int) + random(2)-1];

}(i) 67XXAX (ii) 69AXXA (iii) 66AAXA (iv) 67AAAM

Page 11: €¦  · Web viewi)Which category of constructor - Function 4 belongs to and what is the purpose of using it?

(e) Find the output of the following program segment ( Assuming that all required header files are included in the program 2 void main()

{char *text[2]={“TWO”, “SIX”}; for(int c=0;c<2;c++){

for(int d=0;d<strlen(text[0]);d++) if(islower(text[c][d]))

cout<<(char) toupper(text[c][d]); else if(isupper(text[c][d]) &&(d%2==0))

cout<<(char) tolower(text[c][d]); else text[c][d] ;

cout<<d <<endl ;}

}(f) Find the output of the following program segment ( Assuming that all required header files are included in the

program 2 void main()

{char Text[ ]=”TALenT@orG”; for(int

i=0;Text[i]!=’\0’;i++){ if(!isalpha(Text[i]))

Text[i]=’*’;else if(!isupper(Text[i])) Text[i]=Text[i]

+1;else Text[i]=Text[i+1];

}cout<<Text ;

}

2(a). What is the importance of constructor in OOP ? Explain it with example . 2

(b) Define a class MARKER with the following specifications : 4Private members: product_code character(6) , brand_name character(15) Price float ,

Product_type character(L-long , S-short) , category character(20)Public members: A constructor to assign initial values of product_code as ST200, brand_name

as “SONY” , product_type as ‘L’ and price as 10000 .Another constructor which takes initial values as parameters and assigns them to the respective member data .A function det() which calculates category of the product based on the following calculations :

Price category<10000 Economy>=10000 but <30000 Elegent>=30000 Luxury

(c) Consider the following class counter: 3class counter{ protected : unsigned int count;public : counter()

{ count = 0; }void inc_count(){ count++; }

int get_count(){ return count; }

};

Write code in C++ to publically derive another class new_counter from class counter. Class new_counter should have the following additional function members in the public visibility mode:

Page 12: €¦  · Web viewi)Which category of constructor - Function 4 belongs to and what is the purpose of using it?

(i) A parameterized constructor to initialize the value of count to the value of parameter. (ii) dec_count() to decrease the value of data member count by 1. (iii) Reset() to set the value of data member count to 0.

Sub:-physics Holiday Home work