国际标准计量单位,这是一个C

问题1:警告 1 warning C4490: “override”:
重写说明符的用法不正确;“Height::Tostring”与 ref
基类方法不匹配 e:\Visual Studio
2005\Projects\Ex7_16\Ex7_16.cpp 30 

using System;

1英美制

问题2:自己的理想结果:He is Fred
his Weight is 185 pounds 7 ounces.
his height is 6 feet 3 inches which is 1.91 meters.
运行的结果就最后一句不同.

class Person

长度

 

{

英寸inch(pl.inches)=2.5400limi厘米 英尺foot(pl.feet)=12英寸=0.3048米
码yard=3英尺=0.9144米 英里mile=1760码=1.6093公里

代码如下:

// 一个字段不加访问控制 默认是 private

水程长度

#include “stdafx.h”

// private 修饰的字段只能在本类中使用

链cable length,cable’s length=185.2米 海里sea mile=10链=1.852公里

using namespace System;

private string _name;

地积

value class Height
 {
 private:
  int feet;
  int inches;

private int _age;

英亩acre=40.4686公亩

  literal int inchesPerFoot=12;
  literal double inchesToMeters=2.54/100;
 public:
  Height(int ins)
  {
   feet=ins/inchesPerFoot;
   inches=ins%inchesPerFoot;
  }
CA88新登入,  Height(int ft,int ins):feet(ft),inches(ins){}

private float _height;

重量

  property double meters
  {
   double get()
   {
    return inchesToMeters*(feet*inchesPerFoot+inches);
   }
  }
  virtual String^ Tostring() override
  {
   return feet+L”feet”+inches+L”inches”;
  }
 };
 value class Weight
 {
  private:
            int lbs;
            int oz;

private float _price;

盎司ounce=28.3496克 磅pound=16盎司=0.4539千克 长吨long ton=2240磅
短吨=1016.0470千克 1短吨=907.1849千克

            literal int ouncePerPound=16;
            literal double lbsToKg=1.0/2.2;
public:
 Weight(int pounds,int ounces)
 {
  lbs=pounds;
  oz=ounces;
 }
 property int pounds
 {
  int get()
  {
   return oz;
  }
  void set(int value)
  {
   lbs=value;
  }
 }
 property double kilograms
 {
  double get()
  {
   return lbsToKg*(lbs+oz/ouncePerPound);
  }
 }
 virtual String^ Tostring() override
 {
  return lbs+L”pounds”+oz+L”ounces”;
 }
 };
 ref class Person
 {
 private:
  Height ht;
  Weight wt;
 public:
  property String^ Name;
  Person(String^ name,Height h,Weight w):ht(h),wt(w)
  {
   Name=name;
  }
  Height getHeight()
  {
   return ht;
  }
  Weight getWeight()
  {
   return wt;
  }
 };

private float _weight;

液量

int main(array<System::String ^> ^args)
{
    Weight hisWeight=Weight(185,7);
 Height hisHeight=Height(6,3);
 Person^his=gcnew Person(L”Fred”,hisHeight,hisWeight);

private bool _girl;

加伦gallon=4.546升=3.785升

 Weight herWeight=Weight(105,3);
 Height herHeight=Height(5,2);
 Person^her=gcnew Person(L”Freda”,herHeight,herWeight);

private string _address;

2公制

 Console::WriteLine(L”Shi is {0}”,her->Name);
 Console::WriteLine(L”Her Weight is {0:F2}
kilograms.”,her->getWeight().kilograms);
 Console::WriteLine(L”Her Height is {0} which is {1:F2}
meters.”,her->getHeight(),her->getHeight().meters);

private int _IDnumber;

长度

 Console::WriteLine(L”He is {0}”,his->Name);
 Console::WriteLine(L”His Weight is {0:F2}
kilograms.”,his->getWeight().kilograms);
 Console::WriteLine(L”His Height is {0} which is {1:F2}
meters.”,his->getHeight(),his->getHeight().meters);

public int IDNumber {

毫米millimeter(mm)=0.001米 厘米centimeter(cm)=0.01米 米meter(m)
公里kilometer(km)=1000米 1厘米=0.3937英寸 1米=3.2808英尺
1公里=0.6214英里

}

set {

地积

_IDnumber = value;

公亩are(a)=100平方米 公顷hectare(ha)=100公亩 1公亩=0.0247英亩
1公顷=2.4711英亩

}

容积

get {

毫升milliliter(ml)=0.001升 升liter(l) 1升=0.2600加伦=0.2600加伦

return _IDnumber;

重量

}

毫克milligram(mg)=0.001克 克gram(g) 千克kilogram(kg)=1000克
公吨ton(t)=1000千克 1克=0.0352盎司 1千克=2.2046磅 1公吨=0.9842长吨
1公吨=1.1023短吨

}

public string Address {

set {

_address = value;

}

get {

return _address;

}

}

public bool Girl {

set {

_girl = value;

}

get {

return _girl;

}

}

public float Weight {

set {

_weight = value;

}

get {

return _weight;

}

}

public float Price {

set;

get;

}

// 属性

public string Name {

set {

_name = value;

}

get {

return _name;

}

}

// 一个字段想让外界访问要提供 方法

// 存

// public void SetName (string name)

// {

// // this 后面的就是字段

// this.name = name;

// _name = name;

// // 取

// public string GetName ()