terminado parte1
This commit is contained in:
8
Makefile
8
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
|
||||
|
||||
BIN
bin/programa
BIN
bin/programa
Binary file not shown.
@@ -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)
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
BIN
obj/Cliente.o
BIN
obj/Cliente.o
Binary file not shown.
BIN
obj/Fecha.o
BIN
obj/Fecha.o
Binary file not shown.
BIN
obj/main.o
BIN
obj/main.o
Binary file not shown.
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
14
src/main.cpp
14
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{
|
||||
|
||||
Reference in New Issue
Block a user