jueves, 5 de enero de 2012

C++ Clase entera simple con métodos para leer y escribir datos

//archivo centero.h
// Class automatically generated by Dev-C++ New Class wizard

#ifndef CENTERO_H
#define CENTERO_H



// No description
class cEntero
{
   
            int n;
    public:
        // class constructor
        cEntero();
        // class destructor
        ~cEntero();
        int obtenerEntero();
        void escribirEntero(int num);
};

#endif // CENTERO_H

//archivo centero.cpp
// Class automatically generated by Dev-C++ New Class wizard

#include "centero.h" // class's header file
// class constructor
cEntero::cEntero()
{
    // insert your code here
    n=0;
}

// class destructor
cEntero::~cEntero()
{
    // insert your code here
}

void cEntero::escribirEntero(int num)
{
    n=num;
}

int cEntero::obtenerEntero()
{
    return(n);
}
 
//archivo main.cpp
#include <cstdlib>
#include <iostream>
#include "centero.h"
using namespace std;

int main(int argc, char *argv[])
{
    cEntero e1;
    cEntero e2;
   
    e1.escribirEntero(3);
    e2.escribirEntero(4);
   
    cout << e1.obtenerEntero() << endl;
    cout << e2.obtenerEntero() << endl;
   
    system("PAUSE");
    return EXIT_SUCCESS;
}



No hay comentarios:

Publicar un comentario