c++类和对象等编程

仅供参考 另外我的程序可能有错误 你如果高兴的话 可以在构造函数中初始变量什么的 这个只是我个人意见 #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(); else re.printdata();return 0;}这个存放在test1.cpp中我已经N久没碰这些东西了
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值