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.
#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();
}
}
}
Comments
Leave a comment