【12.1】c++ primer plus 课后编程答案
来源:互联网 发布:天蝎网络第二季看不到 编辑:程序博客网 时间:2024/06/07 04:15
C++ PRIMER PLUS 课后答案 使用IDE为window7系统下的VS2010
/*user.h*/
#ifndef USERSH_H_#define USERSH_H_#include <string>using std::ostream;using std::istream;class Cow{char name[20];char * hobby;double weight;public:Cow();Cow(const char * nm,const char * ho,double wt);Cow(const Cow & c);~Cow();Cow & operator = (const Cow & c);void showcow()const;};#endif
/*userfucntion.cpp*/#include "usersh.h"#include <iostream>#include <cstring>using std::cout;using std::cin;using std::ostream;using std::istream;Cow::Cow(){name[0]='\0';weight=50;hobby=new char[1];hobby[0]='\0';}Cow::Cow(const char * nm,const char * ho,double wt){strcpy(name,nm);hobby=new char [strlen(ho)+1];strcpy(hobby,ho);weight=wt;}Cow::Cow(const Cow & c){strcpy(name,c.name);hobby=new char [strlen(c.hobby)+1];strcpy(hobby,c.hobby);weight=c.weight;}Cow::~Cow(){delete [] hobby;}Cow & Cow::operator =(const Cow & c){if(this==&c)return * this;delete [] hobby;strcpy(name,c.name);hobby=new char [strlen(c.hobby)+1];strcpy(hobby,c.hobby);weight=c.weight;}void Cow::showcow()const{cout<<"name:"<<name<<'\n';cout<<"hobby:"<<hobby<<'\n';cout<<"weight:"<<weight<<'\n';}
/*main*/#include <iostream>#include <Windows.h>#include "usersh.h"using std::cout;using std::cin;using std::endl;int main(){ Cow one("xiao ming","sleep ",40);one.showcow();Cow two(one);two.showcow();Cow three;three=two;three.showcow();system("pause");return 0;}
阅读全文
0 0
- C++primer plus第六版课后编程题答案12.1
- C++primer plus第六版课后编程练习答案12.1
- 【12.1】c++ primer plus 课后编程答案
- C++PRIMER PLUS第六版课后编程答案 4.1-4.5
- C++PRIMER PLUS第六版课后编程答案 4.6-4.10
- C++PRIMER PLUS第六版课后编程答案 5.1-5.5
- C++PRIMER PLUS第六版课后编程答案 5.6-510
- C++primer plus第六版课后编程题答案 6.1
- C++primer plus第六版课后编程题答案 6.2
- C++primer plus第六版课后编程题答案 6.3
- C++primer plus第六版课后编程题答案 6.4
- C++primer plus第六版课后编程题答案 6.5
- C++primer plus第六版课后编程题答案 6.6
- C++primer plus第六版课后编程题答案 6.7
- C++primer plus第六版课后编程题答案 6.8
- C++primer plus第六版课后编程题答案 6.9
- C++primer plus第六版课后编程题答案7.1
- C++primer plus第六版课后编程题答案7.2
- python 发送http请求填坑
- USB协通讯议(很好的一篇文章)
- Openstack Neutron扩展实现细节(QOS)
- 又遇到vmware不能启动了(vmware12/Deepin15.4(4.9.0kernel))
- 一次一密文件加密程序
- 【12.1】c++ primer plus 课后编程答案
- 找出Vector中所有最小值
- JS创建对象的几种方式
- CNN
- 使用JDBCTemplate实现与Spring结合,方法公用 ——测试(EmpDaoImplTest)
- Layer的实现细节
- 华为实习day2
- Android RatingBar(评分控件)
- Adversarial Autoencoder