How does a car class in Java convert to C++?

Asked

Viewed 76 times

0

public class Carro {

    private String nome;
    private int ano;
    private String modelo;
    private String marca;
    private String combustivel;
    private Double valor;

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public int getAno() {
        return ano;
    }

    public void setAno(int ano) {
        this.ano = ano;
    }

    public String getModelo() {
        return modelo;
    }

    public void setModelo(String modelo) {
        this.modelo = modelo;
    }

    public String getMarca() {
        return marca;
    }

    public void setMarca(String marca) {
        this.marca = marca;
    }

    public String getCombustivel() {
        return combustivel;
    }

    public void setCombustivel(String combustivel) {
        this.combustivel = combustivel;
    }

    public Double getValor() {
        return valor;
    }

    public void setValor(Double valor) {
        this.valor = valor;
    }

    @Override
    public String toString() {
        return "Carro{" + "nome=" + nome + ", ano=" + ano + ", modelo=" + modelo + ", marca=" + marca + ", combustivel=" + combustivel + ", valor=" + valor + '}';
    }
}

1 answer

1

In C++ would look like this:

class Carro{

   private: 

  string nome;
  int ano;
 string modelo;string marca;string combustivel;double valor;

public:
 getter /setter;

void print(){

   cout << "Carro modelo is: " << modelo; 

          }     

};

int main(void){
        Carro car;

        car.setModelo("GOL");

        car.print();

        return 0;

              }
  • 1

    Usually you don’t do this in C++, this is a more pragmatic language that observes more details than in Java and looks for more efficiency, and if you were to simulate like Java the allocation would not be done like this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.