diff --git a/Makefile b/Makefile index e6982e1..a183c89 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,3 @@ -# =============================== -# Makefile para proyecto con Fecha -# =============================== - # --- Configuración general --- CXX = g++ CXXFLAGS = -Wall -Wextra -std=c++17 -Iinclude @@ -31,11 +27,11 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp # --- Limpieza --- clean: rm -rf $(OBJ_DIR)/*.o - @echo "🧹 Archivos objeto eliminados." + @echo "Archivos objeto eliminados." mrproper: clean rm -rf $(BIN_DIR)/* - @echo "🧹 Ejecutables eliminados." + @echo "Ejecutables eliminados." # --- Ejecución rápida --- run: all diff --git a/bin/programa b/bin/programa index 789f224..2ccd7f1 100755 Binary files a/bin/programa and b/bin/programa differ diff --git a/include/Cliente.h b/include/Cliente.h index 9365006..6608169 100644 --- a/include/Cliente.h +++ b/include/Cliente.h @@ -11,7 +11,7 @@ class Cliente { char *nombre; Fecha fechaAlta; public: - Cliente(long int d, char *nom, Fecha f); + Cliente(long int d, const char *nom, Fecha f); virtual ~Cliente(); Cliente& operator=(const Cliente& c); @@ -19,10 +19,10 @@ public: const char* getNombre() const { return nombre; } //VIP devolver un puntero constante para evitar que desde el main() se puede modificar el nombre Fecha getFecha() const { return fechaAlta; } - void setNombre(char *nom); + void setNombre(const char *nom); void setFecha(Fecha f); - bool operator==(Cliente c) const; // if (c1 ===c2) + bool operator==(const Cliente& c) const; // if (c1 ===c2) }; diff --git a/include/Fecha.h b/include/Fecha.h index 4a904aa..2f09f6b 100644 --- a/include/Fecha.h +++ b/include/Fecha.h @@ -23,6 +23,7 @@ public: Fecha operator+(const int &i) const; //f+5 friend Fecha operator+(const int &i, const Fecha &f); //const por seguridad y & por velocidad + friend ostream& operator<<(ostream& os, const Fecha& f); }; Fecha operator+(const int &i, const Fecha &f); //const por seguridad y & por velocidad diff --git a/obj/Cliente.o b/obj/Cliente.o index c15ff29..93d8e1b 100644 Binary files a/obj/Cliente.o and b/obj/Cliente.o differ diff --git a/obj/Fecha.o b/obj/Fecha.o index 1b409ba..93d78ee 100644 Binary files a/obj/Fecha.o and b/obj/Fecha.o differ diff --git a/obj/main.o b/obj/main.o index 95589c7..e1f2538 100644 Binary files a/obj/main.o and b/obj/main.o differ diff --git a/src/Cliente.cpp b/src/Cliente.cpp index 1fdf50a..62f17f0 100644 --- a/src/Cliente.cpp +++ b/src/Cliente.cpp @@ -5,7 +5,7 @@ #include "Cliente.h" //Cliente::Cliente(long int d, char *nom, Fecha f):fechaAlta(f.getDia(), f.getMes(), f.getAnio()) { -Cliente::Cliente(long int d, char *nom, Fecha f):fechaAlta(f) { //esta cabecera es mas corta (invoco +Cliente::Cliente(long int d,const char *nom, Fecha f):fechaAlta(f) { //esta cabecera es mas corta (invoco this->dni=d; //constructor copia de fecha //en vez de constructor de 3 parametros) //this->nombre=nombre; //MAL!!!! @@ -31,7 +31,7 @@ Cliente& Cliente::operator=(const Cliente& c) { return *this; } -bool Cliente::operator==(Cliente c) const { +bool Cliente::operator==(const Cliente& c) const { if (this->dni!=c.dni) return false; if (strcmp(this->nombre, c.nombre)!=0) return false; if (this->fechaAlta.getDia()!=c.fechaAlta.getDia() || @@ -40,4 +40,19 @@ bool Cliente::operator==(Cliente c) const { return true; } -//RESTO DE METODOS Y FUNCIONES A RELLENAR POR EL ALUMNO... +//RESTO DE METODOS Y FUNCIONES A RELLENAR POR EL ALUMNO.. + +void Cliente::setNombre(const char *nom){ + delete[] this->nombre; + this->nombre = new char[strlen(nom)+1]; + strcpy(this->nombre, nom); +} + +ostream& operator<<(ostream& os, const Cliente& c) { + os << c.getDni() << " - " << c.getNombre() << " (" << c.getFecha() << ")"; + return os; +} + +void Cliente::setFecha(Fecha f) { + this->fechaAlta = f; +} diff --git a/src/Fecha.cpp b/src/Fecha.cpp index eddb2a7..241108e 100644 --- a/src/Fecha.cpp +++ b/src/Fecha.cpp @@ -5,33 +5,6 @@ Fecha::Fecha(const int &dia, const int &m, const int &anio) { } void Fecha::setFecha(const int &dia, const int &mes, const int &a) { -/* - if ((mes == 1) || (mes == 3) || (mes == 5) .... - dmax=31; - else if ((mes == 4) || (mes == 6) || (mes == 9) .... - dmax=30; - else if (mes == 2) - dmax=28; - - switch (mes) { - case 1: - case 3: - case 5: - ... - dmax=31; - break; - case 4: - case 6: - case 9: - ... - dmax=30; - break; - default: - dmax=28; - break; - } -*/ -//ES MAS RAPIDO Y COMODO USAR UN ARRAY QUE GUARDE LOS DIAS DE CADA MES... int dmax, diaMes[] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; this->anio=a; //VIP debo asignar año para que al llamar a bisiesto() tenga el año bien if (this->bisiesto()) @@ -110,5 +83,17 @@ Fecha Fecha::operator++(int) { //f++ return temp; //devolvemos el objeto antes del incrementado } +ostream& operator<<(ostream& os, const Fecha& f) { + os << f.getDia() << "/" << f.getMes() << "/" << f.getAnio(); + return os; +} +Fecha Fecha::operator+(const int &dias)const { //f+5 + Fecha resultado = *this; + for(int i = 0; i < dias; i++){ + ++resultado; + } + return *this; +} + diff --git a/src/main.cpp b/src/main.cpp index 9fcd58b..0668d50 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,19 +23,19 @@ int main() { f4.setFecha(31, 12, 2000); //f4=31/12/2000 - cout << "f4: "; f4.ver(); cout << endl; +// cout << "f4: "; f4.ver(); cout << endl; f3=f4++; //indica que método/s se esta ejecutando aqui - cout << "f3: "; f3.ver(); cout << endl; +// cout << "f3: "; f3.ver(); cout << endl; ++f4; - cout << "f4: "; f4.ver(); cout << endl; +// cout << "f4: "; f4.ver(); cout << endl; // f1=2+f2+3; -// cout << "Fechas: "; f1.ver(); cout << ", "; f2.ver(); cout << ", "; -// f3.ver(); cout << ", "; f4.ver(); cout << endl; + cout << "Fechas: "; f1.ver(); cout << ", "; f2.ver(); cout << ", "; + f3.ver(); cout << ", "; f4.ver(); cout << endl; -/* Cliente *p = new Cliente(75547001, "Susana Diaz", f1); + Cliente *p = new Cliente(75547001, "Susana Diaz", f1); f1.setFecha(7,10,2015); Cliente c(75547999, "Juan Sin Miedo", Fecha(29,2,2000)); @@ -53,7 +53,7 @@ int main() { cout << "\nDatos de los clientes: \n"; cout << *p << "\n" << c << "\n" << j << "\n"; delete p; p = NULL; -*/ + if (std::filesystem::exists("/etc/os-release")){ system("read -p 'Presione una tecla para continuar' " ); return 0; }else{