【10.1】c++ primer plus 课后编程答案

来源:互联网 发布:飞行员是什么意思网络 编辑:程序博客网 时间:2024/09/21 06:37

C++ PRIMER PLUS 课后答案 
使用IDE为window7系统下的VS2010

/*user.h*/#ifndef USERSH_H_#define USERSH_H_#include <string> class countr{private:         std::stringname;         std::stringcount_num_;         double money_;public:              countr(std::stringp,std::string q,double m);         countr();         ~countr(){};          void show() const;         void save(double money);         void out(double money);};   #endif

//////////////////////////////////*userfucntion.cpp*/#include "usersh.h"#include <iostream>using std::cin;using std::cout;countr::countr(){         name="noname";         count_num_="noname";         money_=0;} countr::countr(std::string p="no name",std::stringq="no name",double m=0){         name=p;         count_num_=q;         money_=m;} void countr::out(double money){         char ch;         if(money_<money)                  {                          cout<<"themoney in your count  is not enough,youcan out maxnuim:"                                   <<money_<<'\n';                          cout<<"pleaseenter Y to out, Q to quit:";                                              while(cin>>ch&&ch!='Q')                          {                                   if(ch=='Y')                                            {                                                     money_=0;                                                     break;                                            }                                   else                                   {                                            cout<<"pleaseenter again!:"<<'\n';                                            cout<<"(Y to out, Q to quit)";                                            continue;                                   }                          }                        }         else                  money_-=money;}void countr::save(double money){         money_+=money;} void countr::show()const{         cout<<name<<'\n';         cout<<count_num_<<'\n';         cout<<money_<<'\n';}

///////////////////////////////*main*/#include <iostream>#include <Windows.h>#include "usersh.h"#include <string>#include <cctype> int main(){            countr* r=new countr("LXK","meat",100);         r->show();         r->save(100.5);         r->show();         r->out(100.5);         r->show();         r->out(100.5);         r->show();         delete r;         system("pause");         return 0;}