且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何一次读取一组char条目并打印结果

更新时间:2022-12-26 20:15:47

你的班级只需要几件事:国家名称,人口及其面积。

您的外部代码从用户读取名称,填充和大小,并使用该信息构造类的实例(使用带有三个参数的构造函数) 。你的班级决不应该直接与用户互动 - 这不是它的工作。



然后外部代码构造一个国家实例数组,它从中填充用户然后通过查看数组来检查每个类别中最大的 - 您可能添加到您班级的唯一帮助者是计算人口和区域的人口密度。



但这是你的作业,所以我不会给你任何代码!尝试一下,你会发现它比你正在尝试的更容易。
Your class need only a couple of things: the Country Name, population, and it's area.
Your external code reads the name, population, and size from the user and uses that information to construct an instance of the class (using a constructor which takes three parameters). At no time should your class interact directly with the user - that's not its job.

The external code then constructs an array of "country" instances which it populates from the user and and then examine to find the largest in each category by looking at the array - the only "helper" you might add to your class is to calculate the population density from the population and the area.

But this is your homework, so I'll give you no code! Give it a try, and you'll see that it's a easier to do it that way than what you are trying.