fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <fstream> //library for files
  5. #include <cctype>
  6. #include <algorithm>
  7. #include <iterator>
  8. #include <sstream>
  9. #include <typeinfo>
  10.  
  11.  
  12. using namespace std;
  13.  
  14. template <class T>
  15. void alloc3DArray(T *** &x, int numberOfRows, int numberOfColumns,int numberOfDepth )
  16. {
  17.  
  18. int i=0;
  19. int j=0;
  20. int k=0;
  21.  
  22.  
  23. // allocate an array for array of arrays
  24. x = new T ** [numberOfRows];
  25.  
  26.  
  27. // Allocate an array for each element of the first array
  28. for(i = 0; i < numberOfRows; i++)
  29. {
  30.  
  31. x[i] = new T *[numberOfColumns];
  32.  
  33. // Allocate an array of T for each element of this array
  34. for(j = 0; j < numberOfColumns; j++)
  35. {
  36.  
  37. x[i][j] = new T [numberOfDepth];
  38.  
  39. // Specify an initial value
  40. for(int k = 0; k < numberOfDepth; ++k)
  41. {
  42. x[i][j][k] = -1;
  43.  
  44.  
  45. }
  46.  
  47.  
  48. }
  49. }
  50.  
  51. }
  52.  
  53. template <class T>
  54. void dealloc3DArray(T *** &x, int numberOfRows, int numberOfColumns )
  55.  
  56. {
  57. // Check if it exeists
  58. if(!x) //it does not exist
  59. exit(1);
  60.  
  61.  
  62.  
  63. for (int i = 0; i < numberOfRows; ++i)
  64. {
  65. for (int j = 0; j < numberOfColumns; ++j)
  66.  
  67. {
  68. //delete innest
  69. delete [] x[i][j];
  70. }
  71.  
  72. //delete columns
  73. delete [] x[i];
  74. }
  75. //delete first array
  76. delete [] x;
  77. }
  78.  
  79. template <class T>
  80. const vector<T> allOperationsNotWorking(T *** &myArray1, T *** &myArray2, T *** &myArray3,int numberOfRows, int numberOfColumns,int numberOfDepth )
  81.  
  82. {
  83. int i=0;
  84. int j=0;
  85. int k=0;
  86.  
  87. int size = numberOfRows * numberOfColumns * numberOfDepth; //find vector size
  88. vector<T> &myvector = vector<T>(size);// create a vector
  89. //vector<T>::const_iterator it;// const_iterator is faster than iterator
  90. for(i = 0; i < numberOfRows; i++)
  91. for(j = 0; j < numberOfColumns; j++)
  92. for(k = 0; k < numberOfDepth; k++){
  93.  
  94. myArray3[i][j][k] =myArray1[i][j][k]+myArray2[i][j][k];
  95.  
  96. myvector.push_back(myArray3[i][j][k]);
  97.  
  98.  
  99. }
  100. return myvector;
  101.  
  102.  
  103. }
  104.  
  105. vector<string> allOperationsString(string *** &myArray1, string *** &myArray2, string *** &myArray3,int numberOfRows, int numberOfColumns,int numberOfDepth )
  106.  
  107. {
  108. int i=0;
  109. int j=0;
  110. int k=0;
  111.  
  112. int size = numberOfRows * numberOfColumns * numberOfDepth; //find vector size
  113. vector<string> myvector = vector<string>(size);// create a vector
  114. //vector<T>::const_iterator it;// const_iterator is faster than iterator
  115. for(i = 0; i < numberOfRows; i++)
  116. for(j = 0; j < numberOfColumns; j++)
  117. for(k = 0; k < numberOfDepth; k++){
  118.  
  119. myArray3[i][j][k] =myArray1[i][j][k]+myArray2[i][j][k];
  120.  
  121. myvector.push_back(myArray3[i][j][k]);
  122.  
  123.  
  124. }
  125. return myvector;
  126.  
  127.  
  128. }
  129.  
  130. template <class T>
  131. vector<T> isWord(vector<T> &stringVector, vector<T> &goodOnes,vector<T> &badOnes, vector<T> &dict)
  132. {
  133. vector<int> strV;
  134.  
  135.  
  136. if (typeid(stringVector).name()== typeid(strV).name()){
  137.  
  138. //if (typeid(stringVector)==int){
  139. ofstream badFile; // declare and object as output file using ofstream
  140. cout << " Illegal Vector" << endl;
  141. badFile.open ("hw1bout2.txt", ios::app);
  142. badFile << "Illegal Vector" << endl;
  143. badFile.close();
  144. return badOnes;
  145. }
  146.  
  147. int i=0;
  148. int j=0;
  149. int FIRSTSIZE=stringVector.size();
  150. int SECONDSIZE = dict.size();
  151. std::string sInput="";
  152. std::string sDict="";
  153.  
  154. sort(stringVector.begin(), stringVector.end());//sort() uses quicksort from the algorith library
  155.  
  156. for(int i=0, j=0; i < FIRSTSIZE && j < SECONDSIZE; ){
  157. sInput=stringVector[i];
  158.  
  159. char (*transformation_fn)(char) = &std::toupper;
  160. std::transform(sInput.begin(), sInput.end(), sInput.begin(), transformation_fn); //convert input word to upper
  161.  
  162. sDict=dict[j];
  163.  
  164.  
  165. if(sInput.compare(sDict) == 0) {
  166. goodOnes.push_back(stringVector[i]); //write good word to vector
  167.  
  168. i++;//advance one position in string vector
  169. j++;//advance one position in dictionary
  170. }
  171.  
  172. else if(stringVector[i] < dict[j] && FIRSTSIZE < SECONDSIZE){// wrods did not match
  173. if (stringVector[i].size() >0) badOnes.push_back(stringVector[i]); //write bad word to vector if not empty string
  174. i++;//advance one position in string vector
  175. }
  176.  
  177. else{
  178. j++;//advance one position in dictionary
  179. }
  180. }
  181.  
  182.  
  183.  
  184. return goodOnes;
  185. }
  186.  
  187. template<class T >
  188. vector<string> isWord(vector<int> &stringVector, vector<string> &goodOnes,vector<string> &badOnes, vector<string> &dict)
  189. {
  190.  
  191. vector<int> strV;
  192.  
  193.  
  194. if (typeid(stringVector).name()== typeid(strV).name()){
  195.  
  196. badOnes.push_back("Illegal Vector" );
  197. }
  198. return badOnes;
  199.  
  200. }
  201.  
  202. //template<class T>
  203. vector<int> allOperations(int *** &myArray1, int *** &myArray2, int *** &myArray3,int numberOfRows, int numberOfColumns,int numberOfDepth )
  204.  
  205. {
  206. int i=0;
  207. int j=0;
  208. int k=0;
  209.  
  210. int size = numberOfRows * numberOfColumns * numberOfDepth; //find vector size
  211. vector<int> myvector = vector<int>(size);// create a vector
  212. //const vector<int>& myvector;
  213. //vector<int>::const_iterator it = myvector.begin();
  214. vector<int>::const_iterator it;// const_iterator is faster than iterator
  215. for(i = 0; i < numberOfRows; i++)
  216. for(j = 0; j < numberOfColumns; j++)
  217. for(k = 0; k < numberOfDepth; k++){
  218.  
  219. myArray3[i][j][k] =myArray1[i][j][k]+myArray2[i][j][k];
  220.  
  221. myvector.push_back(myArray3[i][j][k]);
  222.  
  223.  
  224. }
  225. return myvector;
  226.  
  227.  
  228. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
stdout

Standard output is empty