Skip to content

Instantly share code, notes, and snippets.

@grayed
Created April 3, 2021 14:46
Show Gist options
  • Save grayed/0eb74495d00ff1d73a555111330cb311 to your computer and use it in GitHub Desktop.
Save grayed/0eb74495d00ff1d73a555111330cb311 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
/*
* Написать программу, описывающую базу данных владельцев автомобилей.
* Класс автомобиля должен содержать ссылки/указатели на всех владельцев,
* а класс владельца должен содержать ссылки/указатели на все имеющиеся в наличии автомобили.
* Для каждого автомобиля должно быть реализовано свойство, показывающее количество владельцев.
*/
class Auto {
std::vector<Owner&> owners;
public:
// ... реализовать конструктор(-ы), деструктор (если нужно), name(), addOwner(), ownersCount()
};
class Owner; // аналогично, внутри класса завести поле vector<Auto&> autos
// https://gist.github.com/grayed - код с прошлых занятий
int main()
{
Auto auto1(/* ... */); Auto auto2(/* ... */); Auto auto3(/* ... */);
Owner owner1(/* ... */); Owner owner2(/* ... */); Owner owner3(/* ... */);
auto1.addOwner(owner1);
auto1.addOwner(owner2);
auto2.addOwner(owner2);
std::vector<Auto> autos; autos.push_back(auto1); autos.push_back(auto2); autos.push_back(auto3);
std::vector<Owner> owners{ owner1, owner2, owner3 };
for (auto& a : autos)
std::cout << "Automobile " << a.name() << " has " << a.ownersCount() << " owners" << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment