Namesp.h
1 #pragmaOnce2#include <string>3 4 namespacePers5 {6 using namespacestd;7 struct Person8 {9 stringfname;Ten stringlname; One }; A voidGetperson (Person &); - voidShowperson (ConstPerson &); - } the - namespaceDebts - { - using namespacePers; + structDebt - { + person name; A Doubleamount; at }; - voidGETDEBT (Debt &); - voidSHOWDEBT (ConstDebt &); - DoubleSumdebts (ConstDebt ar[],intn); -}
Namesp.cpp
1#include"Namesp.h"2#include <iostream>3 4 using namespacestd;5 6 voidPers::getperson (Person &RP)7 {8cout <<"Enter First Name:";9CIN >>Rp.fname;Tencout <<"Enter Last Name:"; OneCIN >>Rp.lname; A } - - voidPers::showperson (ConstPerson &RP) the { -cout << Rp.fname <<", "<<Rp.lname; - } - + voidDEBTS::GETDEBT (Debt &Rd) - { + Getperson (rd.name); Acout <<"Enter Debt:"; atCIN >>Rd.amount; - } - - voidDEBTS::SHOWDEBT (ConstDebt &Rd) - { - Showperson (rd.name); incout <<": $"<< Rd.amount <<Endl; - } to + DoubleDebts::sumdebts (ConstDebt ar[],intN) - { the DoubleTotal =0; * for(inti =0; I < n; i++) $ {Panax NotoginsengTotal + =Ar[i].amount; - } the returnTotal ; +}
Namessp.cpp
1#include <iostream>2#include"Namesp.h"3 4 voidOther (void);5 voidAnother (void);6 7 intMain ()8 {9 usingdebts::D EBT;Ten usingdebts::showdebt; One ADebt Golf = {{"Benny","Goatsniff"},120.0 }; - showdebt (golf); - Other (); the another (); - -Std::cin.Get(); - return 0; + } - + voidOther (void) A { at using namespacestd; - using namespacedebts; - -Person DG = {"Doodles","Glister" }; - Showperson (DG); -cout <<Endl; in -Debt zippy[3]; to inti; + for(inti =0; I <3; i++) - { the getdebt (Zippy[i]); * } $ for(i =0; I <3; i++)Panax Notoginseng { - showdebt (Zippy[i]); the } +cout <<"total debt: $"<< Sumdebts (Zippy,3) <<Endl; A return; the } + - voidAnother (void) $ { $ usingPers::P erson; -Person collector = {"Milo","RightShift" }; - Pers::showperson (collector); theStd::cout <<Std::endl; -}
C + + namespace usage code