TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ALL
from: FRANK MASINGILL
date: 1997-05-12 11:41:00
subject: Creating workable subclasses

    Here is a simple program with only one main class to sum a couple of 
numbers.  I'm trying to learn about classes.
    ---------------------START HERE------------------------
//compute.cpp
#include 
class Compute
{
    private:
        int Num1, Num2;        //private data members
    public:
        Compute(int, int);       //constructor function
        ~Compute();              //destructor function
        int Sum(void);           //member function to compute sum
};
//Constructor function
Compute::Compute(int N1, int N2)
{
    Num1 = N1;
    Num2 = N2;
}
//Destructor function
Compute::~Compute()
{
}
int Compute::Sum()
{
    return Num1 + Num2;
}
//Main
main()
{
    Compute Answer(156,2347);        //declare a sum
    cout <<  Answer.Sum();           //compute and display sum
}
---------------------END HERE-----------------------
    This works.  Now what I would like to do is to modify it so as to
have a subclass ADD to get this same result and then a subclass SUBTRACT to 
subtract the same two numbers.  I think this will help me to understand the 
relationships and then I can use the pattern to extend to dividing and 
multiplication.
    Will somebody please show me how to set this up to subtract using this 
same class structure?
    Thanks in advance.
                            Sincerely,
                                            Frank
--- FMail/386 1.02
---------------
* Origin: Maybe in 5,000 years frankmas@juno.com (1:396/45.12)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.