TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: CLIFF RHODES
from: FRANK MASINGILL
date: 1997-05-13 07:23:00
subject: Creating workable subcla

 > Frank, you do not need subclasses. You should add member
 > functions
 > Add() and Subtract(). Their form would look exactly like your
 > Sum()
 > member.
    O.K., Cliff, I am not surprised to hear that because I was really just 
looking for some understandable way to approach teaching myself about classes 
and sub-classes but that can come along.
    Anyhow using your valued advice, I came up with the following:
-------------------------START HERE---------------------
//Calc.cpp
#include 
#include 
class Calc
{
    private:
        int Num1, Num2;        //private data members
    public:
        Calc(int, int);       //constructor function
        Calc(float,float);
        int Add(void);        //member function to compute sum
        int Subtract(void);   //member function to compute difference
        int Multiply(void);   //member function to compute product
        float Divide(void);     //member function to compute quotient
};
//Constructor function
Calc::Calc(int N1, int N2 )
{
    Num1 = N1;
    Num2 = N2;
}
Calc::Calc(float N1, float N2)
{
    Num1 = N1;
    Num2 = N2;
}
int Calc::Add()   { return Num1 + Num2; }
int Calc::Subtract()  { return Num1 - Num2; }
int Calc::Multiply() { return Num1 * Num2; }
float Calc::Divide() { return  Num1 / Num2; }
main()
{
    clrscr();
    Calc AddAnswer(156,23);
    cout << "\n"  << AddAnswer.Add();            //compute and display sum
    Calc SubAnswer(156,23);
    cout << "\n"  << SubAnswer.Subtract();       //compute and declare 
difference
    Calc MulAnswer(156,23);
    cout << "\n"  << MulAnswer.Multiply();       //compute and display 
roduct
    Calc DivAnswer(156,23);
    cout << "\n"  << DivAnswer.Divide();         //compute and display 
quotient
    return 0;
}
--------------------------END HERE-------------------------------
    Can you imagine (grin) the courage required to show one's ignorance all 
over the place??
    Anyhow, the above "works" even if it has technical flaws but you will 
notice that I was endeavoring, without success, to "fix" the problem that the 
DIVISION process needs floats rather than ints if THAT answer is to be 
accurate.  I, apparently, didn't gain anything by separating the Calc 
variable into four different variables.
    Your critique and that of anybody else who reads will be appreciated.  
Did I make ANY progress?
                            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™.