求哪位高手帮我编一道C++题,题目自拟。

发布时间:2024-05-21 13:50 发布:上海旅游网

问题描述:

请您按下面格式写一下啊!
一:题目名称。
二:问题描述。
三:问题分析。
四:解决方案:1.算法设计。 2.数据结构设计。
五:程序代码(最好有注释,怕看不懂)
谢谢!:)
点,圆,圆柱体层次分析那个回答也没有关于圆柱体的啊 还有 怎么没有主程序 还有谁帮帮忙啊

问题解答:

1:考察点,圆,圆柱体的层次结构;
2:设计程序输入坐标点数据,对半径置值,求面积
3:(a)首先定义点类point,然后从point类派生圆类,最后从circle类派生圆柱体类cylinder;(b)point类数据成员x,y定义为保护成员,便于培生类直接使用,而不需要通过成员函数;
4:
//circle.h
#ifndef CIRCLR_H
#define CIRCLE_H
class Circle:public Point
{ friend ostream&operator<<(ostream&,const Circle &);//友员函数//
public:
circle(double r=0.0,int x=0,y=0;);//构造函数//
void setRadius(double);//置半径值//
double area()const;//返回面积//
protected:
double radius;//成员数据,半径//
};//带初始化式构造函数,首先调用基类构造函数//
circle::circle(double r,int a,b):point(a,b)
{setRadius(r)};//对半径置值//
void circle::setRadius(double r)
{radius=(r>=0?r:0);}//返回半径值//
double circle::getradius()const{return radius;)}//计算并返回面积//
double circle::area()const
{return 3.14159 * radius * radius;}//输出圆心坐标和半径值//
ostream & operator<<(ostream & output,const circle&c)
{output<<"center="<<'['<<c.x<<","<<c.y<<"]"<<";radius="
<<setiosflags(ios::fixed|ios::showpoint)<<setprecision(2)<<c.radius;
return output;
}
#enddif

不 太清楚

那算谁 的 ???

你 我 他???

鄙视

题目:时间函数举例4(一个猜数游戏,判断一个人反应快慢)。

程序源代码:
#include "time.h"
#include "stdlib.h"
#include "stdio.h"
main()
{char c;
clock_t start,end;
time_t a,b;
double var;
int i,guess;
srand(time(NULL));
printf("do you want to play it.('y' or 'n') \n");
loop:
while((c=getchar())=='y')
{
i=rand()%100;
printf("\nplease input number you guess:\n");
start=clock();
a=time(NULL);
scanf("%d",&guess);
while(guess!=i)
{if(guess>i)
{printf("please input a little smaller.\n");
scanf("%d",&guess);}
else
{printf("please input a little bigger.\n");
scanf("%d",&guess);}
}
end=clock();
b=time(NULL);
printf("\1: It took you %6.3f seconds\n",var=(double)(end-start)/18.2);
printf("\1: it took you %6.3f seconds\n\n",difftime(b,a));
if(var<15)
printf("\1\1 You are very clever! \1\1\n\n");
else if(var<25)
printf("\1\1 you are normal! \1\1\n\n");
else
printf("\1\1 you are stupid! \1\1\n\n");
printf("\1\1 Congradulations \1\1\n\n");
printf("The number you guess is %d",i);
}
printf("\ndo you want to try it again?(\"yy\".or.\"n\")\n");
if((c=getch())=='y')
goto loop;
}

期未了~~~

热点新闻