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

来源:互联网 发布:网络购物狂欢节 编辑:程序博客网 时间:2024/06/05 10:37

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

/*user.h*/#ifndef USERSH_H_#define USERSH_H_#include <string>class Move{private:         double x;         double y;public:         Move(double a=0,double b=0);         void showmove() const;         Move  add(const Move & m)const;         void reset(double a=0,double b=0);};  #endif 


/*userfucntion.cpp*/#include "usersh.h"#include <iostream>using std::cout;using std::cin; Move::Move(double a/* =0 */,double b/* =0*/){         x=a;         y=b;} void Move::showmove() const{         cout<<"X:"<<x<<'\n';         cout<<"Y:"<<y<<'\n';}void Move::reset(double a/* =0 */,doubleb/* =0 */){         x=a;         y=b;} Move Move::add(const Move & m)const{         Move st;         st.x=m.x;         st.y=m.y;         returnst;        } 


/*main*/#include <iostream>#include <Windows.h>#include "usersh.h"#include <string>#include <cctype>using std::cout;using std::cin; int main(){            Move a;         a.showmove();          Move b(10,20);         b.showmove();          a=a.add(b);         a.showmove();          a.reset();         a.showmove();          system("pause");         return 0;}


原创粉丝点击