我在完成任务时遇到问题,我需要建立一个游泳池课程并让它向用户询问游泳池信息,以便它可以根据水的含量为您提供填充游泳池所需的时间。它。第一个问题是与pool1.setsize(),pool1.setfillrate(),setarea,setlevel我得到错误LNK2019为他们还有一些语法错误,我无法弄清楚如何摆脱,一个是在.gettime ()说的参数太少但我没有尝试传递一个参数,我试图让int时间被送回来
#include "stdafx.h"
#include <iostream>
using namespace std;
class swimmingpool
{
public:
void setsize(int, int, int);
void setarea(int);
void setfillrate(int);
void setdrainrate(int);
int gettime(int&);
void setlevel(int);
level = level * length * width;
level = area - level;
Time = level / fillrate;
private:
int length;
int width;
int depth;
int area;
int fillrate;
int drainrate;
int Time;
int level;
};
int _tmain()
{
swimmingpool pool1;
int len;
int wid;
int dep;
int are;
int fill;
int drn;
int lvl;
int time;
cout << "enter length, width, depth" << endl;
cin >> len;
cin >> wid;
cin >> dep;
cout << endl;
pool1.setsize(len, wid, dep);
are = len * wid * dep;
pool1.setarea(are);
cout << "enter the fill rate (int only for a sqft per hr)" << endl;
cin >> fill;
cout << endl;
pool1.setfillrate(fill);
cout << "enter water level" << endl;
cin >> lvl;
cout << endl;
pool1.setlevel(lvl);
time = pool1.gettime();
//lvl = lvl * len * wid;
//lvl = are - lvl;
//time = lvl / fill;
cout << " it will take " << time << " hours" " to fill " << lvl << " sqft in the pool" << endl;
system("pause");
return 0;
答案 0 :(得分:1)
链接器错误告诉您类中声明的成员函数没有实现。尝试在类声明之后(};
之后)以下列方式添加实现代码:
void swimmingpool::setsize(int len, int wid, int dep)
{
length = len;
width = wid;
depth = dep;
}
您还需要为所有成员函数(setarea,setfillrate,setdrainrate,gettime,setlevel)执行此操作
BTW这段代码不会编译:
level = level * length * width;
level = area - level;
Time = level / fillrate;
感觉上面的代码可能应该在setlevel函数中,至少部分是这样。祝你好运。