C++高手救急!!!

作者&投稿:徒彼 (联系方式在网页底部的电邮联系)
求C++高手救急!!!十万火急!~

#include "stdio.h"
#include "math.h"

class Shape
{
public:
char m_shape;
double s; //面积
virtual void Cal_area(){};
};

class Circle :public Shape
{
public:
Circle(double x,double y,double r)
{
this->m_shape = 'c';
this->r = r;
this->x = x;
this->y = y;
}
double x,y;
double r;
virtual void Cal_area()
{
s=3.14*r*r;
}

};

class Rectangle :public Shape
{
public:
Rectangle(double x,double y,double width,double height)
{
this->m_shape = 'r';
this->x = x;
this->y = y;
this->width = width;
this->height= height;

}
double x,y, width,height;
virtual void Cal_area()
{
s=width*height;
}
};

class Triangle:public Shape
{
public :
Triangle(double x1,double y1,double x2,double y2,double x3,double y3)
{
this->m_shape = 't';
this->x1 = x1;
this->y1 = y1;
this->x2 = x2;
this->y2 = y2;
this->x3 = x3;
this->y3 = y3;
}

double x1,y1,x2,y2,x3,y3;
virtual void Cal_area()
{
double d1 = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
double d2 = sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
double d3 = sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
double p=(d1+d2+d3)/2;
s=sqrt(p*(p-d1)*(p-d2)*(p-d3));
}
};

