这是我写的一段C++猜数字的程序,老师让我给改写成有CLASS格式的,我英文不好,英文书看不明白,求助
#include <iostream.h>
#include <cstdlib>
#include <time.h>
int main()
{
int myMax,secretNumber,i;
int t=0;
srand(time(0));
cout<<"input the myMax :"; //out a proper prompt message
cin>>myMax; //and input an integer into myMax
secretNumber=1+rand()%myMax; // prescribe the secretNumber range 1<=r<=myMax cout<<"please guess the number:";
cin>>i; if (i > secretNumber)
cout << "Wrong! your number is bigger than the number i have.\n";
else if (i < secretNumber)
cout << "Wrong! your number is smaller than the number i have.\n"; while(i != secretNumber ) //the guess series starts
{
cout << "Please guess again\n";
cin >> i;
if (i > secretNumber)
cout << "Wrong! your number is bigger than the number i have.\n";
else if (i < secretNumber)
cout << "Wrong! your number is smaller than the number i have.\n";
else cout << "Yes,you are right! You are very bright guy!\n";
t++;
if (t>10) //limit the guess times
{
cout << "Do you kown the binary search?? you've not taken the course for Introduction to Computer Engineering!\n";
break; // out the series
}
}return 0;}
改写成有以下格式的:
class MyGames
{
public:
void treasureSearch()
{ }
private:
int secretNumber;
};//end of the class MyGamesint main()
{
}
我真的不怎么明白对于才学习C++的我,实在很痛苦,我在韩国但是看不懂书,真郁闷死了
#include <iostream.h>
#include <cstdlib>
#include <time.h>
int main()
{
int myMax,secretNumber,i;
int t=0;
srand(time(0));
cout<<"input the myMax :"; //out a proper prompt message
cin>>myMax; //and input an integer into myMax
secretNumber=1+rand()%myMax; // prescribe the secretNumber range 1<=r<=myMax cout<<"please guess the number:";
cin>>i; if (i > secretNumber)
cout << "Wrong! your number is bigger than the number i have.\n";
else if (i < secretNumber)
cout << "Wrong! your number is smaller than the number i have.\n"; while(i != secretNumber ) //the guess series starts
{
cout << "Please guess again\n";
cin >> i;
if (i > secretNumber)
cout << "Wrong! your number is bigger than the number i have.\n";
else if (i < secretNumber)
cout << "Wrong! your number is smaller than the number i have.\n";
else cout << "Yes,you are right! You are very bright guy!\n";
t++;
if (t>10) //limit the guess times
{
cout << "Do you kown the binary search?? you've not taken the course for Introduction to Computer Engineering!\n";
break; // out the series
}
}return 0;}
改写成有以下格式的:
class MyGames
{
public:
void treasureSearch()
{ }
private:
int secretNumber;
};//end of the class MyGamesint main()
{
}
我真的不怎么明白对于才学习C++的我,实在很痛苦,我在韩国但是看不懂书,真郁闷死了
解决方案 »
- 为何总有人说,指针可以先定义,后初始化呢?我试过编译报错呀? 大家在讨论指针与引用的区别是,都在说,引用在定义是必须初始化,但是指针定义时不用初始化,可以先定义
- 创建文件问题
- VC6.0怎样做导航图钉窗口
- dll自定义类往List Control 中写值
- FILE_FTP_INFO *pInfo=new FILE_FTP_INFO FTP问题
- 怎么在VC7.1中添加想重载的父类中的虚函数?VC6中很方便啊
- 请指点迷津
- 关于所画图形的滚动显示
- 用VC提取系统字体写入文本文件
- 高级isapi编程,诚恳请教。
- 问一道计算机网络的考试题目,请各位大侠帮忙,谢谢~~~~~~
- .xls文件可以做为数据源么?
然后在Main里面只写上MyGames game;game.treasureSearch();