c++类和对象等编程

来源:互联网 发布:深圳程序员招聘网 编辑:程序博客网 时间:2024/05/03 21:39
仅供参考 另外我的程序可能有错误 你如果高兴的话 可以在构造函数中初始变量什么的 这个只是我个人意见 #include <iostream>#include <string>using namespace std;class rech{public:std::int long=0;std::int wide=0;}把这个存放在rech.h中#include <iostream>#include <string>#include "rech.p"using namespace std;class rech_cpp{public:rech_h();~rech_h();void setdata(){cout<<"please set the long of the rechangle"<<endl;cin>>long<<endl;cout<<"please set the wide of the rechangle"<<endl;cin>>wide<<endl;cout<<"long="<<long<<endl;cout<<"wide="<<wide<<endl;}void revisedate(){cout<<"please revise the long of the rechangle"<<endl;cin>>long<<endl;cout<<"please revise the wide of the rechangle"<<endl;cin>>wide<<endl;cout<<"long="<<long<<endl;cout<<"wide="<<wide<<endl;}void printdata(){cout<<"long="<<long<<endl;cout<<"wide="<<wide<<endl;cout<<"perimeter="<<(long+wide)*2<<endl;cout<<"area="<<long*wide<<endl;}}这个存放在rech.cpp中#include <iostream>#include <string>#include "rech.h"#include "rech.cpp"using namespace std;int main(){int x;cout<<"1 setdata "<<endl;cout<<"2 revisedata "<<endl;cout<<"3 printdata "<<endl;cout<<"please chose the menu(1~3)"<<endl;cin>>x<<endl;rech_cpp re;if(x=1)re.setdata();elseif(x=2)re.revisedata();elsere.printdata();return 0;}这个存放在test1.cpp中我已经N久没碰这些东西了
原创粉丝点击