00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <fstream>
00023 using namespace std;
00024
00025
00026 #include <SawVector.h>
00027
00028 int main(int argc, char *argv[]){
00029
00030 cout << "*************************************************" << endl ;
00031 cout << "* *" << endl ;
00032 cout << "* VECTOR MANIPULATION *" << endl ;
00033 cout << "* *" << endl ;
00034 cout << "* Nestor Aguirre 2006 *" << endl ;
00035 cout << "* nfaguirrec@unal.edu.co *" << endl ;
00036 cout << "* *" << endl ;
00037 cout << "*************************************************" << endl ;
00038 cout << endl ;
00039
00040 cout << "---------------------------------------" << endl ;
00041 cout << " Inicializando a un valor constante " << endl ;
00042 cout << "---------------------------------------" << endl ;
00043 cout << endl ;
00044 SawVector vector1(4, 2.36) ;
00045 cout << "A = " << vector1 << endl ;
00046 cout << endl ;
00047
00048 cout << "------------------------------------------" << endl ;
00049 cout << " Obteniendo los datos desde un arreglo " << endl ;
00050 cout << "------------------------------------------" << endl ;
00051 cout << endl ;
00052 double vec[5] = {2.35, 0.156, 4.521, 0.789, 5.423 } ;
00053 SawVector vector2( vec, 5 ) ;
00054 cout << "B = " << vector2 << endl ;
00055 cout << endl ;
00056
00057 cout << "-------------------------------------" << endl ;
00058 cout << " Probando el constructor de copia " << endl ;
00059 cout << "-------------------------------------" << endl ;
00060 cout << endl ;
00061 SawVector vector3( vector2 ) ;
00062 cout << "C = " << vector3 << endl ;
00063 cout << endl ;
00064
00065 cout << "----------------------------" << endl ;
00066 cout << " Probando el operador == " << endl ;
00067 cout << "----------------------------" << endl ;
00068 cout << endl ;
00069 cout << "C == B ? " << ( (vector3 == vector2) ? "TRUE" : "FALSE" ) << endl ;
00070 cout << endl ;
00071
00072 cout << "-------------------------------------------" << endl ;
00073 cout << " Obteniendo el elemento maximo y minimo " << endl ;
00074 cout << "-------------------------------------------" << endl ;
00075 cout << endl ;
00076 uint i ;
00077 double max = vector3.getMax( &i ) ;
00078 cout << "vec[" << i << "] = " << max << endl ;
00079 double min = vector3.getMin( &i ) ;
00080 cout << "vec[" << i << "] = " << min << endl ;
00081 cout << endl ;
00082
00083 cout << "---------------------------------------" << endl ;
00084 cout << " Probando el operador de asignacion " << endl ;
00085 cout << "---------------------------------------" << endl ;
00086 cout << endl ;
00087 SawVector vector4( 5 ) ;
00088 vector4 = vector3 ;
00089 cout << "A = " << vector4 << endl ;
00090 cout << endl ;
00091
00092 cout << "---------------------------------------------" << endl ;
00093 cout << " Probando intercambiar elementos 2 <--> 4 " << endl ;
00094 cout << "---------------------------------------------" << endl ;
00095 cout << endl ;
00096 vector4.swapElements( 2, 4 ) ;
00097 cout << "A_{2,4} = " << vector4 << endl ;
00098 cout << endl ;
00099
00100 cout << "--------------------------------" << endl ;
00101 cout << " Probando invertir elementos " << endl ;
00102 cout << "--------------------------------" << endl ;
00103 cout << endl ;
00104 vector4.reverse() ;
00105 cout << "A_{inverse} = " << vector4 << endl ;
00106 cout << endl ;
00107
00108 cout << "--------------------------------" << endl ;
00109 cout << " Probando sumar dos vectores " << endl ;
00110 cout << "--------------------------------" << endl ;
00111 cout << endl ;
00112 cout << "A = " << vector3 << endl ;
00113 cout << "B = " << vector4 << endl ;
00114 cout << "A+B = " << vector3 + vector4 << endl ;
00115 cout << endl ;
00116
00117 cout << "---------------------------------" << endl ;
00118 cout << " Probando restar dos vectores " << endl ;
00119 cout << "---------------------------------" << endl ;
00120 cout << endl ;
00121 cout << "A = " << vector3 << endl ;
00122 cout << "B = " << vector4 << endl ;
00123 cout << "A-B = " << vector3 - vector4 << endl ;
00124 cout << endl ;
00125
00126 cout << "-----------------------------------------------" << endl ;
00127 cout << " Probando producto punto entre dos vectores " << endl ;
00128 cout << "-----------------------------------------------" << endl ;
00129 cout << endl ;
00130 cout << "A = " << vector3 << endl ;
00131 cout << "B = " << vector4 << endl ;
00132 cout << "A*B = " << vector3 * vector4 << endl ;
00133 cout << endl ;
00134
00135 cout << "--------------------------------------------------" << endl ;
00136 cout << " Probando multiplicar un escalar con un vector " << endl ;
00137 cout << "--------------------------------------------------" << endl ;
00138 cout << endl ;
00139 cout << "A = " << vector4 << endl ;
00140 cout << "B = " << 0.456 << endl ;
00141 cout << "A*B = " << vector4*0.456 << endl ;
00142 cout << "B*A = " << 0.456*vector4 << endl ;
00143 cout << endl ;
00144
00145 cout << "--------------------------------------------" << endl ;
00146 cout << " Probando sumar un escalar con un vector " << endl ;
00147 cout << "--------------------------------------------" << endl ;
00148 cout << endl ;
00149 cout << "A = " << vector4 << endl ;
00150 cout << "B = " << 0.756 << endl ;
00151 cout << "A+B = " << vector4+0.756 << endl ;
00152 cout << "B+A = " << 0.756+vector4 << endl ;
00153 cout << endl ;
00154
00155 cout << "-----------------------------------------" << endl ;
00156 cout << " Obteniendo los datos desde un stream " << endl ;
00157 cout << "-----------------------------------------" << endl ;
00158 cout << endl ;
00159 SawVector vector5( 5 ) ;
00160 ifstream file("vector.data") ;
00161 file >> vector5 ;
00162 file.close() ;
00163 cout << "A = " << vector5 << endl ;
00164
00165 cout << "------------------------------------------------" << endl ;
00166 cout << " Obteniendo la norma euclideana de un vector " << endl ;
00167 cout << "------------------------------------------------" << endl ;
00168 cout << "A = " << vector5 << endl ;
00169 cout << "| A | = " << vector5.getEuclideanNorm() << endl ;
00170
00171 return EXIT_SUCCESS;
00172 }