动物类及修改-C++
/*
功能:动物类
日期:2013-10-12
*/
#include <iostream>
#include <string>
using namespace std;
class Animal
{
public:
Animal(string aName,string aGender,string aColor,string aVoice);
~Animal();
void rest();
void Display()const;
private:
string m_aName;
string m_aGender;
string m_aColor;
string m_aVoice;
};
Animal::Animal(string aName="Dog",string aGender="Male",string aColor="Yellow",string aVoice="wangwang"):
m_aName(aName),m_aGender(aGender),m_aColor(aColor),m_aVoice(aVoice){};
Animal::~Animal()
{
};
void Animal::Display()const
{
cout<<"Now animal information is:"<<endl;
cout<<"Animal name:"<<m_aName<<endl;
cout<<"Animal gender:"<<m_aGender<<endl;
cout<<"Animal color:"<<m_aColor<<endl;
cout<<"Animal Voice:"<<m_aVoice<<endl;
cout<<"What do you want to reset:(1.name;2.gender;3.color;4.voice;5.exit)";
}
void Animal::rest()
{
int choice;
do
{
Display();
cin>>choice;
switch(choice)
{
case 1:
cout<<"Reset name:";
cin>>m_aName;
break;
case 2:
cout<<"Reset gender:";
cin>>m_aGender;
break;
case 3:
cout<<"Reset color:";
cin>>m_aColor;
break;
case 4:
cout<<"Reset voice:";
cin>>m_aVoice;
break;
case 5:
break;
}
}while(choice!=5);
}
int main(void)
{
Animal animal;
animal.rest();
system("pause");
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Preview
除特别注明外,本站所有文章均为 Windcoder网 原创,转载请注明出处来自: dong-wu-lei-ji-xiu-gai-c
Loading comments...

Preview
No Data