找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 294|回复: 7

[求助]一个最简分数的程式设计问题.拜托帮帮忙

[复制链接]
发表于 2009-11-2 05:07:25 | 显示全部楼层 |阅读模式 IP:江苏扬州
我是一个初学者 很多东西我读到现在还是没有概念...
以下是我们老师派的一个问题...我去找过一些范例..但是我还是做不出来..
希望有人可以帮帮我..给点提示..或是弄个类似的给我参考都行...拜托各位帮帮忙..

Define a class for a type called Fraction. This class is used to represent a ratio of two integers. Include mutator functions that allow the user to set the numerator and the denominator. Also include a member function that returns the value of numerator / denominator as a double. Include an additional member function that outputs the value of the fraction reduced to lowest terms, e.g. instead of outputting 20/60 the method should output 1/3. This will require finding the greatest common divisor for the numerator and denominator, and then dividing both by that number. Embed your class in a test program.
int main()
{
// Some test fractions
Fraction f1, f2;
f1.setNumerator(4);
f1.setDenominator(2);
cout << f1.getDouble() << endl;
f1.outputReducedFraction();
cout << endl;
f2.setNumerator(20);
f2.setDenominator(60);
cout << f2.getDouble() << endl;
f2.outputReducedFraction();
cout << endl;
}
发表于 2009-11-2 05:07:30 | 显示全部楼层 IP:江苏扬州
让你根据main建立类吗?
回复

使用道具 举报

发表于 2009-11-2 05:07:34 | 显示全部楼层 IP:江苏扬州
我自己也弄不清楚阿.....<<~刚学c++不久的大一学生...连基础都弄不好= =....英文超差.....
不过有同学教我用
void Fraction::setNumerator(int C) //带入分子
{ Numerator = C; }
void Fraction::setDenominator(int D) //带入分母
{ Denominator = D; }
double Fraction::getDouble() //传回计算后的值
{
return (static_cast<double>(Numerator) / static_cast<double>(Denominator)); }

不过我还是不太懂.......抱歉@@...
回复

使用道具 举报

发表于 2009-11-2 05:07:40 | 显示全部楼层 IP:江苏扬州
你的题目你不知道啊?

最好把英语搞成中文

我看着英语头疼..呵呵
回复

使用道具 举报

发表于 2009-11-2 05:07:52 | 显示全部楼层 IP:江苏扬州
搞成中文阿...大致上我也只知道是要写个程式把题目给的分数弄成最简分数...
详细的我也看不懂...汗...
真是抱歉...
翻译软体的更是惨不忍睹..自己按字典的是文意连接不起来....
回复

使用道具 举报

发表于 2009-11-2 05:07:58 | 显示全部楼层 IP:江苏扬州
俺知道了...哈哈

这个不难...

不过我现在要下了.

提示你下...创建个类.setNumerator()处理分母.setDenominator()处理分子;getDouble()这个应该是约分的~

约分有条件控制...找最大公约数. 也可以考虑用递归
回复

使用道具 举报

发表于 2009-11-2 05:08:04 | 显示全部楼层 IP:江苏扬州
谢谢师妃暄大姐 小弟我再努力....
我去试试...
回复

使用道具 举报

发表于 2009-11-2 05:08:10 | 显示全部楼层 IP:江苏扬州
http://www.youtube.com/watch?v=lP-94IgHoOo

这首改编的歌..真是让学程式设计的人有很大的共鸣阿....
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 03:28 , Processed in 0.203578 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表