Over a million developers have joined DZone.

Classes.cpp

·
#include 
#include 

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;                    
}
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}