📄 程序12.7:附加练习1.cpp
字号:
/* 程序12.7:附加练习1.cpp:*/
#include<iostream> //包含头文件
#include<string> //包含头文件
using namespace std; //使用名字空间std
class RandomNumbers
{
int seed;
double count;
public:
//声明变量seed默认值为0
RandomNumbers(int seed=0)
{
this->seed=seed;
count=180.0/3.14;
}
float random ()
{
return seed/count;
}
void displayRandom(int counter)
{
for(int i=1; i<counter; i++)
{
float random=seed/count*i;
cout<<"Random number is: "<<random<<endl;
}
}
};
void displayMenu()
{
cout<<"Want random numbers?(Y/N) :";
}
int main()
{
char choice;
int number;
displayMenu();
cin>>choice;
RandomNumbers randomNumber(3);
while(choice!='n'&&choice!='N')
{
cout << "How many random numbers do you want? :";
cin>>number;
if(number==1)
{
int random=randomNumber.random();
cout<< "Random number is :"<<random;
}
else
{
randomNumber.displayRandom(number);
}
displayMenu();
cin>>choice;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -