Advertisement
Guest User

Untitled

a guest
May 24th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.38 KB | None | 0 0
  1. #include <fstream>
  2. #include <list>
  3. #include <algorithm>
  4. #include <iterator>
  5. #include <stdlib.h>
  6. #include <sstream>
  7. #include <string>
  8. #include <numeric>
  9. #include <iostream>
  10.  
  11. using namespace std;
  12.  
  13. template<class T>class Comparable
  14. {
  15. public:
  16.     virtual T compareTo(T obj) = 0;
  17. };
  18.  
  19. template<class T>class CTableColumn:Comparable<int>
  20. {
  21. private:
  22.     string rowName;
  23.     string colName;
  24.     string content;
  25. public:
  26.     CTableColumn()
  27.     {
  28.         rowName = "\0";
  29.         colName = "\0";
  30.         content = "\0";
  31.     }
  32.  
  33.     CTableColumn(string rowName, string colName, const T content)
  34.     {
  35.         rowName = rowName;
  36.         colName = colName;
  37.         content = content;
  38.     }
  39.     CTableColumn(const CTableColumn& ob)
  40.     {
  41.         rowName = ob.rowName;
  42.         colName = ob.colName;
  43.         content = ob.content;
  44.     }
  45.  
  46.     string getRowName()const { return rowName; }
  47.     string getColName()const { return colName; }
  48.     T getContent()const { return content; }
  49.     void setValue(const T& content) { content = m_content; }
  50.  
  51.     void compareTo(CTableColumn toObj)
  52.     {
  53.         if (rowName > toObj.rowName && colName > toObj.colName && content > toObj.content) return 1;
  54.         else if (rowName < toObj.rowName && colName < toObj.colName && content < toObj.content) return -1;
  55.         else return 0;
  56.     }
  57.     bool CTableColumn :: operator < (CTableColumn& ob) const { return ((rowName < ob.rowName) && (colName < ob.colName) && (content < ob.content)); }
  58.     bool CTableColumn :: operator == (CTableColumn& ob) const { return ((rowName == ob.rowName) && (colName == ob.colName) && (content == ob.content));
  59.     bool CTableColumn :: operator + (CTableColumn& oRes) const
  60.     {
  61.         CTableColumn oRes((rowName + oRes.rowName) && (colName + oRes.colName) && (content + oRes.content));
  62.         return oRes;
  63.     }
  64.     friend istream operator >> (istream is, CTableColumn ob);
  65.     friend ostream operator << (ostream os, CTableColumn ob);
  66.     }
  67. };
  68. template<CTableColumn, int> void CTableColumn<int> ::istream& operator >> (istream is, CTableColumn ob)
  69. {
  70.     cout << "Row Name:";    is >> ob.rowName;
  71.     cout << "Col Name:";    is >> ob.colName;
  72.     cout << "Content:";     is >> ob.content;
  73.     return is;
  74. }
  75. template<CTableColumn int > void CTableColumn::ostream& operator << (ostream os, CTableColumn ob)
  76. {
  77.     os << ob.getRow() << "  -  " << ob.getCol() << "  -  " << ob.getContent() << endl;
  78.     return os;
  79. }
  80.  
  81. template<class T> class CTable : public CTableColumn<string>
  82. {
  83. private:
  84.     string name;
  85.  
  86. };
  87. void main()
  88. {
  89.     system("pause");
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement