课本上最基础的题,我不会做

jbzj 2005-07-26 06:31:15
有四个圆塔,圆心分别为(2,2),(-2,2),(-2,-2),(2,-2),圆半径为1。这四个圆塔的高度为10米,塔以外无建筑物。今输入任一点的坐标,求该点的建筑高度。

请大家帮我一下啊!
...全文
154 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
DuoFG 2005-07-26
  • 打赏
  • 举报
回复
main()
{
int h=10;
float x1=2,y1=2,x2=-2,y2=-3,x3=-2,y3=-2,x4=2,y4=-2,x,y,d1,d2,d3,d4;
printf("enter a point(x,y):");
scanf("%f,%f",&x,&y);
d1=(x-x1)*(x-x1)+(y-y1)*(y-y1);
d2=(x-x2)*(x-x2)+(y+y2)*(y+y2);
d3=(x+x3)*(x+x3)+(y-y3)*(y-y3);
d4=(x+x4)*(x+x4)+(y+y4)*(y+y4);
if(d1>1&&d2>1&&d3>1&&d4>1)
h=0;
printf("gaodu=%d",h);
}
K 2005-07-26
  • 打赏
  • 举报
回复
我寒一下楼上的,你不会发个帖子?
softheaven 2005-07-26
  • 打赏
  • 举报
回复
问提提出者提的是老谭书上面的一道题,不过我不是想解决这道题的。我写了个摸拟的栈---类。
还请高手修改一下不错之处,指点一下我在此编程中,暴露出的问题。谢了我先有礼了。// 本文来自铁道P246,;
//设计一个栈结构体的类,栈内存放的数据是三个字母的字符串(AAA,BCC,ABZ,KIS..)
//数据成员包括栈本身(stack),栈大小(size),及目前顶端位(top);
//成员函数则可以处埋栈内的数据引用,包括加入栈add(),从堆栈中删除delete(),
//检查堆栈是否已满IsFull(),检查堆栈是否已空等IsEmpty(),当然还有构造函数。
//测试时,可以写一段主程序main(),定义一个栈象,并对此对像做加入堆栈,
//删除栈的操作,提示:加入堆栈时,要考栈是否已满,且必须维护值保特在顶端的位置;
//删除栈时,则要考虑栈是否已空,并维护值在顶端位置
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#define FALSE -1
#define TURE 1
class stack
{
public:
stack(int sizeofstack);//构造函数
~stack();//析构函数
int ISFULL(class stack );
int ISEMPTY(class stack); //判断栈中是否为空
void COUTSTACKPT(class stack stacksample);//显示栈的内容
void ADD(char * str); //入栈操作
void POP(class stack stacksample); //弹栈操作
private:
char * stackpoint[20]; //指针数组
int size;
int top;
};
void stack::POP(class stack stacksample) //弹栈操作
{
if(ISEMPTY(stacksample)==FALSE)
{
top--;
}
}
void stack::ADD(char * str) //入栈操作
{

top++;
strcpy(stackpoint[top],str);
}
int stack::ISEMPTY(class stack stacksample)//判断栈是否为空
{
if(top>=0) {return FALSE;}
else {cout <<endl<<"stack is empty";return( TURE);}
}
void stack::COUTSTACKPT(class stack stacksample)//先判断后显示栈的内容
{
if( ISEMPTY(stacksample)==FALSE ) {cout<<stackpoint[top]<<endl;}
else {cout<<"the stack is empty"<<endl;}
}
stack::stack(int sizeofstack )//构造函数申请栈空间
{
int i;
top=-1;
for(i=0;i<sizeofstack;i++)
stackpoint[i]= (char * )new char [i][100];
}

stack::~stack()//析构函数
{
top=-1;
}
void main()
{
int i,stacksize;//初始申请栈的大小
char stacktemp[80];
cout<< "enter the stack's size please :";
cin>>stacksize;
stack t1(stacksize); //构造函数申请栈空间
t1.COUTSTACKPT(t1); //先判断后显示栈内容
for(i=0;i<stacksize;i++) // 入栈
{
cout<<" enter string please :";
cin>> stacktemp;
t1.ADD(stacktemp);
}
cout<<"Befor first pop"<<endl;
t1.COUTSTACKPT(t1);
t1.POP(t1);
cout<<"After pop"<<endl;
t1.COUTSTACKPT(t1);
t1.POP(t1);
cout<<"After pop again"<<endl;
t1.COUTSTACKPT(t1);
t1.POP(t1);
cout<<"After pop 3th"<<endl;
t1.COUTSTACKPT(t1);
t1.POP(t1);
cout<<"After pop 4th"<<endl;
t1.COUTSTACKPT(t1);
}
neulxg 2005-07-26
  • 打赏
  • 举报
回复
如果是圆柱的话,就是判断点的问题了。即如果某一点的坐标(x,y)符合以下方程:(x-2)^2+(y-2)^=1 or (x-2)^2+(y+2)^2=1 or (x+2)^+(y+2)^2=1 or (x+2)^2+(y-2)^2=1 的时候,该点的H就为10m。如果是圆锥的话,还得知道圆锥方程,按上面方法做判断就可以了
jixingzhong 2005-07-26
  • 打赏
  • 举报
回复
就是判断点在的范围...




我还不是很明白...

三维的?

圆柱 ? 圆锥??

69,374

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