animals.cpp
上传用户:sz0451
上传日期:2022-07-29
资源大小:256k
文件大小:1k
源码类别:

.net编程

开发平台:

Visual C++

  1. // This is the main project file for VC++ application project 
  2. // generated using an Application Wizard.
  3. #include "stdafx.h"
  4. #include <string.h>
  5. #using <mscorlib.dll>
  6. #include <tchar.h>
  7. using namespace System;
  8. __gc class animal
  9. {
  10. public:
  11.     int     legs;
  12.     void SetName(String *Name) { strName = strName->Copy(Name); };
  13.     String* GetName() { return strName; };
  14. private:
  15.     String  *strName;
  16. };
  17. // This is the entry point for this application
  18. int _tmain(void)
  19. {
  20.     // TODO: Please replace the sample code below with your own.
  21.     animal *Cat, *Dog;
  22.     Cat = new animal;
  23.     Dog = new animal;
  24.     Cat->SetName("Cat");
  25.     Cat->legs = 4;
  26.     Dog->SetName("Dog");
  27.     Dog->legs = 4;
  28.     Console::WriteLine("Animal 1");
  29.     Console::Write("Name ");
  30.     Console::WriteLine(Cat->GetName());
  31.     Console::Write("Legs ");
  32.     Console::WriteLine(Cat->legs);
  33.     Console::WriteLine();
  34.     Console::WriteLine("Animal 2");
  35.     Console::Write("Name ");
  36.     Console::WriteLine(Dog->GetName());
  37.     Console::Write("Legs ");
  38.     Console::WriteLine(Dog->legs);
  39.     Console::WriteLine();
  40.     return 0;
  41. }