Jump to content

C++ Inheritance help!?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
rossen

rossen

    Newbie

  • Members
  • Pip
  • 4 posts
can anyone make a C++ program with the use of inheritance?

and with the use of this formula:

P=I/T

thanks,
-----------------------------------------
Girly Myspace Layouts become a vegetarian

#2
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
A very simple example, showing how "Derived" inherits the functionality from "Base".
#include <iostream>

class Base
{
    public:
        void basefunction() { std::cout << "In Base" << std::endl; }
};

class Derived : public Base
{
    public:
        void derivedfunction() { std::cout << "In Derived" << std::endl; }
};

int main()
{
    Base b;
    Derived d;
    
    b.basefunction();
    d.basefunction();
    d.derivedfunction();
        
    return 0;
}
I don't know what you mean by that formula, could you be more specific?

#3
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts

v0id said:

A very simple example, showing how "Derived" inherits the functionality from "Base".

#include <iostream>


class Base

{

    public:

        void basefunction() { std::cout << "In Base" << std::endl; }

};


class Derived : public Base

{

    public:

        void derivedfunction() { std::cout << "In Derived" << std::endl; }

};


int main()

{

    Base b;

    Derived d;

    

    b.basefunction();

    d.basefunction();

    d.derivedfunction();

        

    return 0;

}

I don't know what you mean by that formula, could you be more specific?

I think he meant, a formula, P must be effect and I ampere and T is for time. Thats my guess, which would be likely he wants to enter two numbers and divide them. As I see your small code, its good and will work if he could work on the rest with it :P
Posted Image

#4
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
He can easily implement a member function:
int CalculateP(int I, int T)
{
    return I/T;
}


#5
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts

v0id said:

He can easily implement a member function:

int CalculateP(int I, int T)

{

    return I/T;

}



Wonderful, now he should be able to do the rest I guess xD
Posted Image

#6
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
What's this doing in the C# forum?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#7
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
Wow, I didn't even notice that.

It has been fixed now. Thank you for letting us know.

#8
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Welcome. :)
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums