26.cpp
来自「包括了学生学籍管理系统 对输入字符串的排序程序 代码正确」· C++ 代码 · 共 51 行
CPP
51 行
#include<iostream>
#include<iomanip>
using namespace std;
template<class T>
class tmplt{
T arr[100];
int m;
public:
tmplt(int count)
{
m=count<100? count:100;
}
void dataIn();
void reverseOut();
};
template<class T>
void tmplt<T>::dataIn()
{
cout<<"输入数据:"<<endl;
for(int i=0;i<m;i++)
cin>>arr[i];
cout<<"输入的数据为:"<<endl;
for(i=0;i<m;i++)
cout<<setw(4)<<arr[i];
cout<<endl;
}
template<class T>
void tmplt<T>::reverseOut()
{
cout<<"反序输出为:"<<endl;
for(int i=m-1;i>=0;i--)
cout<<setw(4)<<arr[i];
cout<<endl;
}
void main()
{
int c;
int n=5;
cout<<"整型数据:"<<endl;
tmplt<int> a(n);
a.dataIn();
a.reverseOut();
cout<<"字符型数据:"<<endl;
tmplt<char> b(n);
b.dataIn();
b.reverseOut();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?