c++中头文件错误
#include<iostream>#include<math>usingnamespacestd;classgrap//定义基类图形类{public://公有函数成员g...
#include<iostream>
#include<math>
using namespace std;
class grap // 定义基类图形类
{
public: // 公有函数成员
grap (int wid){width = wid;}
float area(){}
float peri(){}
int getWidth(){return width;}
private: // 私有数据成员
int width; // 宽度或半径
};
class Rectangle:public grap{ // 定义矩形类
int height;
public:
Rectangle(int wid, int hei):grap(wid){
height = hei;
}
float area(){return getWidth() * height;}
float peri(){return getWidth()*2+2*height;}
};
class Triangle:public grap{ // 定义三角形类
int side1;
int side2;
public:
Triangle(int wid, int side1,side2):grap(wid){
side1=side1;
side2=side2;
}
float area(){return sqrt(0.5*(wid+side1+side2)(0.5*(wid+side1+side2)-wid)(0.5*(wid+side1+side2)-side1)(0.5*(wid+side1+side2)-side2));}
float peri(){return wid+side1+side2;}
};
class Circle:public grap{ // 定义圆类
public:
Circle(int wid):grap(wid){
}
float area(){return 3.14 * getWidth() * getWidth();}
float peri(){return 2*3.14*getWidth();}
};
void main(){
Rectangle rect(7,8);
Triangle tri(2,2,2);
Circle cir(7);
cout<<"矩形的面积是:"<<rect.area()<<endl
<<"矩形的周长是:"<<rect.peri()<<endl
<<"三角形的面积是:"<<tri.area()<<endl
<<"三角形的周长是:"<<tri.peri()<<endl
<<"圆的面积是:"<<cir.area()<<endl
<<"圆的周长是:"<<cir.peri()<<endl;
}
这个程序在编译时提示: Cannot open include file: 'math': No such file or directory。不知道为什么,请高手指点。 展开
#include<math>
using namespace std;
class grap // 定义基类图形类
{
public: // 公有函数成员
grap (int wid){width = wid;}
float area(){}
float peri(){}
int getWidth(){return width;}
private: // 私有数据成员
int width; // 宽度或半径
};
class Rectangle:public grap{ // 定义矩形类
int height;
public:
Rectangle(int wid, int hei):grap(wid){
height = hei;
}
float area(){return getWidth() * height;}
float peri(){return getWidth()*2+2*height;}
};
class Triangle:public grap{ // 定义三角形类
int side1;
int side2;
public:
Triangle(int wid, int side1,side2):grap(wid){
side1=side1;
side2=side2;
}
float area(){return sqrt(0.5*(wid+side1+side2)(0.5*(wid+side1+side2)-wid)(0.5*(wid+side1+side2)-side1)(0.5*(wid+side1+side2)-side2));}
float peri(){return wid+side1+side2;}
};
class Circle:public grap{ // 定义圆类
public:
Circle(int wid):grap(wid){
}
float area(){return 3.14 * getWidth() * getWidth();}
float peri(){return 2*3.14*getWidth();}
};
void main(){
Rectangle rect(7,8);
Triangle tri(2,2,2);
Circle cir(7);
cout<<"矩形的面积是:"<<rect.area()<<endl
<<"矩形的周长是:"<<rect.peri()<<endl
<<"三角形的面积是:"<<tri.area()<<endl
<<"三角形的周长是:"<<tri.peri()<<endl
<<"圆的面积是:"<<cir.area()<<endl
<<"圆的周长是:"<<cir.peri()<<endl;
}
这个程序在编译时提示: Cannot open include file: 'math': No such file or directory。不知道为什么,请高手指点。 展开
5个回答
展开全部
/*
矩形的面积是:56
矩形的周长是:30
三角形的面积是:1.73205
三角形的周长是:6
圆的面积是:153.86
圆的周长是:43.96
请按任意键继续. . .
*/
#include <iostream>
#include <cmath>
using namespace std;
class grap { // 定义基类图形类
private: // 私有数据成员
int width; // 宽度或半径
public: // 公有函数成员
grap (int wid){width = wid;}
float area(){}
float peri(){}
int getWidth(){return width;}
};
class Rectangle:public grap{ // 定义矩形类
private:
int height;
public:
Rectangle(int wid, int hei):grap(wid){ height = hei; }
float area(){return getWidth() * height;}
float peri(){return 2*(getWidth() + height);}
};
class Triangle:public grap{ // 定义三角形类
private:
int side1;
int side2;
public:
Triangle(int wid,int s1,int s2):grap(wid){
side1 = s1;
side2 = s2;
}
float area() {
float p = (getWidth() + side1 + side2)/2;
return sqrt(p*(p - side1)*(p - side2)*(p - getWidth()));
}
float peri(){ return getWidth() + side1 + side2; }
};
class Circle:public grap{ // 定义圆类
public:
Circle(int wid):grap(wid){ }
float area(){return 3.14 * getWidth() * getWidth();}
float peri(){return 2*3.14*getWidth();}
};
int main(){
Rectangle rect(7,8);
Triangle tri(2,2,2);
Circle cir(7);
cout << "矩形的面积是:" << rect.area() << endl;
cout << "矩形的周长是:" << rect.peri() << endl;
cout << "三角形的面积是:" << tri.area() << endl;
cout << "三角形的周长是:" << tri.peri() << endl;
cout << "圆的面积是:" << cir.area() << endl;
cout << "圆的周长是:" << cir.peri() << endl;
return 0;
}
矩形的面积是:56
矩形的周长是:30
三角形的面积是:1.73205
三角形的周长是:6
圆的面积是:153.86
圆的周长是:43.96
请按任意键继续. . .
*/
#include <iostream>
#include <cmath>
using namespace std;
class grap { // 定义基类图形类
private: // 私有数据成员
int width; // 宽度或半径
public: // 公有函数成员
grap (int wid){width = wid;}
float area(){}
float peri(){}
int getWidth(){return width;}
};
class Rectangle:public grap{ // 定义矩形类
private:
int height;
public:
Rectangle(int wid, int hei):grap(wid){ height = hei; }
float area(){return getWidth() * height;}
float peri(){return 2*(getWidth() + height);}
};
class Triangle:public grap{ // 定义三角形类
private:
int side1;
int side2;
public:
Triangle(int wid,int s1,int s2):grap(wid){
side1 = s1;
side2 = s2;
}
float area() {
float p = (getWidth() + side1 + side2)/2;
return sqrt(p*(p - side1)*(p - side2)*(p - getWidth()));
}
float peri(){ return getWidth() + side1 + side2; }
};
class Circle:public grap{ // 定义圆类
public:
Circle(int wid):grap(wid){ }
float area(){return 3.14 * getWidth() * getWidth();}
float peri(){return 2*3.14*getWidth();}
};
int main(){
Rectangle rect(7,8);
Triangle tri(2,2,2);
Circle cir(7);
cout << "矩形的面积是:" << rect.area() << endl;
cout << "矩形的周长是:" << rect.peri() << endl;
cout << "三角形的面积是:" << tri.area() << endl;
cout << "三角形的周长是:" << tri.peri() << endl;
cout << "圆的面积是:" << cir.area() << endl;
cout << "圆的周长是:" << cir.peri() << endl;
return 0;
}
更多追问追答
追问
我想问一下,为什么我编写的那个程序将头文件改成#include #include 怎么还是不行啊?
追答
什么错误信息?
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
math.h是C语言的标准库,C++的话应该是cmath,这样编译就正常了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<iostream>
#include<math.h>
using namespace std;
#include<math.h>
using namespace std;
追问
不行啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
math.h或者 cmath
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
应该是math.h吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询