Answer to Question #286457 in C for Dofree130

Question #286457

write a program to define a structure called a car. the member elements of the car structure are model(like bmw, ford...etc), production year (1999,2020,...), and lastly price. create an array of 10 cars. get input for all 10 cars from the user. then the program display complete information (model, year, price) of those cars only which are above 250000 in price or production date bigger than 2000.

1
Expert's answer
2022-01-11T04:10:31-0500
#include <iostream>

class car
{
    char model[10];
    short int production_year;
    int lastly_price;
public:
    void input()
    {
        std::cout<<"Enter model: ";
        std::cin>>model;
        std::cout<<"Enter production year: ";
        std::cin>>production_year;
        std::cout<<"Enter lastly price: ";
        std::cin>>lastly_price;
    }
    const int& get_price()
    {
        return this->lastly_price;
    }
    const short int& get_year()
    {
        return this->production_year;
    }
    void output()
    {
        std::cout<<model<<'\t'<<production_year<<'\t'<<lastly_price<<'\n';
    }
};
int main()
{
    car cars[10];
    for(int i = 0; i!= 10; ++i)
    {
        cars[i].input();
    }
    for(int i = 0; i!= 10; ++i)
    {
        if(cars[i].get_price() > 250000 && cars[i].get_year() > 2000)
        {
            cars[i].output();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS