Order Of Execution Of Constructor Analysis Information Technology Essay

When the architect is authentic in abject chic and it is a absence constructor, again there is no charge to ascertain architect in acquired class.

When the architect authentic in the abject chic in the parameterised, again the architect in acquired chic is additionally parameterised.

First the architect of the abject chic will be accomplished and again of acquired class.

The adjustment of beheading is aboriginal of all the architect of basic chic will be accomplished and again of abject chic and again at aftermost of the acquired class.

(b) Chic D is acquired from chic B. The chic D does not accommodate any abstracts associates of its own. Does the chic D crave constructors? If yes, why?

Answer: Yes , chic D requires architect alike if it doesn’t accommodate any abstracts affiliate of its own. Acquired chic architect is acclimated to accommodate the ethics to the abject chic constructor.

Example-

#include

Using namespace std;

class alpha

{

int p;

public:

alpha(int i)

{

p=i;

cout<<"alpha initializedn";

}

void show_p(void)

{

cout<<"p="<

}

};

class beta

{

float q;

public:

beta(float j)

{

q=j;

cout<<"beta initializedn";

}

void show_ q(void)

{

cout<<"q="<

}

};

class gamma: attainable beta , attainable alpha

{

int x,y;

public:

gamma(int a, float b, int c, int d):

alpha (a),beta(b)

{

x =c;

y =d;

cout<<"gamma initializedn";

}

viod show_xy(void)

{

cout<<"x="<

cout<<"y="<

}

};

int main( )

{

gamma g(5,10.75,20,30);

cout<<"n";

g.show_p( );

g.show_q( );

g.show_xy( );

getch( );

}

Question 2: We apperceive that a clandestine affiliate of a abject chic is not inheritable. Is it anyhow attainable for the altar of a acquired chic to admission the clandestine associates of the abject class? If yes, how? Remember the abject chic cannot be modified.

Answer: No, it is not attainable to admission the clandestine abstracts associates of the abject chic irrespective of whether the acquired chic has been affiliated about or privately.For example, in the afterward affairs the acknowledgment for accessing the clandestine abstracts associates of the abject chic by the attainable associates of the acquired chic is invalid:

CASE 1: A acquired chic with clandestine derivation.

class baseA{

private:

int value;

};

class acquired : clandestine baseA{

public:

void f()

{

++value;

};

};

CASE 2: Alike if the acquired chic has been acquired about from the abject class, the attainable associates of the acquired chic cannot admission the clandestine affiliate of the abject class.

class baseA{

private:

int value;

};

class derivedB : attainable baseA{

public:

void F(){

++value;

};

};

A acquired chic attainable affiliate action cannot admission the clandestine affiliate of a abject chic irrespective of whether the acquired chic has been acquired about or privately.The aloft affairs shows an absurdity bulletin advertence that baseA :: amount is not accessible.

Question 3: Assume that a publishing aggregation prints books and agenda books(electronic form-CD). Create a chic alleged advertisement with abstracts associates title, price, and author’s name. From advertisement class, acquire two classes alleged book and ebook. Te book chic adds a folio calculation abstracts affiliate alleged pcount while ebook adds abstracts affiliate arena time name ptime. Each of these classes charge accept affiliate action getdata( ) to apprehend chic specific abstracts from keyboard and displaydata( ) to achievement the chic specific abstracts to the computer screen.

Answer .

#include

#include

class publication

{

Char title[50], author_name[50];

Float price;

public:

void getdata( )

{

cout<<"enter the book title, name of columnist and amount of book"<

cin>>title>>author_name>>price;

}

void display( )

{

cout<<" Appellation "<<"t"<<"author"<<"t"<<"price"<

cout<

}

};

class book : attainable publication

{

int pcount;

public:

void getdata( )

{

cout<<"enter the no. of pages"<

cin>>pcount;

}

void display( )

{

cout<<"number of pages is : "<

}

};

class ebook : attainable publication

{

float ptime;

public:

void getdata( )

{

cout<<"enter the arena time"<

cin>>ptime;

}

void display( )

{

cout<<" arena time is : "<

}

};

void main( )

{

clrscr( );

publication p;

book b;

ebook e;

p.getdata();

p.display();

b.getdata();

b.display();

e.getdata();

e.display();

getch();

}

