学习十天的复习程序
来源:互联网 发布:ubuntu网卡驱动下载 编辑:程序博客网 时间:2024/05/17 03:12
#include <iostream>
using namespace std;
enum CHOICE...{
DrawRect = 1,
GetArea,
GetPerim,
ChangeDimensions,
Quit};
class Rectangle
...{
public:
Rectangle(int width,int height);
~Rectangle();
int GetHeight() const
...{
return itsHeight;
}
int GetWidth() const
...{
return itsWidth;
}
int GetArea() const
...{
return itsHeight*itsWidth;
}
int GetPerim() const
...{
return 2*(itsHeight+itsWidth);
}
void SetSize(int newWidth,int newHeight);
private:
int itsWidth;
int itsHeight;
};
void Rectangle::SetSize(int newWidth , int newHeight)
...{
itsWidth = newWidth;
itsHeight = newHeight;
}
Rectangle::Rectangle(int width , int height)
...{
itsWidth = width;
itsHeight = height;
}
Rectangle::~Rectangle ()
...{
}
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 << " Invaid Choice ,try again.";
cout << endl << endl;
continue;
}
switch(choice)
...{
case DrawRect:
DoDrawRect(theRect);
break;
case GetArea:
DoGetArea(theRect);
break;
case GetPerim:
DoGetPerim(theRect);
break;
case ChangeDimensions:
int newLength,newWidth;
cout << " New width:";
cin >> newWidth;
cout << " New height: ";
cin >> newLength;
theRect.SetSize(newWidth , newLength);
DoDrawRect(theRect);
break;
case Quit:
fQuit = true;
cout <<" Exiting ... " << endl << endl;
break;
default:
cout << "Error in choice!"<< endl;
fQuit = true;
break;
}
}
return 0;
}
int DoMenu()
...{
int choice;
cout << endl << endl;
cout << "***** Menu*****" << endl;
cout << "(1) Draw Rectangle:"<< endl;
cout << "(2) Area:" << endl;
cout << "(3) Perimeter: " << endl;
cout << "(4) Resize: " << endl;
cout << "(5) Quit:" << endl;
cin >> choice;
return choice;
}
void DoDrawRect(Rectangle theRect)
...{
int heigth = theRect.GetHeight();
int width = theRect.GetWidth();
for ( int i = 0;i < heigth; i++)
...{
for (int j =0; j< width;j++)
cout <<"*";
cout << endl;
}
}
void DoGetArea(Rectangle theRect)
...{
cout << "Area: " << theRect.GetArea() << endl;
}
void DoGetPerim(Rectangle theRect)
...{
cout << "Perimeter: " << theRect.GetPerim() << endl;
}
using namespace std;
enum CHOICE...{
DrawRect = 1,
GetArea,
GetPerim,
ChangeDimensions,
Quit};
class Rectangle
...{
public:
Rectangle(int width,int height);
~Rectangle();
int GetHeight() const
...{
return itsHeight;
}
int GetWidth() const
...{
return itsWidth;
}
int GetArea() const
...{
return itsHeight*itsWidth;
}
int GetPerim() const
...{
return 2*(itsHeight+itsWidth);
}
void SetSize(int newWidth,int newHeight);
private:
int itsWidth;
int itsHeight;
};
void Rectangle::SetSize(int newWidth , int newHeight)
...{
itsWidth = newWidth;
itsHeight = newHeight;
}
Rectangle::Rectangle(int width , int height)
...{
itsWidth = width;
itsHeight = height;
}
Rectangle::~Rectangle ()
...{
}
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 << " Invaid Choice ,try again.";
cout << endl << endl;
continue;
}
switch(choice)
...{
case DrawRect:
DoDrawRect(theRect);
break;
case GetArea:
DoGetArea(theRect);
break;
case GetPerim:
DoGetPerim(theRect);
break;
case ChangeDimensions:
int newLength,newWidth;
cout << " New width:";
cin >> newWidth;
cout << " New height: ";
cin >> newLength;
theRect.SetSize(newWidth , newLength);
DoDrawRect(theRect);
break;
case Quit:
fQuit = true;
cout <<" Exiting ... " << endl << endl;
break;
default:
cout << "Error in choice!"<< endl;
fQuit = true;
break;
}
}
return 0;
}
int DoMenu()
...{
int choice;
cout << endl << endl;
cout << "***** Menu*****" << endl;
cout << "(1) Draw Rectangle:"<< endl;
cout << "(2) Area:" << endl;
cout << "(3) Perimeter: " << endl;
cout << "(4) Resize: " << endl;
cout << "(5) Quit:" << endl;
cin >> choice;
return choice;
}
void DoDrawRect(Rectangle theRect)
...{
int heigth = theRect.GetHeight();
int width = theRect.GetWidth();
for ( int i = 0;i < heigth; i++)
...{
for (int j =0; j< width;j++)
cout <<"*";
cout << endl;
}
}
void DoGetArea(Rectangle theRect)
...{
cout << "Area: " << theRect.GetArea() << endl;
}
void DoGetPerim(Rectangle theRect)
...{
cout << "Perimeter: " << theRect.GetPerim() << endl;
}
- 学习十天的复习程序
- 小码哥杯java程序比赛复习(十)常用类(中)
- 初学者的学习复习
- Oracle学习笔记十:监听程序及服务的配置
- 学习Java,C等程序开发的十大诀窍
- 学习Java,C等程序开发的十大诀窍
- C#学习笔记(十)-实现Windows程序的数据更新
- 十天复习,过不到计算机二级是你的运气PIE
- 复习php知识点十
- ffmpeg的复习、学习、总结
- 待学习&复习的内容
- 初学者的学习复习day_2
- 初学者的学习复习day_4
- 初学者的学习复习_day5
- 初学者的学习复习day_6
- 初学者的学习复习day_7
- C++语言复习十 类的继承和派生 实例
- Android复习练习十(SQLite的事务机制)
- 一个睡五分钟等于六个钟头的方法 (转载)
- 这次四川地震怎么就事先无法预防呢
- 今天在此开山
- 四川成都发生地震!!!!!!!!!!!!
- Xp下配置JSP环境:jdk+eclipse+tomcat+mysql
- 学习十天的复习程序
- 近期关注
- 此刻,四川汶川的地震尚未结束......
- 传票翻打测试程序 V1.3
- Ken Levine谈《Bioshock》的叙事
- Linux入门常用命令手册
- Samba 服务器简单设置(初学者)
- C# OFFICE操作
- 33bbb.com在线图片