TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: KURT KUZBA
from: FRANK MASINGILL
date: 1997-09-04 04:46:00
subject: Worked this out

   Kurt and Cliff and Jerry, I worked this out just by looking at patterns 
nd
I think some of it is beginning to sink in.  It seems like beating a dead
horse to you fellows but for me, I think I'm edging forward.  Maybe this will
help some other novice trying to learn classes.  Fortunately, I don't mind
being laughed at!!
   Criticize away if you have time and inclination.
----------------------------START HERE-----------------------------
// Example of a class with only one data item.
// but the data item can be used in as many objects as you create
#include 
#include 
class templatex            // no objects created this is only a pattern
{
   private:
      int dataTemp1;        // private data is going to be an int
      int dataTemp2;        // private data is going to be an int also
      int dataTempSum;
   public:
      void setupData(int x,int y, int z) // define & init data member 
unction
      {
         dataTemp1 = x;
         dataTemp2 = y;
         z = x+y;
         dataTempSum = z;
      }
      void showData()         // member function to display the data
      {
         //display with iostream
         cout << dataTemp1 << "+" << dataTemp2 << "=" << dataTempSum
              << endl;
      }
};
void main()
{
   templatex a,b,c;         // create three objects of class templatex
   int d;
   a.setupData(24,38,d);      // place data into a.setupData member function
   b.setupData(25,39,d);      // place data into b.setupData member function
   c.setupData(26,40,d);      // place data into c.setupData member function
   clrscr();                // clear the screen
   cout << "Now add the two data items in each of the three objects\n";
   cout << "and show the sum of each addition of the two addends\n";
   a.showData();            // display the data in a  using showData function
   b.showData();            // display the data in b    "     "        "
   c.showData();            // display the data in c    "     "        "
}
--------------------------------END HERE------------------------------
Sincerely, 
                                     Frank
                                                                              
                                                       
--- PPoint 2.03
---------------
* 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™.