首页 分享 1、领养宠物并打印宠物信息: 打印自己的信息,含上述属性值 打印出顾客选择的宠物的基本信息。

1、领养宠物并打印宠物信息: 打印自己的信息,含上述属性值 打印出顾客选择的宠物的基本信息。

来源:萌宠菠菠乐园 时间:2025-04-24 05:03

class Dog

{

private:

string name;

string strain;

public:

Dog(string name, string strain)

{

this->name = name;

this->strain = strain;

}

void print()

{

cout << "Pet dog: Name=" << this->name << ", Strain=" << this->strain << endl;

}

};

class Penguin

{

private:

string name;

string sex;

public:

Penguin(string name, string sex)

{

this->name = name;

this->sex = sex;

}

void print()

{

cout << "Pet penguin: Name=" << this->name << ", Sex=" << this->sex << endl;

}

};

int main()

{

cout << "Welcome to the Pet Store!" << endl;

cout << "We have two kinds of pets available: dogs and penguins." << endl;

cout << "Please select a pet type (Enter 1 for dog, 2 for penguin): ";

int petType;

cin >> petType;

if (petType == 1)

{

cout << "You have selected a dog. Please enter nickname: ";

string name;

cin >> name;

cout << "Please enter strain: ";

string strain;

cin >> strain;

Dog dog(name, strain);

dog.print();

}

else if (petType == 2)

{

cout << "You have selected a penguin. Please enter nickname: ";

string name;

cin >> name;

cout << "Please enter sex (M for male, F for female): ";

string sex;

cin >> sex;

Penguin penguin(name, sex);

penguin.print();

}

else

{

cout << "Invalid choice. Please choose 1 or 2." << endl;

}

return 0;

}

相关知识

1、领养宠物并打印宠物信息: 打印自己的信息,含上述属性值 打印出顾客选择的宠物的基本信息。
领养宠物并打印宠物信息java代码
Dog和Penguin类 领养宠物并打印宠物信息
Java类和对象笔试题
java类笔试题
打印样张的色彩对比
领养宠物并打印宠物信息java
宠物领养价格卡模板打印,为你提供领养费用的全面指南
领养宠物合同协议书模板打印.docx
python宠物模拟

网址: 1、领养宠物并打印宠物信息: 打印自己的信息,含上述属性值 打印出顾客选择的宠物的基本信息。 https://www.mcbbbk.com/newsview1126577.html

所属分类:萌宠日常
上一篇: 吉家宠物年产20万吨宠物食品项目
下一篇: 全球和中国宠物食品市场趋势分析报

推荐分享