Logo Studenta

Actividad de Aprendizaje 06 Métodos de Ordenamiento iterativos - Fernando Cesar Sandoval Padilla

¡Este material tiene más páginas!

Vista previa del material en texto

UNIVERSIDAD DE GUADALAJARA
Centro Universitario de Ciencias Exactas e Ingenierías
Estructura de datos I
Actividad de Aprendizaje 06. Métodos de Ordenamiento iterativos
Alumno: Sandoval Padilla Fernando Cesar
Docente: Gutiérrez Hernández Alfredo
Código: 215685409
Sección: D12
	
			 28 de Septiembre de 2019
Resumen personal:
Para la realización de esta actividad fue necesaria la implementación y el acomodo de la estructuras del código del ejercicio cinco para agregar los métodos de ordenamiento requeridos, entonces lo difícil de realizar esta actividad fue el adaptar el código en base a uno de los vistos en clase, es decir, tomando como utilidad el uso de plantillas para implementar estos métodos de ordenamiento, lo cual cambio drásticamente el código anterior, por otra parte el aprendizaje de esta actividad fue la implementación de estos métodos de ordenamiento, en los que podemos notar cuales ordenan mejor o cuales pueden resultar mas eficaces a la hora de realizar un ordenamiento de una lista dependiendo de su tamaño.
Código fuente:
main.cpp
1 #include <iostream>
2 #include <cstdlib>
3 #include <windows.h>
4 #include "Lista.h"
5 #include "Musica.h"
6 using namespace std;
7 int main() {
8 setlocale(LC_ALL,"spanish");
9 Musicbox<Songs> mySongs;
10 Songs mySong;
11 char op, op2;
12 string myString;
13 int myInt;
14
15 cout << "Bienvenido al programa" << endl;
16 do {
17 if( mySongs.getLastPos() != -1 )
18 for( int i(0) ; i <= mySongs.getLastPos() ; i++ )
19 cout << mySongs.retrieve(i)<< endl;
20 cout << "----------------Menu----------------" << endl;
21 cout << "1) Añadir cancion" << endl;
22 cout << "2) Eliminar cancion" << endl;
23 cout << "3) Buscar cancion" <<endl;
24 cout << "4) Ordenar" << endl;
25 cout << "5) Otras opciones" << endl;
26 cout << "6) Salir" << endl;
27 cout << "Ingresa una opcion" << endl;
28 cin >> op;
29 op = toupper(op);
30 switch(op) {
31 case '1':
32 cout << "Menu" << endl;
33 cout << "1) Añadir cancion" << endl;
34 cout << "2) Añadir desde una posicion" << endl;
35 cout << "Ingrese una opcion:";
36 cin >> op;
37 op = toupper(op);
38 switch(op) {
39 case '1':
40 cin.ignore();
41 cout << "Ingrese el nombre de la cacion:";
42 getline(cin,myString);
43 mySong.setSongName(myString);
44 cout << "Ingrese el nombre del autor:";
45 getline(cin,myString);
46 mySong.setSongAutor(myString);
47 cout << "Ingrese la posicion en el ranking:";
48 getline(cin,myString);
49 mySong.setSongRanking(myString);
50 try {
51 mySongs.insertMusic(mySongs.getLastPos(),mySong);
52 }
53 catch(Exception ex) {
54 cout << ex.what() << endl;
55 }
56 break;
57 case '2':
58 cin.ignore();
59 cout << "Proporcione el nombre de la cacion:";
60 getline(cin,myString);
61 mySong.setSongName(myString);
62 cout << "Proporcione el nombre del autor:";
63 getline(cin,myString);
64 mySong.setSongAutor(myString);
65 cout << "Proporcione la posicion en el ranking:";
66 getline(cin,myString);
67 mySong.setSongRanking(myString);
68 cout << "Proporcione la posicion en que desa añadir:";
69 cin >> myInt;
70 try {
71 mySongs.insertMusic(myInt,mySong);
72 }
73 catch(Exception ex) {
74 cout << ex.what() << endl << endl;
75 }
76 break;
77 default:
78 cout <<"Opcion invalida" <<endl;
79 break;
80 }
81 break;
82 case '2':
83 cout << "Ingrese que cancion deseas eliminar >> ";
84 cin >> myInt;
85 try {
86 mySongs.deleteMusic(myInt);
87 }
88 catch (Exception ex) {
89 cout << ex.what() << endl << endl;
90 }
91 break;
92 case '3':
93 cout << "Menu" << endl;
94 cout << "1) Busqueda lineal" << endl;
95 cout << "2) Busqueda binaria" << endl;
96 cout << "Ingresa una opcion" << endl;
97 cin >> op;
98 op = toupper(op);
99 switch(op) {
100 case '1':
101 cin.ignore();
102 cout << "Ingresa la cancion a buscar >> ";
103 getline(cin,myString);
104 mySong.setSongAutor(myString);
105 mySong.setSongName(myString);
106 try {
107 cout << mySongs.retrieve(mySongs.FindDataL(mySong)) << endl;
108 }
109 catch( Exception ex ) {
110 cout << ex.what() << endl;
111 }
112 break;
113 case '2':
114 cin.ignore();
115 cout << "Ingresa la cancion a buscar >> ";
116 getline(cin,myString);
117 mySong.setSongAutor(myString);
118 mySong.setSongName(myString);
119 try {
120 cout << mySongs.retrieve(mySongs.FindDataB(mySong)) << endl;
121 }
122 catch( Exception ex ) {
123 cout << ex.what() << endl;
124 }
125 break;
126 }
127 system("pause");
128 break;
129 case '4':
130 cout << "Menu" << endl;
131 cout << "A) Por Cancion" << endl;
132 cout << "B) Por Autor" << endl;
133 cin >> op;
134 cin.ignore();
135 op = toupper(op);
136 op == 'A' ? op2 = 'A' : op2 = 'B';
137 cout << "Menu" << endl;
138 cout << "1) Metodo burbuja" << endl;
139 cout << "2) Metodo Shell" << endl;
140 cout << "3) Metodo Insercion" << endl;
141 cout << "4) Metodo Seleccion" << endl;
142 cin >> op;
143 cin.ignore();
144 op = toupper(op);
145 switch(op) {
146 case '1':
147 try {
148 mySongs.BubbleSortSongs(op2);
149 }
150 catch(Exception ex) {
151 cout << ex.what() << endl;
152 }
153 break;
154 case '2':
155 try {
156 mySongs.ShellSortSongs(op2);
157 }
158 catch(Exception ex) {
159 cout << ex.what() << endl;
160 }
161 break;
162 case '3':
163 try {
164 mySongs.InsertSortSongs(op2);
165 }
166 catch(Exception ex) {
167 cout << ex.what() << endl;
168 }
169 break;
170 case '4':
171 try {
172 mySongs.SelectSortSongs(op2);
173 }
174 catch(Exception ex) {
175 cout << ex.what() << endl;
176 }
177 break;
178 }
179 break;
180
181
182
183 case '5':
184 int other;
185 cout<<"1.-Primer elemento: "<<endl;
186 cout<<"2.-Ultimo elemento: "<<endl;
187 cout<<"3.-Elemento anterior: "<<endl;
188 cout<<"4.-Siguiente elemento: "<<endl;
189 cout<<"5.-Eliminar todo: "<<endl;
190 cin>>other;
191 if (other==1)
192 {
193 try {
194 cout << mySongs.retrieve(mySongs.FirstMusic());
195 }
196 catch(Exception ex) {
197 cout << ex.what() << endl;
198 }
199 system("pause");
200 }
201 else if (other==2)
202 {
203 try {
204 cout << mySongs.retrieve(mySongs.LastMusic());
205 }
206 catch(Exception ex) {
207 cout << ex.what() << endl;
208 }
209 system("pause");
210 }
211 else if (other==3)
212 {
213 cout << "Ingresa la posicion a buscar >> ";
214 cin >> myInt;
215 try {
216 cout << mySongs.retrieve(mySongs.PrevMusic(myInt)) << endl;
217 }
218 catch(Exception ex) {
219 cout << ex.what() << endl;
220 }
221 system("pause");
222
223 }
224 else if (other==4)
225 {
226 cout << "Ingresa la posicion a buscar >> ";
227 cin >> myInt;
228 try {
229 cout << mySongs.retrieve(mySongs.NextMusic(myInt)) << endl;
230 }
231 catch(Exception ex) {
232 cout << ex.what() << endl;
233 }
234 system("pause");
235
236 }
237 else if (other==5)
238 {
239 do {
240 cout << "Estas seguro? [S/N]" << endl;
241 cin >> op;
242 op = toupper(op);
243 if( op == 'S' ) {
244 try {
245 mySongs.DeleteAllMusic();
246 }
247 catch(Exception ex) {
248 cout << ex.what() << endl;
249 }
250 cout << "Se han eliminado satisfactoriamente" << endl;
251 }
252 }
253 while ( op != 'S' and op != 'N');
254 system("pause");
255 }
256 else{
257 cout<<"Opcion inexistente"<<endl;
258 system("pause");
259 }
260 break;
261 default:
262 cout << "Se ha ingresado una opcion incorrecta, intentelo de nuevo" << endl;
263 }
264 system("cls");
265 }
266 while(op!='6');
267 return 0;
268 }
Lista.h
1 #ifndef LISTA_H
2 #define LISTA_H
3 #include "Musica.h"
4 #include <string>
5 #include "Exception.h"
6 template <class T, int ARRAYSIZE = 1024>
7 class Musicbox {
8 private:
9 T AllMusics[ARRAYSIZE];
10 int Last;
11 void copyAll(const Musicbox<T,ARRAYSIZE>&);
12 void MergeSortSongs(const int&, const int&);
13 void QuickSortSongs(const int&, const int&);
14 void swapSong(T&,T&);
15 public:
16 Musicbox();
17 bool isFull();
18 bool isEmpty();
19 bool isValidPos(const int&);
20 void insertMusic(const int&, const T&);
21 void deleteMusic(const int&);
22 int FirstMusic();
23 int LastMusic();
24 int PrevMusic(const int&);
25 int NextMusic(const int&);
26 int FindDataL(const T&);
27 int FindDataB(const T&);
28 T& retrieve(const int&);
29 void BubbleSortSongs(const char&);
30 void ShellSortSongs(const char&);
31 voidInsertSortSongs(const char&);
32 void SelectSortSongs(const char&);
33 void QuickSortSongs();
34 void MergeSortSongs();
35 std::string toString();
36 void DeleteAllMusic();
37 int getLastPos();
38 Musicbox<T,ARRAYSIZE>& operator = (const Musicbox<T,ARRAYSIZE>&);
39 };
40 template <class T, int ARRAYSIZE>
41 void Musicbox<T,ARRAYSIZE>::copyAll(const Musicbox<T,ARRAYSIZE>& AllMusic) {
42 int i(0);
43 while ( i <= Last ) {
44 this->AllMusics[i] = AllMusic.AllMusics[i];
45 }
46 }
47 template <class T, int ARRAYSIZE>
48 Musicbox<T,ARRAYSIZE>::Musicbox() : Last(-1) { }
49 template <class T, int ARRAYSIZE>
50 bool Musicbox<T,ARRAYSIZE>::isFull() {
51 return Last == ARRAYSIZE - 1;
52 }
53 template <class T, int ARRAYSIZE>
54 bool Musicbox<T,ARRAYSIZE>::isValidPos(const int& pos) {
55 return pos > -1 and pos <= Last;
56 }
57 template <class T, int ARRAYSIZE>
58 bool Musicbox<T,ARRAYSIZE>::isEmpty() {
59 return Last == -1;
60 }
61 template <class T, int ARRAYSIZE>
62 void Musicbox<T,ARRAYSIZE>::insertMusic(const int& pos, const T& Song) {
63 if( isFull() ) {
64 throw Exception("Desbordamiento de datos, insertMusic");
65 }
66 if( pos != -1 and !isValidPos(pos) ) {
67 throw Exception("Posicion invalida, insertMusic");
68 }
69 int i(Last);
70 while( i > pos ) {
71 AllMusics[i] = AllMusics[i-1];
72 i--;
73 }
74 AllMusics[pos + 1] = Song;
75 Last++;
76 }
77 template <class T, int ARRAYSIZE>
78 void Musicbox<T,ARRAYSIZE>::deleteMusic(const int& pos) {
79 if(isEmpty()) {
80 throw Exception("Insuficiencia de datos, deleteMusic");
81 }
82 if(!isValidPos(pos)) {
83 throw Exception("Posicion invalida, deleteMusic");
84 }
85 int i = pos;
86 while( i < Last ) {
87 AllMusics[i] = AllMusics[i+1];
88 i++;
89 }
90 Last--;
91 }
92 template <class T, int ARRAYSIZE>
93 int Musicbox<T,ARRAYSIZE>::FirstMusic() {
94 if(isEmpty()) {
95 throw Exception("Insuficiencia de datos, FirstMusic");
96 }
97 return 0;
98 }
99 template <class T, int ARRAYSIZE>
100 int Musicbox<T,ARRAYSIZE>::LastMusic() {
101 if(isEmpty()) {
102 throw Exception("Insuficienca de datos, LastMusic");
103 }
104 return Last;
105 }
106 template <class T, int ARRAYSIZE>
107 int Musicbox<T,ARRAYSIZE>::PrevMusic(const int& pos) {
108 if( isEmpty() ) {
109 throw Exception("Insuficiencia de datos, PrevMusic");
110 }
111 if( !isValidPos(pos) or pos == 0) {
112 throw Exception("Posicion invalida, PrevMusic");
113 }
114 return pos - 1;
115 }
116 template <class T, int ARRAYSIZE>
117 int Musicbox<T,ARRAYSIZE>::NextMusic(const int& pos) {
118 if( isEmpty() ) {
119 throw Exception("Insuficiencia de datos");
120 }
121 if( !isValidPos(pos) or pos == Last ) {
122 throw Exception("Posicion invalida, NextPos");
123 }
124 return pos + 1;
125 }
126 template <class T, int ARRAYSIZE>
127 int Musicbox<T,ARRAYSIZE>::FindDataL(const T& Element ) {
128 if( isEmpty() ) {
129 throw Exception("Insuficiencia de datos, FindDataL");
130 }
131 int i(0);
132 while ( i <= Last ) {
133 if( AllMusics[i] == Element ) {
134 return i;
135 }
136 i++;
137 }
138 return -1;
139 }
140 template <class T, int ARRAYSIZE>
141 int Musicbox<T,ARRAYSIZE>::FindDataB(const T& Element) {
142 if( isEmpty() ) {
143 throw Exception("Insuficiencia de datos, FindDataB");
144 }
145 int i(0), j(Last), m;
146 while ( i <= j ) {
147 m = ( i + j ) / 2;
148 if( AllMusics[m] == Element ) {
149 return m;
150 }
151 if( Element < AllMusics[m] ) {
152 j = m - 1;
153 }
154 else {
155 i = m + 1;
156 }
157 }
158 return -1;
159 }
160 template <class T, int ARRAYSIZE>
161 T& Musicbox<T,ARRAYSIZE>::retrieve(const int& pos) {
162 if( isEmpty() ) {
163 throw Exception("Insuficiencia de datos, retrieveSong");
164 }
165 if( !isValidPos(pos) ) {
166 throw Exception("Insuficiencia de datos, retrieveSong");
167 }
168 return AllMusics[pos];
169 }
170 template <class T, int ARRAYSIZE>
171 void Musicbox<T,ARRAYSIZE>::swapSong(T& a,T& b) {
172 T aux(a);
173 a=b;
174 b=aux;
175 }
176 template <class T, int ARRAYSIZE>
177 void Musicbox<T,ARRAYSIZE>::BubbleSortSongs(const char& opt) {
178 int i(Last), j;
179 bool flag;
180 do {
181 flag = false;
182 j = 0;
183 while( j < i ) {
184 if( opt == 'A' ) {
185 if( AllMusics[j].getSongName() > AllMusics[j+1].getSongName() ) {
186 swapSong( AllMusics[j], AllMusics[i] );
187 flag = true;
188 }
189 }
190 if( opt == 'B' ) {
191 if( AllMusics[j].getSongAutor() > AllMusics[j+1].getSongAutor() ) {
192 swapSong( AllMusics[j], AllMusics[i] );
193 flag = true;
194 }
195 }
196 j++;
197 }
198 i--;
199 }
200 while(flag);
201 }
202 template <class T, int ARRAYSIZE>
203 void Musicbox<T,ARRAYSIZE>::ShellSortSongs(const char& opt) {
204 float fact ( 3.0 / 4.0) ;
205 int dif( (Last + 1) * fact), lim, i;
206 while(dif > 0) {
207 lim = Last - dif;
208 i=0;
209 while( i <= lim ) {
210 if(opt == 'A') {
211 if( AllMusics[i].getSongName() > AllMusics[ i+ dif ].getSongName() ) {
212 swapSong( AllMusics[i], AllMusics[i+dif] );
213 }
214 }
215 if(opt == 'B') {
216 if( AllMusics[i].getSongAutor() > AllMusics[ i+ dif ].getSongAutor() ) {
217 swapSong( AllMusics[i], AllMusics[i+dif] );
218 }
219 }
220 i++;
221 }
222 dif *= fact;
223 }
224 }
225 template <class T, int ARRAYSIZE>
226 void Musicbox<T,ARRAYSIZE>::InsertSortSongs(const char& opt) {
227 int i(1), j;
228 T aux;
229 if( opt == 'A') {
230 while( i <= Last ) {
231 aux = AllMusics[i];
232 j=i;
233 while ( j > 0 and aux.getSongName() < AllMusics[j-1].getSongName() ) {
234 AllMusics[j] = AllMusics[j-1];
235 j--;
236 }
237 if( i != j ) {
238 AllMusics[j] = aux;
239 }
240 i++;
241 }
242 }
243 if(opt == 'B') {
244 while( i <= Last ) {
245 aux = AllMusics[i];
246 j=i;
247 while ( j > 0 and aux.getSongAutor() < AllMusics[j-1].getSongAutor() ) {
248 AllMusics[j] = AllMusics[j-1];
249 j--;
250 }
251 if( i != j ) {
252 AllMusics[j] = aux;
253 }
254 i++;
255 }
256 }
257 }
258 template <class T, int ARRAYSIZE>
259 void Musicbox<T,ARRAYSIZE>::SelectSortSongs(const char& opt) {
260 int i(0), j, m;
261 while( i < Last ) {
262 m = i;
263 j = i + 1;
264 if( opt == 'A') {
265 while( j < Last ) {
266 if( AllMusics[j].getSongName() < AllMusics[m].getSongName() ) {
267 m = j;
268 }
269 j++;
270 }
271 }
272 if( opt == 'B') {
273 while( j < Last ) {
274 if( AllMusics[j].getSongAutor() < AllMusics[m].getSongAutor()) {
275 m = j;
276 }
277 j++;
278 }
279 }
280 if( m!=i ) {
281 swapSong( AllMusics[i], AllMusics[m] );
282 }
283 i++;
284 }
285 }
286 template <class T, int ARRAYSIZE>
287 void Musicbox<T,ARRAYSIZE>::MergeSortSongs() {
288 MergeSortSongs(0,getLastPos());
289 }
290 template <class T, int ARRAYSIZE>
291 void Musicbox<T,ARRAYSIZE>::MergeSortSongs(const int& leftEdge, const int& rightEdge) {
292 if( leftEdge >= rightEdge ) { ///Criterio de paro, si se encuentran, se termina
293 return;
294 }
295 ///Dividide y venceras
296 int m( (leftEdge + rightEdge) / 2 );
297 MergeSortSongs( leftEdge, m);
298 MergeSortSongs( m + 1, rightEdge);
299 ///Copiar a temporal
300 T temp[ARRAYSIZE];
301 for( int z(leftEdge) ; z <= rightEdge ; z++ ) {
302 temp[z] = AllMusics[z];
303 }
304 ///Intercalacion
305 int i(leftEdge), j( m + 1 ), x(leftEdge);
306 while ( i <= m and j <= rightEdge) {
307 while( i <= m and temp[i] <= temp[j] ) {
308 AllMusics[x++] = temp[i++];
309 }
310 if( i <= m) {
311 while( j <= rightEdge and temp[j] <= temp[i] ) {
312 AllMusics[x++] = temp [j++];
313 }
314 }
315 while ( i <= m ) {
316 AllMusics[x++] = temp[i++];
317 }
318 while( j <= rightEdge ) {
319 AllMusics[x++] = temp [j++];
320 }
321 }
322 }
323 template <class T, int ARRAYSIZE>
324 void Musicbox<T,ARRAYSIZE>::QuickSortSongs() {
325 QuickSortSongs(0,getLastPos());
326 }
327 template <class T, int ARRAYSIZE>
328 void Musicbox<T,ARRAYSIZE>::QuickSortSongs(const int& leftEdge, const int& rightEdge) {
329 if( leftEdge >= rightEdge ) {
330 return;
331 }
332 ///Separacion
333 int i(leftEdge), j(rightEdge);
334 while( i < j ) {
335 while( i < j and AllMusics[i] <= AllMusics[rightEdge] ) {
336 i++;
337 }
338 while( i < j and AllMusics[j] >= AllMusics[rightEdge] ) {
339 j--;
340 }
341 if( i != j ) {
342 swapSong(AllMusics[i],AllMusics[j]);
343 }
344}
345 if( i != rightEdge ) {
346 swapSong(AllMusics[i],AllMusics[rightEdge]);
347 }
348 ///Divide y venceras
349 QuickSortSongs(leftEdge, i - 1);
350 QuickSortSongs(i + 1, rightEdge);
351 }
352 template <class T, int ARRAYSIZE>
353 std::string Musicbox<T,ARRAYSIZE>::toString() {
354 std::string AllMusic;
355 for( int i(0) ; i <= Last ; i++ ) {
356 AllMusic += AllMusics[i].toString() + "\n" ;
357 }
358 return AllMusic;
359 }
360 template <class T, int ARRAYSIZE>
361 void Musicbox<T,ARRAYSIZE>::DeleteAllMusic() {
362 Last = -1;
363 }
364 template <class T, int ARRAYSIZE>
365 int Musicbox<T,ARRAYSIZE>::getLastPos() {
366 return Last;
367 }
368 template <class T, int ARRAYSIZE>
369 Musicbox<T,ARRAYSIZE>& Musicbox<T,ARRAYSIZE>::operator = (const Musicbox<T,ARRAYSIZE>& Song) {
370 copyAll(Song);
371 return *this;
372 }
373 #endif // LISTA_H
Musica.h
1 #ifndef MUSICA_H
2 #define MUSICA_H
3 #include <string>
4 #include <iostream>
5 #include <string>
6 class Songs {
7 private:
8 std::string SongName;
9 std::string SongAutor;
10 std::string SongRanking;
11 public:
12 void setSongName(const std::string&);
13 void setSongAutor(const std::string&);
14 void setSongRanking(const std::string&);
15 std::string toString() const;
16 std::string getSongName() const;
17 std::string getSongAutor() const;
18 std::string getSongRanking() const;
19 bool operator == (const Songs&) const;
20 bool operator != (const Songs&) const;
21 bool operator >= (const Songs&) const;
22 bool operator > (const Songs&) const;
23 bool operator <= (const Songs&) const;
24 bool operator < (const Songs&) const;
25 friend std::ostream& operator << (std::ostream&, Songs&);
26 friend std::istream& operator >> (std::istream&, Songs&);
27 };
28 #endif // MUSICA_H
Musica.cpp
1 #include "Musica.h"
2
3 void Songs::setSongName(const std::string& Name) {
4 SongName = Name;
5 }
6 void Songs::setSongAutor(const std::string& Autor) {
7 SongAutor = Autor;
8 }
9 void Songs::setSongRanking(const std::string& Ranking) {
10 SongRanking = Ranking;
11 }
12 std::string Songs::toString() const {
13 std::string AllSong;
14 AllSong += SongName;
15 AllSong += " | ";
16 AllSong += SongAutor;
17 AllSong += " | ";
18 AllSong += SongRanking;
19 return AllSong;
20 }
21 std::string Songs::getSongName() const {
22 return SongName;
23 }
24 std::string Songs::getSongAutor() const {
25 return SongAutor;
26 }
27 std::string Songs::getSongRanking() const {
28 return SongRanking;
29 }
30 bool Songs::operator == (const Songs& Song) const {
31 return SongName == Song.SongName or SongAutor == Song.SongAutor;
32 }
33 bool Songs::operator != (const Songs& Song) const {
34 return SongName != Song.SongName or SongAutor != Song.SongAutor;
35 }
36 bool Songs::operator >= (const Songs& Song) const {
37 return SongName >= Song.SongName or SongAutor >= Song.SongAutor;
38 }
39 bool Songs::operator > (const Songs& Song) const {
40 return SongName > Song.SongName or SongAutor > Song.SongAutor;
41 }
42 bool Songs::operator <= (const Songs& Song) const {
43 return SongName <= Song.SongName or SongAutor <= Song.SongAutor;
44 }
45 bool Songs::operator < (const Songs& Song) const {
46 return SongName < Song.SongName or SongAutor < Song.SongAutor;
47 }
48 std::ostream& operator << (std::ostream& os, Songs& s){
49 std::string aux;
50 aux = s.SongName + " | " + s.SongAutor + " | " + s.SongRanking + "\n";
51 os << aux;
52 return os;
53 }
54 std::istream& operator >> (std::istream& is, Songs& s){
55 is >> s.SongAutor;
56 is >> s.SongAutor;
57 is >> s.SongRanking;
58 return is;
59 }
Exception.h
1 #ifndef EXCEPTION_H_INCLUDED
2 #define EXCEPTION_H_INCLUDED
3 class Exception : public std::exception {
4 private:
5 std::string msg;
6 public:
7 explicit Exception(const char* message) : msg(message) { }
8
9 explicit Exception(const std::string& message) : msg(message) { }
10
11 virtual ~Exception() throw () { }
12
13 virtual const char* what() const throw() {
14 return msg.c_str();
15 }
16 };
17
18 #endif // EXCEPTION_H_INCLUDED
Capturas de pantalla:
Menu
Añadir canción
Ordenamientos
Método burbuja
Método Shell
Método de inserción 
Método de selección 
Ordenando por autor

Otros materiales