关于自己写的C++头文件问题,编译过程中出现找不到自己写的头文件

头文件及cpp文件如下://=======================================================================... 头文件及cpp文件如下:
//==============================================================================
// Park.h
//==============================================================================
//定义一个名为Park的类

//声明部分
class Park
{
public:
Park();
void set(float, float);
float area();
float perimeter();
private:
float length;
float width;
};

//实现部分
Park::Park()
{
length = 0.0;
width = 0.0;
} //构造函数初始化变量

void Park::set(float len, float wid)
{
//判断输入的长度和宽带是否都大于零
if (len > 0 && wid > 0)
{
length = len;
width = wid;
}
} //对私有数据成员赋值

float Park::area()
{
return length * width;
} //计算草坪面积函数定义

float Park::perimeter()
{
return (length + width) * 2;
} //计算花园周长函数定义

编译后出现错误:Construction Expense.cpp
c:\users\ringfinger\desktop\c++exam\construction expense.cpp(6) : fatal error C1083: Cannot open include file: 'C:\Users\Ringfinger\Desktop\C++Exam\park': No such file or directory
执行 cl.exe 时出错.

Construction Expense.obj - 1 error(s), 0 warning(s)

//=================================================================================
// Construction Expense.cpp-已知花园长宽求其面积和周长进而求建设费用
//=================================================================================

#include <iostream>
#include "C:\Users\Ringfinger\Desktop\C++Exam\park"

using namespace std;

int main()
{
//定义Park类的变量
Park lawn;

//定义其它类型变量
float lawnlength = 0.0;
float lawnwidth = 0.0;
float lawnarea = 0.0;
float lawnperimeter = 0.0;
float lawnprice = 0.0;
float fenceprice = 0.0;
float totallawnprice = 0.0;
float totalfenceprice = 0.0;
float totalprice = 0.0;

//从外部获得部分变量的初始值
cout << " 输入花园长度:";
cin >> lawnlength;
cout << " 输入花园宽度:";
cin >> lawnwidth;
cout << " 输入草皮每平方米价格:";
cin >> lawnprice;
cout << " 输入栅栏每米价格:";
cin >> fenceprice;

//代入数据
lawn.set(lawnlength, lawnwidth);

//计算花园面积和周长
lawnarea = lawn.area ();
lawnperimeter = lawn.perimeter ();

//计算价格
totallawnprice = lawnarea * lawnprice;
totalfenceprice = lawnperimeter * fenceprice;
totalprice = totallawnprice + totalfenceprice;

//显示面积,周长和价格
cout << fixed
cout.precision (2);
cout << " 花园总面积:" << lawnarea << endl;
cout << " 花园周长:" << lawnperimeter << endl;
cout << " 草皮总价格:" << totallawnprice << endl;
cout << " 栅栏总价格:" << totalfenceprice << endl;
cout << " 建设总费用:" << totalprice << endl;

return 0;
}
展开
 我来答
功学林富晓
2019-10-28 · TA获得超过3万个赞
知道大有可为答主
回答量:1.1万
采纳率:25%
帮助的人:776万
展开全部
#include
<iostream>
#include
"C:\Users\Ringfinger\Desktop\C++Exam\park"
//应该是这里出错,你可以直接写#include
"park.h"就可以了
using
namespace
std;
int
main()
{
//定义Park类的变量
Park
lawn;
//定义其它类型变量
float
lawnlength
=
0.0;
float
lawnwidth
=
0.0;
float
lawnarea
=
0.0;
float
lawnperimeter
=
0.0;
float
lawnprice
=
0.0;
float
fenceprice
=
0.0;
float
totallawnprice
=
0.0;
float
totalfenceprice
=
0.0;
float
totalprice
=
0.0;
//从外部获得部分变量的初始值
cout
<<
"
输入花园长度:";
cin
>>
lawnlength;
cout
<<
"
输入花园宽度:";
cin
>>
lawnwidth;
cout
<<
"
输入草皮每平方米价格:";
cin
>>
lawnprice;
cout
<<
"
输入栅栏每米价格:";
cin
>>
fenceprice;
//代入数据
lawn.set(lawnlength,
lawnwidth);
//计算花园面积和周长
lawnarea
=
lawn.area
();
lawnperimeter
=
lawn.perimeter
();
//计算价格
totallawnprice
=
lawnarea
*
lawnprice;
totalfenceprice
=
lawnperimeter
*
fenceprice;
totalprice
=
totallawnprice
+
totalfenceprice;
//显示面积,周长和价格
cout
<<
fixed
cout.precision
(2);
cout
<<
"
花园总面积:"
<<
lawnarea
<<
endl;
cout
<<
"
花园周长:"
<<
lawnperimeter
<<
endl;
cout
<<
"
草皮总价格:"
<<
totallawnprice
<<
endl;
cout
<<
"
栅栏总价格:"
<<
totalfenceprice
<<
endl;
cout
<<
"
建设总费用:"
<<
totalprice
<<
endl;
return
0;
}
Draconious
2009-11-22 · TA获得超过6242个赞
知道大有可为答主
回答量:2142
采纳率:0%
帮助的人:2582万
展开全部
你头文件的名字是错的。你定义的时候是Park.h,用的时候是park,当然不对,最后要用Park.h才行。而且我不知道你为什么这样引用头文件,如果Park.h和主文件是在同一个文件夹里的话直接用include "Park.h"就可以了,不需要写出全部路径。
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
ahaubit
2009-11-22 · TA获得超过1453个赞
知道小有建树答主
回答量:637
采纳率:0%
帮助的人:772万
展开全部
#include "C:\Users\Ringfinger\Desktop\C++Exam\park"//是这里错,你改成:
#include "C:\Users\Ringfinger\Desktop\C++Exam\park.h"试试.
完整代码:
头文件及cpp文件如下:
//==============================================================================
// Park.h
//==============================================================================
//定义一个名为Park的类

