c++
#include <math.h>void index(int a[];int n;int ⊂)
{
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);
}
c++
<P>#include<iostream.h>#include<math.h>
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<<"圆的半径为:";
cin>>r;
s1=area(r);
cout<<"圆的面积为:"<<s1<<endl;
cout<<"矩形的长为:";
cin>>a;
cout<<"矩形的宽为:";
cin>>b;
s2=area(a,b);
cout<<"矩形的面积为:"<<s2<<endl;</P><P>
}</P> <P>?我认为你用的变量太多了……</P><P>发这个干什么?</P> <P>本来想写个试试,可为什么Dev-cpp会提示我Rectangle未定义?奇怪</P><P>VC7就很顺利?</P><P>#include <iostream>
#include <stdlib.h></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 = &re,*p2 = &ci;
re.SetHeight(20);
re.SetWidth(10);
ci.SetRadius(12);
cout << "矩形面积:" << p1->GetArea() << endl;
cout << "圆形面积:" << p2->GetArea() << endl;</P><P> system("PAUSE");
return 0;
}</P>
页:
[1]