POJ C + + programming programming task-polymorphism and virtual functions

Source: Internet
Author: User

Programming Questions #3

Source: POJ (Coursera statement: The exercises completed on POJ will not count against the final results of Coursera. )

Note: Total time limit: 1000ms memory limit: 65536kB

Describe

The following program outputs the result:

A::fun

A::D o

A::fun

C::D o

Please fill in the blanks:

#include <iostream>using namespace Std;class A {    private:        int nval;    Public:        void Fun ()        {cout << "a::fun" << Endl;}        virtual void do ()        {cout << "A::D o" << Endl;}; Class B:public A {public    :        virtual void do ()        {cout << "B::D o" << Endl;}}; Class C:public B {public    :        void Do ()        {cout << "C::D o" << Endl;}        void Fun ()        {cout << "c::fun" << Endl;}}; void call (//Add your code here        ) {    p->fun (); P->do ();} int main () {call    (new A ());    Call (new C ());    return 0;}
Input

No

Output

A::fun

A::D o

A::fun

C::D o

Sample input
No
Sample output
A::funa::D oa::func::D o
#include <iostream>
using namespace Std;
Class A {
Private
int nval;
Public
void Fun ()
{cout << "a::fun" << Endl;}
virtual void do ()
{cout << "A::D o" << Endl;}
};
Class B:public A {
Public
virtual void do ()
{cout << "B::D o" << Endl;}
};
Class C:public B {
Public
void Do ()
{cout << "C::D o" << Endl;}
void Fun ()
{cout << "c::fun" << Endl;}
};
void Call (
Add your code here
A *p
) {
P->fun (); P->do ();
}
int main () {
Call (new A ());
Call (new C ());
return 0;
}

POJ C + + programming programming task-polymorphism and virtual functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.