animal.cpp

来自「这是一个dos版的应用程序」· C++ 代码 · 共 61 行

CPP
61
字号
// ***************************************************************
//  Animal   version:  1.0   ? date: 12/02/2006
//  -------------------------------------------------------------
//  Animal.cpp
//  -------------------------------------------------------------
//  Copyright (C) 2006 - All Rights Reserved
// ***************************************************************
// 
// ***************************************************************

#include "Animal.h"
#include <string.h>
//----------------------------------------------------------------
istream& operator >>(istream &stream,Animal& obj){
		cout<<"输入宠物的颜色:";
		stream>>obj.s_Color;
		cout<<"输入宠物的体重:";
		stream>>obj.n_Weight;
		cout<<"输入宠物喜爱的食物:";
		stream>>obj.s_Food;
		return stream;	
}
//----------------------------------------------------------------
Animal::Animal(){
	s_Type=new char[12];
	s_Color=new char[12];
	s_Food=new char[20];
	n_Weight=0;
	strcpy(s_Type,"     ");
	strcpy(s_Food,"     ");
	strcpy(s_Type,"    ");
//	cout<<"Animal constructor"<<endl;
}
//----------------------------------------------------------------

void Animal::ChangeType(char* t){
	strcpy(s_Type,t);
}
// ---------------------------------------------------------------

void Animal::ChangeColor(char* c){
	strcpy(s_Color,c);
}
//----------------------------------------------------------------

void Animal::ChangeFood(char* f){
	strcpy(s_Food,f);
}
//----------------------------------------------------------------

void Animal::ChangeWeight(int w){
	n_Weight=w;
}

//----------------------------------------------------------------
Animal::~Animal(){	
	delete[] s_Food;
	delete[] s_Color;	
	delete[] s_Type;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?