DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

MemberFunc.cpp

02.01.2008
| 986 views |
  • submit to reddit
        #include <iostream>
#include <string.h>
#include <windows.h>

using namespace std;

class classa
{
      private:
              float y,y0;
              
      public:
             void sety(float y);
             float gety(){return y0;};    
};

             void classa::sety (float y){y0 = y;};


class computer
{
      private:
              string os, machineOS;
              float speed, machinespeed;
              int memory, machinememory;
              bool bluetooth, machineBT;
              string color, machinecolor;
              
      public:
             void setos(string os);
             void setspeed(float speed);
             void setmemory(int memory);
             void setbluetooth(bool bluetooth);
             void setcolor(string color);
             
             string getos(){return machineOS;};
             float getspeed(){return machinespeed;};
             int getmemory(){return machinememory;};
             bool getbluetooth(){return machineBT;};
             string getcolor(){return machinecolor;};
};

             void computer::setos(string os){machineOS = os;};
             void computer::setspeed(float speed){machinespeed = speed;};
             void computer::setmemory(int memory){machinememory = memory;};
             void computer::setbluetooth(bool bluetooth){machineBT = bluetooth;};
             void computer::setcolor(string color){machinecolor = color;};
  
main()
{
      
/* INHERITANCE: PART I */

    int i;
    char tmp[100];
    cout << endl;
    char ar[] = "-[ OK ]- TESTING: We Set the Y-Value using Inheritance ";
    strncpy(tmp,ar,100);
    for(i=0;i<strlen(ar);i++)
    {
        cout << ar[i];
        Sleep(20);
    }
      
      classa b0;
      b0.sety(1.2);
      
      cout << endl;
      cout << "-[ OK ]- The (newly) created Y-value is: " << b0.gety() << endl;
      cout << "-[ OK ]- It worked! Now, please press [ENTER] to continue ..." << endl;
      getchar();
      
/* INHERITANCE: PART II */

      // CREATE NEW COMPUTERS FROM THE GENERIC COMPUTER SKELETON CLASS
      
      computer mainframe;
      computer macintosh;
      computer pc;
      
      // INITIALIZE THE SPECIFICATIONS FOR THE MAINFRAME COMPUTER
      
      mainframe.setos("IBM ESA/390");
      mainframe.setspeed(1.0);
      mainframe.setmemory(512);
      mainframe.setbluetooth(FALSE);
      mainframe.setcolor("BLACK");
      
      // INITIALIZE THE SPECIFICATIONS FOR THE MACINTOSH COMPUTER
      
      macintosh.setos("MacOSX 10");
      macintosh.setspeed(3.0);
      macintosh.setmemory(4);
      macintosh.setbluetooth(FALSE);
      macintosh.setcolor("BLUE");
      
      // INITIALIZE THE SPECIFICATIONS FOR THE PC COMPUTER
      
      pc.setos("Microsoft Windows XP-SP3");
      pc.setspeed(2.0);
      pc.setmemory(2);
      pc.setbluetooth(TRUE);
      pc.setcolor("SILVER");

      // START PRINTING THE SPECIFICATIONS FOR EACH GIVEN COMPUTER
      cout << endl << "-[ OK ]- Now, we will get/print the SPECs of the Computers" << endl << endl;
      
      cout << "\t" << "The MAINFRAME computer " << endl;
      cout << "\t" << "---------------------- " << endl;
      cout << "\t" << "OS        : " << mainframe.getos() << endl;
      cout << "\t" << "Color     : " << mainframe.getcolor() << endl;
      cout << "\t" << "Speed     : " << mainframe.getspeed() << "GHz" << endl;
      cout << "\t" << "Memory    : " << mainframe.getmemory() << "MB" << endl;
      cout << "\t" << "Bluetooth : " << mainframe.getbluetooth() << endl << endl;

      cout << "\t" << "The MACINTOSH computer has: " << endl;
      cout << "\t" << "---------------------- " << endl;
      cout << "\t" << "OS        : " << macintosh.getos() << endl;
      cout << "\t" << "Color     : " << macintosh.getcolor() << endl;
      cout << "\t" << "Speed     : " << macintosh.getspeed() << "GHz" << endl;
      cout << "\t" << "Memory    : " << macintosh.getmemory() << "GB" << endl;
      cout << "\t" << "Bluetooth : " << macintosh.getbluetooth() << endl << endl;
      
      cout << "\t" << "The PC computer has: " << endl;
      cout << "\t" << "---------------------- " << endl;
      cout << "\t" << "OS        : " << pc.getos() << endl;
      cout << "\t" << "Color     : " << pc.getcolor() << endl;
      cout << "\t" << "Speed     : " << pc.getspeed() << "GHz" << endl;
      cout << "\t" << "Memory    : " << pc.getmemory() << "GB" << endl;
      cout << "\t" << "Bluetooth : " << pc.getbluetooth() << endl << endl;
      
      cout << "-[ OK ]- Now, Pick the system you'd like to BUY among the (3) Options" << endl;
      cout << "         The Value Must be between 1-3. Otherwise, the choice will not be recognized." << endl;
      int Choice;
      cin >> Choice;
         switch (Choice)
         {
         case 1: cout << "We do NOT have such systems anymore in our inventory"; getchar(); break;
         case 2: cout << "How about FreeBSD? Rumor has it that it is stable!"; getchar(); break;
         case 3: cout << "The Total is $5,000. Have a great day, come again!"; getchar(); break;
         default:       
              cout << "Sorry, '" << Choice << "' does not correspond to a valid Choice. Nice try!\n\n";
              getchar();
         }
         
      getchar();
      return 0;
}