zoukankan      html  css  js  c++  java
  • 一道题

    // Test.cpp : Defines the entry point for the console application.
    //
    
    #include <stdafx.h>
    #include <stdio.h>
    #include  <math.h>
    #include <string.h>
    
    class Animal
    {
    	public:
    		char name[15];
    		int health;
    		int love;
    };
    
    class Dog:public Animal
    {
    	public:
    		char strain[15];
    };
    
    class Penguin:public Animal
    {
    	public:
    		char sex[15];
    };
    
    void SetProperty(Animal *animal);
    
    int main()
    {
       int i,j,N;
       printf("请输入一个大于0的数表示开始!
    ");
       while(scanf("%d",&N)&&N!=0)                 //输入0表示结束
       {
    	   printf("欢迎来到宠物商店!");
    	   printf("输入您要购买的宠物类型(1.狗  2.企鹅):");
    	   scanf("%d",&i);
    	   printf("
    ");
    	   
    	   if(i==1)
    	   {
    		   Dog *dog=new Dog();
    		   SetProperty(dog);
    		   printf("请选择品种(1.京巴  2.拉布拉多):输入1或2:");
    		   scanf("%d",&j);
    		   if(j==1)
    		   {
    			   strcpy(dog->strain,"京巴");
    		   }
    		   else
    		   {
    			   strcpy(dog->strain,"拉布拉多");
    		   }
    		   printf("宠物的自白:
    ");
    		   printf("我叫:%s,健康值是:%d ,与主人亲密度是:%d ,品种是:%s
    ",dog->name,dog->health,dog->love,dog->strain);
    	   }
    	   else
    	   {
    		   Penguin *penguin=new Penguin();
    		   SetProperty(penguin);
    		   printf("请选择性别(1.Q妹  2.Q仔):");
    		   scanf("%d",&j);
    		   if(j==1)
    		   {
    			   strcpy(penguin->sex,"Q妹");
    		   }
    		   else
    		   {
    			   strcpy(penguin->sex,"Q仔");
    		   }
    		   printf("宠物的自白:
    ");
    		   printf("我叫:%s,健康值是:%d,与主人亲密度是:%d,性别是:%s
    ",penguin->name,penguin->health,penguin->love,penguin->sex);
    	   }
       }
    
       return 0;
    }
    
    void SetProperty(Animal *animal)
    {
        printf("请出入宠物的姓名:自己输入一个名字:");
    	scanf("%s",animal->name);
    	printf("请输入与主人的亲密度:输入0-100的数字:");
    	scanf("%d",&animal->love);
    	printf("请输入健康值:输入0-100的数字:");
        scanf("%d",&animal->health);
    }
    

      

  • 相关阅读:
    HTTP 状态码
    Buffer 流文件
    事件(Event)机制 .on() .emit() .once() .removeListener()
    UDP node客户端和服务端
    node全局变量  node定时器 系统自带的模块 http服务器
    标题省略,不会自动换行
    SpringBoot 出现 Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
    循环对象
    npm
    根据对象的key值,查找对应的属性value
  • 原文地址:https://www.cnblogs.com/dengshiwei/p/3988703.html
Copyright © 2011-2022 走看看