PART-B

Question 4:

(a) How is polymorphism accomplished at (a) abridge time (b) run time?

Answer: Polymorphism is the action of defining a cardinal of altar of altered classes into a accumulation and calls the methods to backpack out the operation of the altar application altered action calls.

Polymorphism can be accomplished in two means one at abridge time and additional at run time.

Polymorphism

Compile time:

Function overloading, abettor overloading

Run time:

virtual functions

Compile time polymorphism:-

This advice is accepted to the compiler at abridge time at that time the compiler is able to baddest the adapted action for a accurate call. This polymorphism uses active operators and affiliate functions. This polymorphism is accomplished at abridge time.

Run time polymorphism:-

When it is accepted what altar are beneath application at run time and the adapted action is invoked. Since the action is affiliated with a accurate chic abundant afterwards after the compilation, this action is alleged run time polymorphism.Run time polymorphism is accomplished by application basic functions and it is accomplished while the affairs is running.

(b) How does the abstraction of basic action advice in accomplishing polymorphism?

Illustrate your by giving a acceptable example.

Answer: This can be illustrated as follows:-

#include

#include

class baseA

{

public:

virtual abandoned display( )

{

cout<<"one n";

}

};

class derivedB : attainable baseA

{

public:

virtual abandoned display( )

{

cout<<"two n";

}

};

class derivedC : attainable baseA

{

public:

virtual abandoned display( )

{

cout<<"three n";

}

};

void main( )

{

baseA obja;

derivedB objb;

derivedC objc;

baseA *ptr[3];

ptr[0]=&obja

ptr[1]=&objb

ptr[2]=&objc

for (int i=0;i<=2;i++)

ptr[i]->display( );

getch();

}

Question 5: When do we accomplish a basic action “pure”? What are the implications of authoritative a action a authentic basic function?

Answer : A authentic basic action or authentic basic adjustment is a basic action that is adapted to be implemented by a acquired chic that is not abstract. Classes absolute authentic basic methods are termed “abstract;” they cannot be instantiated directly, and a bracket of an abstruse chic can alone be instantiated anon if all affiliated authentic basic methods accept been implemented by that chic or a ancestor class.

Although authentic basic methods about accept no accomplishing in the chic that declares them, authentic basic methods in C++ are acceptable to accommodate an accomplishing in their declaring class, accouterment fallback or absence behaviour that a acquired chic can agent to if appropriate.

Pure basic functions are additionally acclimated area the adjustment declarations are actuality acclimated to ascertain an interface for which acquired classes will accumulation all implementations. An abstruse chic confined as an interface contains alone authentic basic functions, and no abstracts associates or accustomed methods. Use of absolutely abstruse classes as interfaces works in C++ as it supports assorted inheritance.

Question 6: Develop an article aggressive affairs in C++ to apprehend the afterward advice from the keyword in which the abject chic consists of agent name, cipher and designation, and the acquired chic absolute the abstracts members, viz. years of acquaintance and age.

Employee name

Employee code

Designation

Years of experience

Age

Design a basic abject chic for the account agent name and code.

Answer :

#include

#include

class A

{

Char name[20],designation[50];

int code;

public:

void get()

{

cout<<"enter name of the employee";

cin>>name;

cout<<"enter appellation of the employee";

cin>>designation;

cout<<"enter cipher of the empsloyee";

cin>>code;

}

void show()

{

cout<<"name of the agent is:"<

cout<<"designation of the agent is:"<

cout<<"code of the agent is:"<

}

};

class B:virtual attainable A

{

int experience,age;

public:

void gets()

{

cout<<"enter age of acquaintance of the employee";

cin>>experience;

cout<<"enter age of the employee";

cin>>age;

}

void put()

{

cout<<"age of acquaintance is:"<

cout<<"age is:"<

}

};

void main()

{

clrscr();

A a;

B b;

a.get();

a.show();

b.gets();

b.put();

getch();

}

………….

Cite This Work

To export a reference to this article please select a referencing stye below:

Reference Copied to Clipboard.
Reference Copied to Clipboard.
Reference Copied to Clipboard.
Reference Copied to Clipboard.
Reference Copied to Clipboard.
Reference Copied to Clipboard.
Reference Copied to Clipboard.

Order a Unique Copy of this Paper