C + + Namespace usage code

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.