ayuda practica1, creacion Makefile
This commit is contained in:
43
Makefile
Normal file
43
Makefile
Normal file
@@ -0,0 +1,43 @@
|
||||
# ===============================
|
||||
# Makefile para proyecto con Fecha
|
||||
# ===============================
|
||||
|
||||
# --- Configuración general ---
|
||||
CXX = g++
|
||||
CXXFLAGS = -Wall -Wextra -std=c++17 -Iinclude
|
||||
SRC_DIR = src
|
||||
OBJ_DIR = obj
|
||||
BIN_DIR = bin
|
||||
TARGET = $(BIN_DIR)/programa
|
||||
|
||||
# --- Archivos fuente y objeto ---
|
||||
SRCS = $(wildcard $(SRC_DIR)/*.cpp)
|
||||
OBJS = $(SRCS:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
|
||||
|
||||
# --- Regla principal ---
|
||||
all: $(TARGET)
|
||||
|
||||
# --- Cómo generar el ejecutable ---
|
||||
$(TARGET): $(OBJS)
|
||||
@mkdir -p $(BIN_DIR)
|
||||
$(CXX) $(CXXFLAGS) $(OBJS) -o $(TARGET)
|
||||
@echo "✅ Compilación completa. Ejecutable en $(TARGET)"
|
||||
|
||||
# --- Cómo compilar cada .cpp a .o ---
|
||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
|
||||
@mkdir -p $(OBJ_DIR)
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
# --- Limpieza ---
|
||||
clean:
|
||||
rm -rf $(OBJ_DIR)/*.o
|
||||
@echo "🧹 Archivos objeto eliminados."
|
||||
|
||||
mrproper: clean
|
||||
rm -rf $(BIN_DIR)/*
|
||||
@echo "🧹 Ejecutables eliminados."
|
||||
|
||||
# --- Ejecución rápida ---
|
||||
run: all
|
||||
./$(TARGET)
|
||||
|
||||
31
include/Cliente.h
Normal file
31
include/Cliente.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef CLIENTE_H
|
||||
#define CLIENTE_H
|
||||
|
||||
#include <iostream> //cin, cout
|
||||
#include "Fecha.h"
|
||||
|
||||
using namespace std;
|
||||
//SI FALTA ALGUN METODO O FUNCION A<>ADIRLO...
|
||||
class Cliente {
|
||||
long int dni;
|
||||
char *nombre;
|
||||
Fecha fechaAlta;
|
||||
public:
|
||||
Cliente(long int d, char *nom, Fecha f);
|
||||
virtual ~Cliente();
|
||||
Cliente& operator=(const Cliente& c);
|
||||
|
||||
long int getDni() const { return this->dni; }
|
||||
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 setFecha(Fecha f);
|
||||
|
||||
bool operator==(Cliente c) const; // if (c1 ===c2)
|
||||
|
||||
};
|
||||
|
||||
ostream& operator<<(ostream &s, const Cliente &c); //funcion no amiga de la clase
|
||||
|
||||
#endif // CLIENTE_H
|
||||
@@ -1,5 +1,30 @@
|
||||
#define Fecha_H
|
||||
#ifndef FECHA_H
|
||||
#define FECHA_H
|
||||
|
||||
#include <iostream>
|
||||
#include <iostream> //cin, cout
|
||||
|
||||
using namespace std;
|
||||
//SI FALTA ALGUN METODO O FUNCION A<>ADIRLO...
|
||||
class Fecha {
|
||||
int dia;
|
||||
int mes, anio;
|
||||
public:
|
||||
Fecha(const int &dia, const int &m, const int &anio);
|
||||
//virtual ~Fecha(); //NO HACE FALTA
|
||||
//Fecha(const Fecha &f); //NO HACE FALTA: EL QUE GENERA EL COMPILADOR FUNCIONA BIEN YA QUE NO HAY PUNTEROS
|
||||
int getDia() const { return dia; }
|
||||
int getMes() const { return this->mes; }
|
||||
int getAnio() const { return this->anio; }
|
||||
void setFecha(const int &dia, const int &mes, const int &a);
|
||||
void ver() const;
|
||||
bool bisiesto() const;
|
||||
Fecha operator++(); //++f
|
||||
Fecha operator++(int i); //f++
|
||||
Fecha operator+(const int &i) const; //f+5
|
||||
|
||||
friend Fecha operator+(const int &i, const Fecha &f); //const por seguridad y & por velocidad
|
||||
};
|
||||
|
||||
Fecha operator+(const int &i, const Fecha &f); //const por seguridad y & por velocidad
|
||||
|
||||
#endif // FECHA_H
|
||||
|
||||
43
src/Cliente.cpp
Normal file
43
src/Cliente.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring> //strlen, strcpy
|
||||
#include <iomanip> //std::setprecision
|
||||
#include <sstream> //stringstream
|
||||
#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
|
||||
this->dni=d; //constructor copia de fecha
|
||||
//en vez de constructor de 3 parametros)
|
||||
//this->nombre=nombre; //MAL!!!!
|
||||
this->nombre=new char[strlen(nom)+1];
|
||||
strcpy(this->nombre, nom);
|
||||
|
||||
//this->fechaAlta=f;//MAL!!!! los tipos no primitivos debe ir en zona inicializadores
|
||||
}
|
||||
|
||||
Cliente::~Cliente() {
|
||||
delete [] this->nombre; //si en el constructor uso new [] en el destructor uso delete []
|
||||
}
|
||||
|
||||
Cliente& Cliente::operator=(const Cliente& c) {
|
||||
if (this != &c) { //si no es x=x
|
||||
this->dni=c.dni;
|
||||
delete [] this->nombre;
|
||||
//this->nombre=c.nombre; //MAL!!!!
|
||||
this->nombre=new char[strlen(c.nombre)+1];
|
||||
strcpy(this->nombre, c.nombre);
|
||||
this->fechaAlta=c.fechaAlta;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Cliente::operator==(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() ||
|
||||
this->fechaAlta.getMes()!=c.fechaAlta.getMes() ||
|
||||
this->fechaAlta.getAnio()!=c.fechaAlta.getAnio()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//RESTO DE METODOS Y FUNCIONES A RELLENAR POR EL ALUMNO...
|
||||
90
src/Fecha.cpp
Normal file
90
src/Fecha.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
#include "Fecha.h"
|
||||
|
||||
Fecha::Fecha(const int &dia, const int &m, const int &anio) {
|
||||
this->setFecha(dia, m, anio); //el cogido es el mismo que el del metodo setFecha
|
||||
}
|
||||
|
||||
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())
|
||||
diaMes[2]=29;
|
||||
|
||||
if (mes<1) //si el mes es incorrecto
|
||||
this->mes=1;
|
||||
else if (mes>12) //si el mes es incorrecto
|
||||
this->mes=12;
|
||||
else
|
||||
this->mes=mes;
|
||||
dmax=diaMes[this->mes]; //una vez fijado el mes veo cuantos dias tiene ese mes como maximo
|
||||
|
||||
if (dia>dmax) //si dia es superior al numero de dias de dicho mes
|
||||
this->dia=dmax;
|
||||
else if (dia<1) //si dia es inferior a 1
|
||||
this->dia=1;
|
||||
else
|
||||
this->dia=dia;
|
||||
}
|
||||
|
||||
bool Fecha::bisiesto() const {
|
||||
if (this->anio%4==0) //esto no es exacto... corregidlo ustedes
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void Fecha::ver() const {
|
||||
if (this->dia < 10)
|
||||
cout << "0";
|
||||
cout << this->dia << "/";
|
||||
if (this->mes < 10)
|
||||
cout << "0";
|
||||
cout << this->mes << "/" << this->anio;
|
||||
}
|
||||
|
||||
Fecha Fecha::operator++() { //++f
|
||||
int dmax, diaMes[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
|
||||
if (this->bisiesto()) //si el a<>o es bisiesto febrero tiene 29 dias
|
||||
diaMes[2]=29;
|
||||
dmax=diaMes[this->mes];
|
||||
this->dia++;
|
||||
if (this->dia>dmax) { //si al incrementar dia superamos el numero de dias de dicho mes
|
||||
this->dia=1; //pasamos a 1
|
||||
this->mes++; //del mes siguiente
|
||||
if (this->mes>12) { //si al incrementar mes pasamos de 12 meses
|
||||
this->mes=1; //pasamos al mes 1
|
||||
this->anio++; //del a<>o siguiente
|
||||
}
|
||||
}
|
||||
return *this; //devolvemos el objeto fecha ya incrementado
|
||||
}
|
||||
|
||||
//RESTO DE METODOS Y FUNCIONES A RELLENAR POR EL ALUMNO...
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include "Fecha.h" //definicion de la clase Fecha
|
||||
|
||||
Reference in New Issue
Block a user