Skip to main content

Assignment XII CS - CONSTRUCTORS & DESTRUCTORS


1. Differentiate between Constructor and Destructor function with respect to Object Oriented Programming.

2. List some of the special properties of the constructor functions.

3. What is a parameterized constructor? How is it useful?

4. What is a copy constructor? What ¡s its significance? Which situation is it invoked in? Support your answer with C++ code.

5. Differentiate between a default constructor and copy constructor, giving suitable examples of each.

6. Describe the importance of destructor. List some of the special properties of destructor.

7. Which of the following is used to identify the copy constructor class type X?
(i) (X&)           (ii) X(&X)           (iii) X(X&)                (iv) X(X)

Justify your answer.

8. Answer the questions (i) and (ii) after going through the following C++ class:

class Stream
{
int StreamCode ; char Streamname[20];float fees;
public:
Stream( ) //Function 1
{
StreamCode=1; strcpy (Streamname,"DELHI");
fees=1000;
}
void display(float C) //Function 2
{
cout<<StreamCode<<":"<<Streamname<<":"<<fees<<endl;
}
~Stream( ) //Function 3
{
cout<<"End of Stream Object"<<endl;
}
Stream (int SC,char S[ ],float F) ; //Function 4
};

i) In Object Oriented Programming, what are Function 1 and Function 4 combined together referred as? Write the definition of function 4.

ii) What is the difference between the following statements?
     Stream S(11,”Science”,8700);
     Stream S=Stream(11,”Science”,8700);

9. Define a class Customer with the following specifications.

Private Members :

Customer_no                          integer
Customer_name                     char (20)
Qty                                         integer
Price, TotalPrice, Discount, Netprice             float

Public members:

a). A constructor to assign initial values of Customer_no as 111,Customer_name as “Leena”, Quantity as 0 and Price, Discount and Netprice as 0.

b). Input( ) – to read data members(Customer_no, Customer_name, Quantity and Price) call Caldiscount().

c). Caldiscount ( ) – To calculate Discount according to TotalPrice and NetPrice
TotalPrice = Price*Qty

TotalPrice >=50000 – Discount 25% of TotalPrice

TotalPrice >=25000 and TotalPrice <50000 - Discount 15% of TotalPrice

TotalPrice <250000 - Discount 10% of TotalPrice

Netprice= TotalPrice-Discount

d). Show( ) – to display Customer details.

10. Answer the questions (i) and (ii),after going through the following class:

class test
{ char paper[20];
int marks;
public:
test() //function1
{ strcpy(paper,”computer”);
marks=0; }
test (char p[]) //function 2
{ strcpy(paper,p);
marks=0;}
test(int M) //function 3
{strcpy(paper,”computer”);
marks=M;}
test (char p[],int M) //function 4
{ strcpy(paper, P);
marks=M;}
};

(i) Which feature of object oriented programming is demonstrated using function1, function2, function3 and function4 in the above class test?

(ii) Write statements in C++ that would execute function 4 in the above class test?

11. Answer the questions (i) and (ii), after going through the following class:

class readbook
{
public:
Readbook() //function-1
{cout<<”open the book”<<endl;}
void readchapter() //function-2
{cout<<”reading chapter-1”<<endl;}
~readbook() //function-3
{cout<<”close the book”}
};

(i) In object oriented programming, what is function-1 referred as and when does it get invoked?
(ii) In object oriented programming, what is function -3 referred as and when does it get invoked?

12. Find the syntax errors if any, and write the error free code and also underline the corrections made.

class abc
{
int x=10;
Float y;
abc()
{
Y=5;
}
~(){ }
};
int main()
{
abc a1,a2;
return 0;
}

NOTE: You can take printout of questions and paste them in your copy.

Last Date of Submission of Assignment: 10/Aug/2015


Popular posts from this blog

Project Work for Class XII Informatics Practices (065) - CBSE 2020-2021

  Marks  allotted : 05 Marks A. PROJECT GUIDELINES The aim of the class project is to create tangible and useful IT application. The learner may identify a real-world problem by exploring the environment. e.g. Students can visit shops/business places, communities or other organizations in their localities and enquire about functioning of the organization, and how data are generated, stored, and managed. The learner can take data stored in csv or database file and analyze using Python libraries and generate appropriate charts to visualize. If an organization is maintaining data offline, then the learner should create a database using MySQL and store the data in tables. Data can be imported in Pandas for analysis and visualization. Learners can use Python libraries of their choice to develop software for their school or any other social good. Learners should avoid plagiarism and violation of copyright issues while working on projects. Any resources (data, image etc.) used in t...

Assignments - XII Computer Science

POINTERS ASSIGNMENT Assignment Date: 09/09/15 Submission Date: 14/09/15 Q1. What will be the output of the following program: int main() { int x [ ] = { 50, 40, 30, 20, 10}: int *p, *t; p = x; t = x + 1; cout << *p << “,” << *t++; return 0; } Q2. What will be the output of the program( Assume all necessary header files are included) void print (char * p ) { p = "Comp"; cout<<"value is "<<p<<endl; } int main( ) { char * x = "Class XII"; print(x); cout<<"new value is "<<x<<endl; return 0; } Q3. Identify errors on the following code segment, and underline the error. float c[ ] ={ 1.2,2.2,3.2,56.2}; float *k,*g; k=c; g=k+4; k=k*2; g=g/2; cout<<”*k=”<<*k<<”*g=”<<*g; Q4. Write the output of the following program. void print (char * p ) { p = "Comp"; cout<<"valu...