C++题目,成功后还加你200分

来源:百度知道 编辑:UC知道 时间:2024/05/30 05:39:02
30、 建立类模板input,在调用构造函数时,完成以下工作:
(1) 提示用户输入
(2) 让用户输入数据;
(3) 如果数据不在预定范围内,重新提示输入。
input型的对象应当按以下形式定义:input ob(“promput message”, min_value, max_value)
其中,promput message是提示输入的信息。可接受的最小值和最大值分别由min_value与max_value指定。

#include<iostream>
using namespace std;
template<class T>
class input
{
T max,min;
public:
input(char *s,T m1,T m2)
{
T p;
min=m1;
max=m2;
cout<<"请输入"<<s<<endl;
cin>>p;
do
{
if(min<=p&&p<=max)
break;
else
{
cout<<"再输入"<<s<<endl;
cin>>p;
}
}while(0);
}
};
int main()
{
input<int> a1("int",1,10);
input<double> a2("double",10.01,20.05);
return 0;
}

不会,别浪费五十分,送我吧