fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <array>
  4.  
  5. struct Person {
  6. std::string name;
  7. std::string surname;
  8. Person(const std::string& nm, const std::string& snm)
  9. :name{ nm }, surname{ snm }
  10. {}
  11. friend
  12. std::ostream& operator<<(std::ostream& out, const Person& person)
  13. {
  14. return out << person.name << ", " << person.surname << ": ";
  15. }
  16. };
  17.  
  18. struct Account {
  19. std::string bankName;
  20. double balance;
  21. Account(const std::string& bnm, double bal)
  22. :bankName{ bnm }, balance{ bal }
  23. {}
  24. friend
  25. std::ostream& operator<<(std::ostream& out, const Account& account)
  26. {
  27. return out << "Nazwa banku: " << account.bankName
  28. << ", saldo: " << account.balance;
  29. }
  30. };
  31.  
  32. struct AccountsIndex {
  33. Person person;
  34. Account account;
  35. AccountsIndex(const Person& per, const Account& acc)
  36. :person{ per }, account{ acc }
  37. {}
  38. friend std::ostream& operator<<(std::ostream& out, const AccountsIndex& accInd)
  39. {
  40. return out << accInd.person << accInd.account;
  41. }
  42. };
  43.  
  44. void print(const std::array<AccountsIndex, 5>& coll)
  45. {
  46. for (auto const& el : coll) {
  47. std::cout << el << '\n';
  48. }
  49. }
  50.  
  51. int main()
  52. {
  53. std::array<AccountsIndex, 5> accounts{
  54. AccountsIndex{Person{"John", ""}, Account{"PKO", 1200}},
  55. AccountsIndex{Person{"Marry", "Mm"}, Account{"BGZ", 1500}},
  56. AccountsIndex{Person{"Marry", "Mmm"}, Account{"BGZ", 1800}},
  57. AccountsIndex{Person{"Kevin", ""}, Account{"BPH", 2236.16}},
  58. AccountsIndex{ Person{"Antonio", ""}, Account{"BRE", 111.23}}
  59. };
  60. print(accounts);
  61. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
John, : Nazwa banku: PKO, saldo: 1200
Marry, Mm: Nazwa banku: BGZ, saldo: 1500
Marry, Mmm: Nazwa banku: BGZ, saldo: 1800
Kevin, : Nazwa banku: BPH, saldo: 2236.16
Antonio, : Nazwa banku: BRE, saldo: 111.23