求助:lnk2001的问题!!

godying 2003-10-19 09:39:22
我用的是vc6编译器,学习c++
程序如下:
#include <iostream>

using namespace std;
enum CHOICE {DrawRect=1,GetArea,GetPerim,ChangeDimensions,Quit};

class Rectangle
{
public:
Rectangle(int width,int height);
~Rectangle();

int GetHeight();
int GetWidth();
int GetArea();
int GetPerim();
void SetSize(int newWidth,int newHeight);

private:

int itsWidth;
int itsHeight;
};

Rectangle::Rectangle(int width,int height)
{
itsWidth=width;
itsHeight=height;
}

Rectangle::~Rectangle(){}

int Rectangle::GetWidth()
{
return itsWidth;
}

int Rectangle::GetHeight()
{
return itsHeight;
}

int Rectangle::GetArea()
{
return (itsWidth*itsHeight);
}

int Rectangle::GetPerim()
{
return (2*itsWidth+2*itsHeight);
}

void Rectangle::SetSize(int newWidth,int newHeight)
{
itsWidth=newWidth;
itsHeight=newHeight;
}

int DoMenu();

void DoDrawRect(Rectangle);
void DoGetArea(Rectangle);
void DoGetPerim(Rectangle);

int main()
{
Rectangle theRect(30,5);

int choice=DrawRect;
int fQuit=false;

while(!fQuit)
{
choice=DoMenu();
if (choice<DrawRect||choice>Quit)
{
cout<<"\nInwalid choice,please try again.\n";
continue;
}

switch(choice)
{
case DrawRect:
DoDrawRect(theRect);
break;
case GetArea:
DoGetArea(theRect);
break;
case GetPerim:
DoGetPerim(theRect);
break;
case ChangeDimensions:
int newWidth,newHeight;
cout<<"\nNew width: ";
cin>>newWidth;
cout<<"\nNew height: ";
cin>>newHeight;

theRect.SetSize(newWidth,newHeight);
DoDrawRect(theRect);
break;
case Quit:
fQuit=true;
cout<<"\nExit...\n\n";
break;
case false:
cout<<"\nError in choice!\n";
fQuit=true;
break;
}
}


return 0;
}

int DoMeun()
{
int choice;
cout<<"\n\n *** Menu ***\n";
cout<<"(1) Draw Rectangle\n";
cout<<"(2) Area\n";
cout<<"(3) Peimeter\n";
cout<<"(4) Resize\n";
cout<<"(5) Quit\n";

cin>>choice;
return choice;
}

void DoDrawRect(Rectangle theRect)
{
int height=theRect.GetHeight();
int width=theRect.GetWidth();

for(int i=0;i<height;i++)
{
for(int j=0;j<width;j++)

cout<<"*";
cout<<"\n";
}
}

void DoGetArea(Rectangle theRect)
{
cout<<" Area: "<<theRect.GetArea()<<endl;
}


void DoGetPerim(Rectangle theRect)
{
cout<<" Perimeter: "<<theRect.GetPerim()<<endl;
}


编译没有问题!
连接问题如下:
--------------------Configuration: R1_1 - Win32 Debug--------------------
Linking...
R1_1.OBJ : error LNK2001: unresolved external symbol "int __cdecl DoMenu(void)" (?DoMenu@@YAHXZ)
Debug/R1_1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

R1_1.exe - 2 error(s), 0 warning(s)
请问各位,问题在哪里?如何解决???
谢谢了!!!
...全文
74 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
daizh 2003-10-19
  • 打赏
  • 举报
回复
不用客气
godying 2003-10-19
  • 打赏
  • 举报
回复
谢谢
谢谢
非常感谢!!
我刚来这里,有什么规定还不懂!!
非常感谢了!!
daizh 2003-10-19
  • 打赏
  • 举报
回复
int DoMeun()//错在这个地方,应该是:int DoMenu()
DoMeun()改为DoMenu()是单词错了
godying 2003-10-19
  • 打赏
  • 举报
回复
哥哥!
实在是看不懂你写的东西,可不可以写明白一点!
谢谢了
daizh 2003-10-19
  • 打赏
  • 举报
回复
#include <iostream>

using namespace std;
enum CHOICE {DrawRect=1,GetArea,GetPerim,ChangeDimensions,Quit};

class Rectangle
{
public:
Rectangle(int width,int height);
~Rectangle();

int GetHeight();
int GetWidth();
int GetArea();
int GetPerim();
void SetSize(int newWidth,int newHeight);

private:

int itsWidth;
int itsHeight;
};

Rectangle::Rectangle(int width,int height)
{
itsWidth=width;
itsHeight=height;
}

Rectangle::~Rectangle(){}

int Rectangle::GetWidth()
{
return itsWidth;
}

int Rectangle::GetHeight()
{
return itsHeight;
}

int Rectangle::GetArea()
{
return (itsWidth*itsHeight);
}

int Rectangle::GetPerim()
{
return (2*itsWidth+2*itsHeight);
}

void Rectangle::SetSize(int newWidth,int newHeight)
{
itsWidth=newWidth;
itsHeight=newHeight;
}

