星际战甲aoe:悬赏80积分,哪位大哥帮忙做下这3个C++题呀,谢谢了!

来源:百度文库 编辑:高考问答 时间:2024/04/27 23:46:02
1:从键盘输入10个正整数并累加求和,把求和结果显示出来!
2:定义一个类,实现求两整数的最小公倍数的功能,在主函数中定义此类的对象,输出该对象的最小公倍数!
3:存在一个类 Person,它的数据成员包括姓名,性别,年龄;建立派生类Student,继承PersonL类,增加数据有;学号和成绩在主函数中定义一个学生对象,输出这个对象的信息!
感激不尽!!

#include <stdio.h>
1.
void main()
{
int i,n,s=0;
for ( n=0;n<10;n++)
{
scanf("%d",&i);
s+=i;
}
printf("%d",s);
}

2.#include <stdio.h>

class A{
public:
int x;
int y;
int getMin()
{
int temp;
if(x) { temp=x;
x=y;
y=temp;
}
int a=x;int b=y;
while(b!=0)/*利用辗除法,直到b为0为止*/
{
temp=a%b;
a=b;
b=temp;
}
return x*y/a;
};
};

void main()
{
A a;
a.x=6;
a.y=9;
printf("%d\n",a.getMin());
}

最后一个自己写吧

自己多动动脑子啊。看书就应该会写了,这个挺简单的。

好好学习
天天向上

呵呵~~~网络有好有坏啊!