Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
guys I need help in this exercise mainly after the letter d) in the creation of another class, here is the first class I did in a header file

Statement of the exercise:

1- Make a program for registration and consultation of new or used vehicles.
a) Define an Automovel class, which has the following information:
- brand - marca
- year - ano
- status (which can be sold or available)
- color - cor
- price - preco
- model - modelo
- state - estado


b) Define a constructor method for the Automovel class that initializes the values ​​of the attributes by passing defined arguments.
c) Define the get and set methods for all attributes and methods.
d) Elaborate another class (UsaAutomovel) to test the Automovel class where:
- A list of automobiles must be created by creating objects of the Automovel class.
- Define a method for filling in data about a car and add it to the list.
e) Make a method to search for vehicles by brand lookBrand - lists the car of a certain brand.
f) make a method that allows the sale of a vehicle.
g) Define in the main class (UsaAutomovel) the following options: List cars and total sales.

2- Create two classes that inherit the characteristics of the automobile class.

C++
#ifndef AUTOMOVEL_H
#define AUTOMOVEL_H


class Automovel
{
    int ano;
    string marca, modelo, cor, estado, status;
    float preco;

    public:
    Automovel(void){
    }
    //consulta
    Automovel(string marca, int ano, string status, string cor, float preco, string modelo, string estado){
        this->marca = marca;
        this->ano = ano;
        this->status = status;
        this->cor = cor;
        this->preco = preco;
        this->modelo = modelo;
        this->estado = estado;
    }
    string getMarca(void){
        return this->marca;
    }
    int getAno(void){
        return this->ano;
    }
    string getStatus(void){
        return this->status;
    }
    string getCor(void){
        return this->cor;
    }
    float getPreco(void){
        return this->preco;
    }
    string getModelo(void){
        return this->modelo;
    }
    string getEstado(void){
        return this->estado;
    }
    void setMarca(string marca){
        this->marca = marca;
    }
    void setAno(int ano){
        this->ano = ano;
    }
    void setStatus(string status){
        this->status = status;
    }
    void setCor(string cor){
        this->cor = cor;
    }
    void setPreco(float preco){
        this->preco;
    }
    void setModelo(string modelo){
        this->modelo;
    }
    void setEstado(string estado){
        this->estado;
    }
    void toString(){
        cout << "Marca: " << this->getMarca() <<" Ano: " << this->getAno() << " Status: " << this->getStatus()<< " Cor: " << this->getCor()<< " Preco: " << this->getPreco() << " Modelo: " << this->getModelo() << " Estado: " << this->getEstado();
    }
};
class UsaAutomovel
{

};
#endif // AUTOMOVEL_H


What I have tried:

I tried to create a new header library with UsaAutomoveis to make the list but I have doubts on how to assemble it
Posted
Updated 23-Apr-21 13:06pm
v2

1 solution

You should think of the Automovel as a class to describe the generic properties of an automobile. Inherited classes derived from it will be specializations and examples could be trucks, vans, and tractors. Give the derived classes additional properties that might describe them like number of axles, number of wheels per rear axle, volume of cargo area, etc. For the purposes of this exercise, you could say a Van only has two axles so it will not need that property while a truck could have two, three, or more.

The syntax for deriving the classes looks like this :
C++
class Van : public Automovel
{
public:
   // describe additional properties here
};

class Truck : public Automovel
{
public:
   // describe additional properties here
    int axles;
};
 
Share this answer
 
Comments
BrennoPedroso 23-Apr-21 19:08pm    
This in case it would be my cpp file to compile together with my hpp file that I sent earlier, but I am not able to execute this presented some errors, if you can help me I will be very grateful.
Rick York 23-Apr-21 21:13pm    
You should edit the original question and paste your revised code into it. I'm not even going to try reading that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900