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

Classes.cpp

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

using namespace std;

class classa
    {
        private:
            int n, n0;
            float x, x0;
            string s, s0;
            
        public:
               
            void setint(int n);
            void setfloat(float x);
            void setstring(string s);
            
            int getint(){return n0;};
            float getfloat(){return x0;};
            string getstring(){return s0;};
    };
    
      void classa::setint (int n){ n0 = n;}   
      void classa::setfloat (float x){ x0 = x;}
      void classa::setstring (string s){ s0 = s;}


main()
{

      /* CREATE THE A0 CLASS FROM CLASSA */
      
      classa a0;
  
      /* SET THE INT, FLOAT, STRING VALUES */
      
      a0.setint(1);
      a0.setfloat(1.1);
      a0.setstring("alpha");
       
      /* PRINT THE INT, FLOAT, STRING VALUES */
      
      cout << "The Set Integer: " << a0.getint() << endl;
      cout << "The Set Float: " << a0.getfloat() << endl;
      cout << "The Set String: " << a0.getstring() << endl;
      
      /* PAUSE, THEN EXIT THE PROGRAM NORMALLY */
                
      getchar();
      return 0;                    
}