void main()
{
Shape *shape[20];
char cType;
double x,y,r,width,height,x1,y1,x2,y2,x3,y3;
scanf("%c",&cType);
int i=0;

while(cType!='x')
{
switch(cType)
{
case 'c':
scanf("%lf",&x);
scanf("%lf",&y);
scanf("%lf",&r);
shape[i]= new Circle(x,y,r);
i++;
break;
case 'r':
scanf("%lf",&x);
scanf("%lf",&y);
scanf("%lf",&width);
scanf("%lf",&height);
shape[i]= new Rectangle(x,y,width,height);
i++;
break;
case 't':
scanf("%lf",&x1);
scanf("%lf",&y1);
scanf("%lf",&x2);
scanf("%lf",&y2);
scanf("%lf",&x3);
scanf("%lf",&y3);
shape[i]= new Triangle(x1,y1,x2,y2,x3,y3);
i++;
break;
}
scanf("%c",&cType);
}
int j=0;
while(j<i)
{
shape[j]->Cal_area();
printf("s=%.2lf",shape[j]->s);
if(shape[j]->m_shape == 'c')
{
printf(" r=%.2lf",((Circle*)shape[j])->r);
}
printf("
");
j++;
}

}

#include

using namespace std;

class Shap{public: virtual double getArea() = 0;};class Rectangle: public Shap{protected: double x,y;public: Rectangle(double a = 0,double b = 0):x(a),y(b){} virtual double getArea() {return x * y;}};class Circle: public Shap{protected: double r;public : const static double PI; Circle(double r = 0){this->r = r;} virtual double getArea(){return PI * r * r;}};const double Circle::PI = 3.14;

int main(){ Shap *shaps[4];

shaps[0] = new Rectangle(1,1); shaps[1] = new Circle(10); shaps[2] = new Rectangle(5,10); shaps[3] = new Circle(1);

double areaSum = 0; for(int i = 0;i getArea(); cout getArea() << endl; delete shaps[i]; }

return 0;}

#include

using namespace std;

templateT Sum(T* arr,int size){ T total = 0; for(int i = 0;i < size;++i) { total += arr[i]; } return total;}

int main(){ int arr1[5] = {1,2,3,4,5}; double arr2[5] = {1.1,2.1,3.1,4.1,5.1};

cout << "The sum of arr1: " << Sum(arr1,sizeof(arr1)/sizeof(int)) << endl; cout << "The sum of arr2: " << Sum(arr2,sizeof(arr2)/sizeof(double)) << endl;

return 0;}


main函数你自己写就可以了

#define queueSIZE 3 这一行的queueSIZE改成QUEUESIZE即可编译通过

#include<iostream>
#define STACKSIZE 3
#define queueSIZE 3
using namespace std;

//stack
struct stack{
int top;
int items[STACKSIZE];
};

void init(struct stack * a_stack)
{
a_stack->top=0;
}

int isFull(struct stack * a_stack)
{
if(a_stack->top<STACKSIZE)
return 0;
else
return 1;
}

void push(struct stack * a_stack,int item)
{
a_stack->items[a_stack->top]=item;
a_stack->top++;

}

int isEmpty(struct stack * a_stack)
{
if (a_stack->top<=0)
return 1;
else
return 0;
}

int pop(struct stack * a_stack)
{

a_stack->top--;
return a_stack->items[a_stack->top];

}

void showstack(struct stack * a_stack)
{
int i;
cout<<"value of top %d\n"<<a_stack->top;
for(i=0;i<a_stack->top;i++)
{
cout<<"position %3d value %5d \n"<<i<<a_stack->items[i];
}
}
//stack end

//queue
struct queue{
int top;
int items[queueSIZE];
};

void init(struct queue * a_queue)
{
a_queue->top=0;
}

int isFull(struct queue * a_queue)
{
if(a_queue->top<queueSIZE)
return 0;
else
return 1;
}

void push(struct queue * a_queue,int item)
{
a_queue->items[a_queue->top]=item;
a_queue->top++;

}

int isEmpty(struct queue * a_queue)
{
if (a_queue->top<=0)
return 1;
else
return 0;
}

int pop(struct queue * a_queue)
{
int tmp=a_queue->items[0];

for(int i=0;i<a_queue->top-1;i++)
a_queue->items[i]=a_queue->items[i+1];

a_queue->top--;
return tmp;

}

void showqueue(struct queue * a_queue)
{
int i;
cout<<"value of top %d\n"<<a_queue->top;
for(i=0;i<a_queue->top;i++)
{
cout<<"position %3d value %5d \n"<<i<<a_queue->items[i];
}
}
//queue end
int main()
{
int number;
struct stack a_stack;
//int a_value;
int item;

init(&a_stack);

do{

cout<<"1.push"<<endl
<<"2.pop" <<endl
<<"3.showstack"<<endl
<<"4.exit"<<endl
<<"please input a number"<<endl;

cin>>number;

switch(number)
{
case 1:
if(isFull (&a_stack))
cout<<"Sorry,the stack is full !\n";
else
{
cout<<"input a number: ";
cin>>item;
push(&a_stack,item);}
break;
case 2:
if(isEmpty (&a_stack))
cout<<"sorry,the stack is empty !\n";
else
cout<<"you get: "<<pop(&a_stack)<<endl;
break;
case 3:
showstack(&a_stack);
break;
case 4:
return 0;
}
}while(1);

return 0;

}

已经OK了 完全可以运行 并且结果正确

#include<iostream>
#define STACKSIZE 3
#define QUEUESIZE 3
using namespace std;

//stack
struct stack{
int top;
int items[STACKSIZE];
};

void init(struct stack * a_stack)
{
a_stack->top=0;
}

int isFull(struct stack * a_stack)
{
if(a_stack->top<STACKSIZE)
return 0;
else
return 1;
}

void push(struct stack * a_stack,int item)
{
a_stack->items[a_stack->top]=item;
a_stack->top++;

}

int isEmpty(struct stack * a_stack)
{
if (a_stack->top<=0)
return 1;
else
return 0;
}

int pop(struct stack * a_stack)
{

a_stack->top--;
return a_stack->items[a_stack->top];

}

void showstack(struct stack * a_stack)
{
int i;
printf("value of top %d\n",a_stack->top);
for(i=0;i<a_stack->top;i++)
{
printf("position %3d value %5d \n",i,a_stack->items[i]);
}
}
//stack end

//queue
struct queue{
int top;
int items[QUEUESIZE];
};

void init(struct queue * a_queue)
{
a_queue->top=0;
}

int isFull(struct queue * a_queue)
{
if(a_queue->top<QUEUESIZE)
return 0;
else
return 1;
}

void push(struct queue * a_queue,int item)
{
a_queue->items[a_queue->top]=item;
a_queue->top++;

}

int isEmpty(struct queue * a_queue)
{
if (a_queue->top<=0)
return 1;
else
return 0;
}

int pop(struct queue * a_queue)
{
int tmp=a_queue->items[0];

for(int i=0;i<a_queue->top-1;i++)
a_queue->items[i]=a_queue->items[i+1];

a_queue->top--;
return tmp;

}

void showqueue(struct queue * a_queue)
{
int i;
cout<<"value of top %d\n"<<a_queue->top;
for(i=0;i<a_queue->top;i++)
{
cout<<"position %3d value %5d \n"<<i<<a_queue->items[i];
}
}
//queue end
int main()
{
int number;
struct stack a_stack;
int a_value;
int item;

init(&a_stack);

do{

cout<<"1.push"<<endl
<<"2.pop" <<endl
<<"3.showstack"<<endl
<<"4.exit"<<endl
<<"please input a number"<<endl;

cin>>number;

switch(number)
{
case 1:
if(isFull (&a_stack))
cout<<"Sorry,the stack is full !\n";
else
{
cout<<"input a number: ";
cin>>item;
push(&a_stack,item);}
break;
case 2:
if(isEmpty (&a_stack))
cout<<"sorry,the stack is empty !\n";
else
cout<<"you get: "<<pop(&a_stack)<<endl;
break;
case 3:
showstack(&a_stack);
break;
case 4:
return 0;
}
}while(1);

return 0;

}

--------------------Configuration: a - Win32 Debug--------------------
Compiling...
3.cpp
D:\zylC++\a\3.cpp(65) : error C2065: 'QUEUESIZE' : undeclared identifier
D:\zylC++\a\3.cpp(65) : error C2057: expected constant expression
D:\zylC++\a\3.cpp(65) : warning C4200: nonstandard extension used : zero-sized array in struct/union
执行 cl.exe 时出错.

相关视频

哪位高手给我讲解下导数的算法,救急啊!!!
求导数的方法 (1)利用定义求函数y=f(x)在x0处导数的步骤:① 求函数的增量Δy=f(x0+Δx)-f(x0)② 求平均变化率 ③ 取极限,得导数。(2)几种常见函数的导数公式:① C'=0(C为常数函数)② (x^n)'= nx^(n-1)(n∈Q*);熟记1\/X的导数 ③ (sinx)'= cosx (cosx)'= - sinx

c 高手 进
char c;float f;} 以下语句正确的是:A x = 10.5; B x.c = 101; C y = x; D printf("%d",x);共用体union 千万记住:共用一块内存 根据 .运算符 访问的数据类型来决定写入的数据。如union data x;x.f=10.5;\/\/f为float,所以写入4个字节 x.c=32;\/\/c为char,写入1个字节...

英语各路高手江湖救急, 小弟无上拜谢!!!
She was talking about her ___C___ as a nurse in a hospital, which we had never heard of.她在谈论她在医院做护士的经历 A. expenses B. excuses C. experiences D. expressions I have no doubt __A___ most of the students in our class can pass the final examination...

C语言的高手请进,有事请叫你们!
你是要分析这个执行过程吧.在printf中调用了fun(4)所以就调用fun(4),判断执行 else 中的return语句,但return中有fun(n-1)= f(3),所以f(4)还不能返回,得先执行f(3),这里又f(4)还等待f(3)返回后再返回 .执行f(3)也是再开空间来计算,不影响f(4)的空间.在f(3)中同样的是执行f(3)中...