namesp.cpp 876 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // namesp.cpp -- namespaces
  2. #include <iostream>
  3. #include "namesp.h"
  4. namespace pers
  5. {
  6. using std::cout;
  7. using std::cin;
  8. void getPerson(Person & rp)
  9. {
  10. cout << "Enter first name: ";
  11. cin >> rp.fname;
  12. cout << "Enter last name: ";
  13. cin >> rp.lname;
  14. }
  15. void showPerson(const Person & rp)
  16. {
  17. std::cout << rp.lname << ", " << rp.fname;
  18. }
  19. }
  20. namespace debts
  21. {
  22. void getDebt(Debt & rd)
  23. {
  24. getPerson(rd.name);
  25. std::cout << "Enter debt: ";
  26. std::cin >> rd.amount;
  27. }
  28. void showDebt(const Debt & rd)
  29. {
  30. showPerson(rd.name);
  31. std::cout <<": $" << rd.amount << std::endl;
  32. }
  33. double sumDebts(const Debt ar[], int n)
  34. {
  35. double total = 0;
  36. for (int i = 0; i < n; i++)
  37. total += ar[i].amount;
  38. return total;
  39. }
  40. }