namesp.h
#pragma once
#include <string> namespace pers
{
using namespace std;
struct Person
{
string fname;
string lname;
};
void getPerson(Person &);
void showPerson(const Person &);
} namespace debts
{
using namespace pers;
struct Debt
{
Person name;
double amount;
};
void getDebt(Debt &);
void showDebt(const Debt &);
double sumDebts(const Debt ar[], int n);
}
namesp.cpp
#include "namesp.h"
#include <iostream> using namespace std; void pers::getPerson(Person & rp)
{
cout << "Enter first name: ";
cin >> rp.fname;
cout << "Enter last name: ";
cin >> rp.lname;
} void pers::showPerson(const Person & rp)
{
cout << rp.fname << ", " << rp.lname;
} void debts::getDebt(Debt & rd)
{
getPerson(rd.name);
cout << "Enter debt: ";
cin >> rd.amount;
} void debts::showDebt(const Debt & rd)
{
showPerson(rd.name);
cout << ": $" << rd.amount << endl;
} double debts::sumDebts(const Debt ar[], int n)
{
double total = ;
for (int i = ; i < n; i++)
{
total += ar[i].amount;
}
return total;
}
namessp.cpp
#include <iostream>
#include "namesp.h" void other(void);
void another(void); int main()
{
using debts::Debt;
using debts::showDebt; Debt golf = { {"Benny","Goatsniff"},120.0 };
showDebt(golf);
other();
another(); std::cin.get();
return ;
} void other(void)
{
using namespace std;
using namespace debts; Person dg = { "Doodles","Glister" };
showPerson(dg);
cout << endl; Debt zippy[];
int i;
for (int i = ; i < ; i++)
{
getDebt(zippy[i]);
}
for (i = ; i < ; i++)
{
showDebt(zippy[i]);
}
cout << "Total debt: $" << sumDebts(zippy, ) << endl;
return;
} void another(void)
{
using pers::Person;
Person collector = { "Milo","Rightshift" };
pers::showPerson(collector);
std::cout << std::endl;
}