animals.cpp
上传用户:sz0451
上传日期:2022-07-29
资源大小:256k
文件大小:1k
- // This is the main project file for VC++ application project
- // generated using an Application Wizard.
- #include "stdafx.h"
- #include <string.h>
- #using <mscorlib.dll>
- #include <tchar.h>
- using namespace System;
- __gc class animal
- {
- public:
- int legs;
- void SetName(String *Name) { strName = strName->Copy(Name); };
- String* GetName() { return strName; };
- private:
- String *strName;
- };
- // This is the entry point for this application
- int _tmain(void)
- {
- // TODO: Please replace the sample code below with your own.
- animal *Cat, *Dog;
- Cat = new animal;
- Dog = new animal;
- Cat->SetName("Cat");
- Cat->legs = 4;
- Dog->SetName("Dog");
- Dog->legs = 4;
- Console::WriteLine("Animal 1");
- Console::Write("Name ");
- Console::WriteLine(Cat->GetName());
- Console::Write("Legs ");
- Console::WriteLine(Cat->legs);
- Console::WriteLine();
- Console::WriteLine("Animal 2");
- Console::Write("Name ");
- Console::WriteLine(Dog->GetName());
- Console::Write("Legs ");
- Console::WriteLine(Dog->legs);
- Console::WriteLine();
- return 0;
- }