#include <iostream>
#include <string>
using namespace std;
class Fecha {
public:
Fecha(int d, int m, int a){
dia = d;
mes = m;
anio = a;
}
void mostrar_fecha() {
cout << "Dia: " << getdia() << endl;
cout << "Mes: " << getmes() << endl;
cout << "Año: " << getanio() << endl;
}
int getdia() {
return dia;
}
int getmes() {
return mes;
}
int getanio() {
return anio;
}
private:
int dia;
int mes;
int anio;
};
int main() {
Fecha obj(12,4,2020);
obj.mostrar_fecha();
return 0;
}
/*
En este codigo, la clase llamda fecha, tiene un constructor que inicializa los atributos de
tipo privado que son dia mes y año, un metodo que se encarga de mostrar la fecha, y los
metodos getter para acceder a los atributos privados.
en el main se crea la instancia de la clase fecha y se llama al metodo mostrar_fecha()
*/
To embed this project on your website, copy the following code and paste it into your website's HTML: