ROBERT 发表于 2004-11-4 12:34:00

c++

#include <math.h>
void index(int a[];int n;int &sub;)
{
int i ;
for (i=0;i<=n;i++;)
{if( a=&sub)&sub=i;}
if (i>n)&sub=-1;
}

void main ()
{
int g,i,m,h;
printf("数组个数为:\n");
scanf("%d",&g);
int b;
printf("请输入%d个整数:\n",g);
for (i=0;i<=g;i++;)
b=scanf("%d",m);
printf("要查找的数为:\n");
scanf("%d",&h);
index(b,g,h);
if(h=-1)printf("该数组中有 %d\n",h);
else if (h!=-1)printf("该数组中没有 %d\n",h);
}

ROBERT 发表于 2004-11-4 15:17:00

c++

<P>#include&lt;iostream.h&gt;
#include&lt;math.h&gt;
double area(double radius=0){
double s ;
s=radius*radius*3.14;
return(s);
}</P><P> double area(double a=0,double b=0)
{
double s;
s=a*b;
return(s);
}

void main(){
double s1,s2,s3,s4,r,a,b;
cout&lt;&lt;"圆的半径为:";
cin&gt;&gt;r;
s1=area(r);
cout&lt;&lt;"圆的面积为:"&lt;&lt;s1&lt;&lt;endl;
   cout&lt;&lt;"矩形的长为:";
   cin&gt;&gt;a;
   cout&lt;&lt;"矩形的宽为:";
   cin&gt;&gt;b;
    s2=area(a,b);
cout&lt;&lt;"矩形的面积为:"&lt;&lt;s2&lt;&lt;endl;</P><P>
}</P>

游侠无极限 发表于 2004-11-4 17:13:00

<P>?我认为你用的变量太多了……</P><P>发这个干什么?</P>

游侠无极限 发表于 2004-11-4 18:05:00

<P>本来想写个试试,可为什么Dev-cpp会提示我Rectangle未定义?奇怪</P><P>VC7就很顺利?</P><P>#include &lt;iostream&gt;
#include &lt;stdlib.h&gt;</P><P>#define PI 3.14
using namespace std;</P><P>class Shape
{
private:
double m_width;
double m_height;
public:
Shape(){};
~Shape(){};
void SetWidth(double w = 0){m_width = w;};
void SetHeight(double h = 0){m_height = h;};
double GetWidth(void){return m_width;};
double GetHeight(void){return m_height;};
virtual double GetArea(void) = 0;
};</P><P>class Rectangle : public Shape
{
public:
Rectangle(){};
~Rectangle(){};
virtual double GetArea(void){return GetWidth()*GetHeight();};
};</P><P>class Circle : public Shape
{
public:
Circle(){};
~Circle(){};
virtual double GetArea(void){return GetWidth()*GetWidth()*PI;};
void SetRadius(double r = 0){SetWidth(r);};</P><P>};</P><P>// ------------------------------------------------
// 主函数过程
// ------------------------------------------------
int main(int argc, char *argv[])
{
Rectangle re;</P><P> Circle ci;
Shape *p1 = &amp;re,*p2 = &amp;ci;
re.SetHeight(20);
re.SetWidth(10);
ci.SetRadius(12);
cout &lt;&lt; "矩形面积:" &lt;&lt; p1-&gt;GetArea() &lt;&lt; endl;
cout &lt;&lt; "圆形面积:" &lt;&lt; p2-&gt;GetArea() &lt;&lt; endl;</P><P> system("PAUSE");
return 0;
}</P>
页: [1]
查看完整版本: c++