《程序设计基础二》第一阶段“类的设计部分“练习题目:1432--1446

Problem 1440. -- 类的设计(9)---国家类Country

1440: 类的设计(9)---国家类Country

Time Limit: 10 Sec  Memory Limit: 65535 MB   64bit IO Format: %lld
Submitted: 896  Accepted: 618
[Submit][Status][Web Board]

Description

设计国家类Country,包含国名(char name[40])、首都(char capital[40])和人口数量(int Population)。根据给定的main函数设计必要的成员函数。main函数已给定,提交时只需要提交main函数外的代码部分。

int main()
{
    Country c1,c2("中国","北京",1400000000);
    cout<<"Country1:"<<c1.GetName()<<"-"<<c1.GetCapital()<<"-"<<c1.GetPopulation()<<endl;
    cout<<"Country2:"<<c2.GetName()<<"-"<<c2.GetCapital()<<"-"<<c2.GetPopulation()<<endl;
    c1.Set("美国","华盛顿",319000000);
    c2.Set("俄罗斯","莫斯科",143000000);
    cout<<"Country3:"<<c1.GetName()<<"-"<<c1.GetCapital()<<"-"<<c1.GetPopulation()<<endl;
    cout<<"Country4:"<<c2.GetName()<<"-"<<c2.GetCapital()<<"-"<<c2.GetPopulation()<<endl;
    c1.Set("日本","东京",126910000);
    c2.Set("德国","柏林",80800000);
    cout<<"Country5:"<<c1.GetName()<<"-"<<c1.GetCapital()<<"-"<<c1.GetPopulation()<<endl;
    cout<<"Country6:"<<c2.GetName()<<"-"<<c2.GetCapital()<<"-"<<c2.GetPopulation()<<endl;
    return 0;
}

Sample Output

Country1:NULL-NONE-0
Country2:中国-北京-1400000000
Country3:美国-华盛顿-319000000
Country4:俄罗斯-莫斯科-143000000
Country5:日本-东京-126910000
Country6:德国-柏林-80800000

[Submit][Status][Web Board]