The entered data is not displayed

1

I have a Garito class in which I have implemented a series of setters and getters to be able to interact with their content. Apart I have some functions that access these methods to show the data. I have managed to show them using parameterized constructors but I can not get them to work using a default constructor .

This is my code:

Garito.cpp

include "Garito.h"

Garito::Garito(){        
}      

Garito::Garito(std::string nombre,std::string direccion)
        : nombre(nombre),
        direccion(direccion){

}

Garito::Garito(const Garito &orig)
        : nombre(orig.nombre),
        direccion(orig.direccion){

}

Garito::~Garito(){

}

void Garito::setNombre(std::string nombre){
    if (nombre == "")
        throw std::string ("[setNombre]: No se ha introducido ningun texto"); 
}
std::string Garito::getNombre() const{
    return nombre;
}

void Garito::setDireccion(std::string direccion){
    if (direccion == "")
        throw std::string ("[setDireccion]: No se ha introducido ningun texto");
}

std::string Garito::getDireccion() const{
    return direccion;
}

Features.cpp

#include <iostream>
#include "funciones.h"


void funciones::mostrarTemazo(const Temazo& t){

   std::cout <<"Interprete: "<<t.getInterprete()<<std::endl;
   std::cout <<"Titulo: "<<t.getTitulo()<<std::endl;
   std::cout <<"Duracion: "<<t.getDuracion()<<" segundos"<<std::endl;
   std::cout <<"Puntaucion: "<<t.getPuntuacion()<< " puntos"<<std::endl;  

}

void funciones::mostrarGarito(const Garito& g){
   std::cout <<"Nombre del Garito: "<<g.getNombre()<<std::endl; 
   std::cout <<"Direccion del Garito: "<<g.getDireccion()<<std::endl;

}

void funciones::mostrarFecha(const Fecha& f){
    std::cout <<"Dia: "<<f.getDia()<<std::endl;
    std::cout <<"Mes: "<<f.getMes()<<std::endl;
    std::cout <<"Anio: "<<f.getAnio()<<std::endl;

}

void funciones::pideGarito(Garito& gg){
    std::string ngarito;

    std::cout <<"Introduce los datos del garito"<<std::endl;
    std::cout <<"Introduce el nombre del garito"<<std::endl;
    getline(std::cin, ngarito);
    gg.setNombre(ngarito);
    std::cout <<"Introduce la direccion del garito"<<std::endl;
    getline(std::cin, ngarito);
    gg.setDireccion(ngarito);

}

main.cpp

#include <cstdlib>
#include <iostream>
#include "Temazo.h"
#include "Garito.h"
#include "Fecha.h"
#include "funciones.h"


/*
 * 
 */
int main(int argc, char** argv) {

    Garito g;
    funciones::pideGarito(g);
    funciones::mostrarGarito(g);

}

The program as it compiles, I can enter the data but at the time of showing them it shows me a blank space.

    
asked by JACK1ETO 22.06.2018 в 16:02
source

1 answer

2
  

The program as it compiles, I can enter the data but at the time of showing them it shows me a blank space.

It's normal for you to pass, because you do not save the data:

void Garito::setNombre(std::string nombre){
    if (nombre == "")
        throw std::string ("[setNombre]: No se ha introducido ningun texto"); 
}

void Garito::setDireccion(std::string direccion){
    if (direccion == "")
        throw std::string ("[setDireccion]: No se ha introducido ningun texto");
}

Where do you see that the std::string passed by parameters is saved in the corresponding member variable? Make this correction:

void Garito::setNombre(std::string nombre){
    if (nombre == "")
        throw std::string ("[setNombre]: No se ha introducido ningun texto"); 
    this->nombre = nombre;
}

void Garito::setDireccion(std::string direccion){
    if (direccion == "")
        throw std::string ("[setDireccion]: No se ha introducido ningun texto");
    this->direccion = direccion;
}
    
answered by 25.06.2018 в 08:25