int DoMenu();

void DoDrawRect(Rectangle);
void DoGetArea(Rectangle);
void DoGetPerim(Rectangle);

int main()
{
Rectangle theRect(30,5);

int choice=DrawRect;
int fQuit=false;

while(!fQuit)
{
choice=DoMenu();
if (choice<DrawRect||choice>Quit)
{
cout<<"\nInwalid choice,please try again.\n";
continue;
}

switch(choice)
{
case DrawRect:
DoDrawRect(theRect);
break;
case GetArea:
DoGetArea(theRect);
break;
case GetPerim:
DoGetPerim(theRect);
break;
case ChangeDimensions:
int newWidth,newHeight;
cout<<"\nNew width: ";
cin>>newWidth;
cout<<"\nNew height: ";
cin>>newHeight;

theRect.SetSize(newWidth,newHeight);
DoDrawRect(theRect);
break;
case Quit:
fQuit=true;
cout<<"\nExit...\n\n";
break;
case false:
cout<<"\nError in choice!\n";
fQuit=true;
break;
}
}


return 0;
}

int DoMeun()//错在这个地方,应该是:int DoMenu()
{
int choice;
cout<<"\n\n *** Menu ***\n";
cout<<"(1) Draw Rectangle\n";
cout<<"(2) Area\n";
cout<<"(3) Peimeter\n";
cout<<"(4) Resize\n";
cout<<"(5) Quit\n";

cin>>choice;
return choice;
}

void DoDrawRect(Rectangle theRect)
{
int height=theRect.GetHeight();
int width=theRect.GetWidth();

for(int i=0;i<height;i++)
{
for(int j=0;j<width;j++)

cout<<"*";
cout<<"\n";
}
}

void DoGetArea(Rectangle theRect)
{
cout<<" Area: "<<theRect.GetArea()<<endl;
}


void DoGetPerim(Rectangle theRect)
{
cout<<" Perimeter: "<<theRect.GetPerim()<<endl;
}
daizh 2003-10-19
  • 打赏
  • 举报
回复
#include <iostream>

using namespace std;
enum CHOICE {DrawRect=1,GetArea,GetPerim,ChangeDimensions,Quit};

class Rectangle
{
public:
Rectangle(int width,int height);
~Rectangle();

int GetHeight();
int GetWidth();
int GetArea();
int GetPerim();
void SetSize(int newWidth,int newHeight);

private:

int itsWidth;
int itsHeight;
};

Rectangle::Rectangle(int width,int height)
{
itsWidth=width;
itsHeight=height;
}

Rectangle::~Rectangle(){}

int Rectangle::GetWidth()
{
return itsWidth;
}

int Rectangle::GetHeight()
{
return itsHeight;
}

int Rectangle::GetArea()
{
return (itsWidth*itsHeight);
}

int Rectangle::GetPerim()
{
return (2*itsWidth+2*itsHeight);
}

void Rectangle::SetSize(int newWidth,int newHeight)
{
itsWidth=newWidth;
itsHeight=newHeight;
}

int DoMenu();

void DoDrawRect(Rectangle);
void DoGetArea(Rectangle);
void DoGetPerim(Rectangle);

int main()
{
Rectangle theRect(30,5);

int choice=DrawRect;
int fQuit=false;

while(!fQuit)
{
choice=DoMenu();
if (choice<DrawRect||choice>Quit)
{
cout<<"\nInwalid choice,please try again.\n";
continue;
}

switch(choice)
{
case DrawRect:
DoDrawRect(theRect);
break;
case GetArea:
DoGetArea(theRect);
break;
case GetPerim:
DoGetPerim(theRect);
break;
case ChangeDimensions:
int newWidth,newHeight;
cout<<"\nNew width: ";
cin>>newWidth;
cout<<"\nNew height: ";
cin>>newHeight;

theRect.SetSize(newWidth,newHeight);
DoDrawRect(theRect);
break;
case Quit:
fQuit=true;
cout<<"\nExit...\n\n";
break;
case false:
cout<<"\nError in choice!\n";
fQuit=true;
break;
}
}


return 0;
}

int DoMenu()//´íÔÚÕâ¸öµØ·½Ó¦¸ÃÊÇint DoMenu()
{
int choice;
cout<<"\n\n *** Menu ***\n";
cout<<"(1) Draw Rectangle\n";
cout<<"(2) Area\n";
cout<<"(3) Peimeter\n";
cout<<"(4) Resize\n";
cout<<"(5) Quit\n";

cin>>choice;
return choice;
}

void DoDrawRect(Rectangle theRect)
{
int height=theRect.GetHeight();
int width=theRect.GetWidth();

for(int i=0;i<height;i++)
{
for(int j=0;j<width;j++)

cout<<"*";
cout<<"\n";
}
}

void DoGetArea(Rectangle theRect)
{
cout<<" Area: "<<theRect.GetArea()<<endl;
}


void DoGetPerim(Rectangle theRect)
{
cout<<" Perimeter: "<<theRect.GetPerim()<<endl;
}

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