//声明部分
class Park
{
public:
Park();
void set(float, float);
float area();
float perimeter();
private:
float length;
float width;
};

//实现部分
Park::Park()
{
length = 0.0;
width = 0.0;
} //构造函数初始化变量

void Park::set(float len, float wid)
{
//判断输入的长度和宽带是否都大于零
if (len > 0 && wid > 0)
{
length = len;
width = wid;
}
} //对私有数据成员赋值

float Park::area()
{
return length * width;
} //计算草坪面积函数定义

float Park::perimeter()
{
return (length + width) * 2;
} //计算花园周长函数定义

编译后出现错误:Construction Expense.cpp
c:\users\ringfinger\desktop\c++exam\construction expense.cpp(6) : fatal error C1083: Cannot open include file: 'C:\Users\Ringfinger\Desktop\C++Exam\park': No such file or directory
执行 cl.exe 时出错.

Construction Expense.obj - 1 error(s), 0 warning(s)

//=================================================================================
// Construction Expense.cpp-已知花园长宽求其面积和周长进而求建设费用
//=================================================================================

#include <iostream>
#include "C:\Users\Ringfinger\Desktop\C++Exam\park.h"

using namespace std;

int main()
{
//定义Park类的变量
Park lawn;

//定义其它类型变量
float lawnlength = 0.0;
float lawnwidth = 0.0;
float lawnarea = 0.0;
float lawnperimeter = 0.0;
float lawnprice = 0.0;
float fenceprice = 0.0;
float totallawnprice = 0.0;
float totalfenceprice = 0.0;
float totalprice = 0.0;

//从外部获得部分变量的初始值
cout << " 输入花园长度:";
cin >> lawnlength;
cout << " 输入花园宽度:";
cin >> lawnwidth;
cout << " 输入草皮每平方米价格:";
cin >> lawnprice;
cout << " 输入栅栏每米价格:";
cin >> fenceprice;

//代入数据
lawn.set(lawnlength, lawnwidth);

//计算花园面积和周长
lawnarea = lawn.area ();
lawnperimeter = lawn.perimeter ();

//计算价格
totallawnprice = lawnarea * lawnprice;
totalfenceprice = lawnperimeter * fenceprice;
totalprice = totallawnprice + totalfenceprice;

//显示面积,周长和价格
cout << fixed
cout.precision (2);
cout << " 花园总面积:" << lawnarea << endl;
cout << " 花园周长:" << lawnperimeter << endl;
cout << " 草皮总价格:" << totallawnprice << endl;
cout << " 栅栏总价格:" << totalfenceprice << endl;
cout << " 建设总费用:" << totalprice << endl;

return 0;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
林声飘扬
2009-11-22 · TA获得超过1630个赞
知道小有建树答主
回答量:1126
采纳率:50%
帮助的人:960万
展开全部
#include <iostream>
#include "C:\Users\Ringfinger\Desktop\C++Exam\park" //应该是这里出错,你可以直接写#include "park.h"就可以了

using namespace std;

int main()
{
//定义Park类的变量
Park lawn;

//定义其它类型变量
float lawnlength = 0.0;
float lawnwidth = 0.0;
float lawnarea = 0.0;
float lawnperimeter = 0.0;
float lawnprice = 0.0;
float fenceprice = 0.0;
float totallawnprice = 0.0;
float totalfenceprice = 0.0;
float totalprice = 0.0;

//从外部获得部分变量的初始值
cout << " 输入花园长度:";
cin >> lawnlength;
cout << " 输入花园宽度:";
cin >> lawnwidth;
cout << " 输入草皮每平方米价格:";
cin >> lawnprice;
cout << " 输入栅栏每米价格:";
cin >> fenceprice;

//代入数据
lawn.set(lawnlength, lawnwidth);

//计算花园面积和周长
lawnarea = lawn.area ();
lawnperimeter = lawn.perimeter ();

//计算价格
totallawnprice = lawnarea * lawnprice;
totalfenceprice = lawnperimeter * fenceprice;
totalprice = totallawnprice + totalfenceprice;

//显示面积,周长和价格
cout << fixed
cout.precision (2);
cout << " 花园总面积:" << lawnarea << endl;
cout << " 花园周长:" << lawnperimeter << endl;
cout << " 草皮总价格:" << totallawnprice << endl;
cout << " 栅栏总价格:" << totalfenceprice << endl;
cout << " 建设总费用:" << totalprice << endl;

return 0;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
ken_cqyou
2009-11-22 · TA获得超过1641个赞
知道小有建树答主
回答量:480
采纳率:0%
帮助的人:335万
展开全部
编程引用文件最好用相对路径 不要用绝对路径
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式