⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 10-3-2.cpp

📁 学习c++的ppt
💻 CPP
字号:
#include <iostream.h>
#include <iomanip.h>
#include <conio.h>
#include <stdlib.h>

template <class Type>
class Array {
    private:
        Type  *element;
        int  size;
    public:
        Array(const int size);
        ~Array();
        Type &operator[](const int index);
        void operator=(Type temp);
        void sort();   
        int  find(Type a);
        Type  sum();
};
template <class Type> inline
Array<Type>::Array(const int s)
{   size = s;
     element = new Type[size];
     for(int i=0; i < size; i ++)  
          element[i] = 0;
}
template <class Type> inline
Array<Type>::~Array()
{   delete element ;
}
template <class Type> 
Type &Array<Type>::operator[](const int index)
{   if(index < 0 || index > size-1) {
           cout << "\n Index value of " << index 
                   << " is out of bound.\n" ;
           exit(2);
     }
     return(element[index]);
}
template <class Type> 
void Array<Type>::operator=(Type temp)
{  
     for(int i=0; i < size; i ++)  
          element[i] = temp;
}
void main()
{   Array <int>  Iobj(20);
     Array <double>  Dobj(20);
     Array <char> Cobj(20);
     cout.flags(ios::showpoint);
	 for(int i=0;i < 20; i++)  {
          Iobj[i] = i; 
		  Dobj[i] = i;
     }    
     Cobj = 'C';
//	 Dobj[22] = 15.87;
     for(i=0;i < 20; i++)  {
          cout << setw(3) << Iobj[i] << setw(15)   
                   << Dobj[i] << "  " << Cobj[i] << endl;
     }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -