diff options
| author | Mitsuo Tokumori <[email protected]> | 2023-08-18 01:54:52 -0500 |
|---|---|---|
| committer | Mitsuo Tokumori <[email protected]> | 2023-08-18 01:54:52 -0500 |
| commit | d6e56dbe184cac37d7aa5cebe3e1db108dee4a28 (patch) | |
| tree | 6729cdc1f629cfe011d63375f462c8646c34ffaf /2023-2 | |
| parent | 8e01ba134a230e47e8b80351dd8abc8c3b72e683 (diff) | |
| download | LP1-d6e56dbe184cac37d7aa5cebe3e1db108dee4a28.tar.gz LP1-d6e56dbe184cac37d7aa5cebe3e1db108dee4a28.tar.bz2 LP1-d6e56dbe184cac37d7aa5cebe3e1db108dee4a28.zip | |
Add 2023-2 L0 example for guided lab
Diffstat (limited to '2023-2')
| -rw-r--r-- | 2023-2/L0/Libros.csv | 33 | ||||
| -rw-r--r-- | 2023-2/L0/fun.cpp | 72 | ||||
| -rw-r--r-- | 2023-2/L0/fun.h | 5 | ||||
| -rw-r--r-- | 2023-2/L0/main.cpp | 21 | ||||
| -rw-r--r-- | 2023-2/L0/reporte.txt | 39 |
5 files changed, 170 insertions, 0 deletions
diff --git a/2023-2/L0/Libros.csv b/2023-2/L0/Libros.csv new file mode 100644 index 0000000..5097249 --- /dev/null +++ b/2023-2/L0/Libros.csv @@ -0,0 +1,33 @@ +QV96140,El Duque en su territorio,Fiorella Florencio Polo,12,37.47
+KC34197,Las demoliciones de Paris,Zkenia Chung Zuniga,10,294.26
+VA35843,L-ecole des menages,Walter Jolay Chumpitaz,14,234.01
+XN48844,The Countess de Charny,Rosario Tabori Arias,30,265.70
+IW10872,El Club de los explotadores,Cesar Rodriguez Serrano,5,263.45
+ZR63735,Elogio de la madrastra,Julio Vilcara Jugo,26,185.88
+FY25192,La hermosa jardinera,Humberto Amezquita Contreras,8,113.40
+OC73472,Le Cousin Pons,Jaime Shirakawa Florian,30,413.61
+QE47018,El Manuscrito del Domino,Raul Collado Villa,1,276.71
+UW23132,House of Pomegranates,David Perez Antezano,8,441.52
+SV17719,Le Colonel Chabert,Cinthia Zegarra Cabello,9,51.20
+SA04133,An Ideal Husband,Delicia Norabuena Zegarra,11,239.17
+SK15788,Le Chef-d oeuvre inconnu,Blanca Acuna Ayllon,22,112.52
+JO84937,Historia de Mayra,Valentina Urbina Antezano,27,53.48
+NF53199,Suspense,Emilio Gonzales Aguirre,17,367.64
+BB35881,Una Navidad,Edilberto Mori Suarez,4,32.80
+XW06135,The Nutcracker,Humberto Vargas Guevara,4,77.27
+QO90975,La Peau de chagrin,Janet Aranda Minaya,30,158.03
+TA81777,Musica para camaleones,Luz Jauregui Bravo,3,218.59
+FW74175,La Cousine Bette,Surami Preciado Pinto,18,279.44
+OT07742,La Fille aux yeux d-or,Alfonso Cabello Lam,13,195.87
+PL70268,Lady -- Windermeres Fan,Victor Garcia Astete,4,329.24
+QA53897,The Corsican Brothers,Ofelia Mercado Caro,8,62.87
+ZQ38637,La casa grade,Delicia Arca Aquino,7,214.72
+PT00038,El nino perdido,Giovana Mejia Zegarra,3,80.23
+FY82455,La guerra del fin de siglo,Milena Zarate Acuna,13,352.36
+KW25071,La Resurrección de Rocambole,Francisco Zimic Salas,4,313.22
+ZK87496,Beat the Devil,Miguel Landeo Estrada,19,178.81
+BH96036,Los tesoros del Rajah,Delicia Arca Leiva,6,360.73
+LM05731,Le Chevalier de Maison - Rouge,Yliana Ortiz Guevara,12,352.26
+XQ03477,Les Ressources de Quinola,Johan Ayala Zevallos,19,369.37
+ZM20053,The Fencing Master,Felicita Castillo Chung,5,26.41
+MG75057,Un viaje de 75 dias,Victoria Shirakawa Saona,18,350.67
diff --git a/2023-2/L0/fun.cpp b/2023-2/L0/fun.cpp new file mode 100644 index 0000000..e317db3 --- /dev/null +++ b/2023-2/L0/fun.cpp @@ -0,0 +1,72 @@ +#include <iostream> // I/O basico (left, right, hex, oct, [no]uppercase, showbase) +#include <iomanip> // manipuladores (setw, setprecision, setfill) +#include <iostream> +#include <cstring> +#include "fun.h" + +#define MAXLEN 100 + +using namespace std; + +void leer_datos_escribir_reporte(std::istream& in, std::ostream& out) { + int sum_qty; + double sum_price; // (price * qty) + + char code[MAXLEN]; + char book_name[MAXLEN]; + char author_name[MAXLEN]; + int qty; + double unit_price; + char c; // dummy + + sum_qty = 0; + sum_price = 0.0; + print_header(out); + int i; + for (i = 0; true; i++) { + // read + in.getline(code, MAXLEN, ','); + in.getline(book_name, MAXLEN, ','); + in.getline(author_name, MAXLEN, ','); + in >> qty; + in >> c; + in >> unit_price; + in.ignore(MAXLEN, '\n'); + if (!in) { + break; + } + // process + to_upper_cstring_inplace(book_name); + sum_qty += qty; + sum_price += qty * unit_price; + + // write + out << setw(2) << right << setfill('0') << i + 1 << ") "; + out << left << setfill(' '); + out << setw(8) << code; + out << setw(32) << uppercase << book_name; + out << setw(32) << author_name; + out << right << setprecision(2) << fixed; + out << setw(4) << qty; + out << setw(4) << ' '; + out << setw(8) << unit_price; + out << '\n'; + } + + out << "\n\n"; + out << "Total cantidad libros: " << sum_qty << '\n'; + out << "Total valor libros: " << sum_price << '\n'; +} + +void print_header(ostream& out) { + // 8 32 32 4 8 + out << "No. Codigo Nombre Autor Cant. Precio \n"; + out << "----------------------------------------------------------------------------------------------\n"; +} + +void to_upper_cstring_inplace(char * s) { + int i; + for (i = 0; s[i] != '\0'; i++) { + s[i] = toupper(s[i]); + } +}
\ No newline at end of file diff --git a/2023-2/L0/fun.h b/2023-2/L0/fun.h new file mode 100644 index 0000000..4277ab4 --- /dev/null +++ b/2023-2/L0/fun.h @@ -0,0 +1,5 @@ +#include <iostream> + +void leer_datos_escribir_reporte(std::istream& in, std::ostream& out); +void print_header(std::ostream& out); +void to_upper_cstring_inplace(char * s);
\ No newline at end of file diff --git a/2023-2/L0/main.cpp b/2023-2/L0/main.cpp new file mode 100644 index 0000000..fc150df --- /dev/null +++ b/2023-2/L0/main.cpp @@ -0,0 +1,21 @@ +// Just an example of I/O with files for INF281 +// Compile with: clang++ -g main.cpp fun.cpp && ./a.out +// Mitsuo 2023-08-17 + +#include <iostream> +#include <fstream> // archivos + +#include "fun.h" + +using namespace std; + +int main(int argc, char ** argv) { + ifstream in("Libros.csv"); + if (!in) { + cerr << "Error: No se pudo abrir archivo\n"; + } + ofstream out("reporte.txt"); + leer_datos_escribir_reporte(in, out); + return 0; +} + diff --git a/2023-2/L0/reporte.txt b/2023-2/L0/reporte.txt new file mode 100644 index 0000000..649dda1 --- /dev/null +++ b/2023-2/L0/reporte.txt @@ -0,0 +1,39 @@ +No. Codigo Nombre Autor Cant. Precio +---------------------------------------------------------------------------------------------- +01) QV96140 EL DUQUE EN SU TERRITORIO Fiorella Florencio Polo 12 37.47 +02) KC34197 LAS DEMOLICIONES DE PARIS Zkenia Chung Zuniga 10 294.26 +03) VA35843 L-ECOLE DES MENAGES Walter Jolay Chumpitaz 14 234.01 +04) XN48844 THE COUNTESS DE CHARNY Rosario Tabori Arias 30 265.70 +05) IW10872 EL CLUB DE LOS EXPLOTADORES Cesar Rodriguez Serrano 5 263.45 +06) ZR63735 ELOGIO DE LA MADRASTRA Julio Vilcara Jugo 26 185.88 +07) FY25192 LA HERMOSA JARDINERA Humberto Amezquita Contreras 8 113.40 +08) OC73472 LE COUSIN PONS Jaime Shirakawa Florian 30 413.61 +09) QE47018 EL MANUSCRITO DEL DOMINO Raul Collado Villa 1 276.71 +10) UW23132 HOUSE OF POMEGRANATES David Perez Antezano 8 441.52 +11) SV17719 LE COLONEL CHABERT Cinthia Zegarra Cabello 9 51.20 +12) SA04133 AN IDEAL HUSBAND Delicia Norabuena Zegarra 11 239.17 +13) SK15788 LE CHEF-D OEUVRE INCONNU Blanca Acuna Ayllon 22 112.52 +14) JO84937 HISTORIA DE MAYRA Valentina Urbina Antezano 27 53.48 +15) NF53199 SUSPENSE Emilio Gonzales Aguirre 17 367.64 +16) BB35881 UNA NAVIDAD Edilberto Mori Suarez 4 32.80 +17) XW06135 THE NUTCRACKER Humberto Vargas Guevara 4 77.27 +18) QO90975 LA PEAU DE CHAGRIN Janet Aranda Minaya 30 158.03 +19) TA81777 MUSICA PARA CAMALEONES Luz Jauregui Bravo 3 218.59 +20) FW74175 LA COUSINE BETTE Surami Preciado Pinto 18 279.44 +21) OT07742 LA FILLE AUX YEUX D-OR Alfonso Cabello Lam 13 195.87 +22) PL70268 LADY -- WINDERMERES FAN Victor Garcia Astete 4 329.24 +23) QA53897 THE CORSICAN BROTHERS Ofelia Mercado Caro 8 62.87 +24) ZQ38637 LA CASA GRADE Delicia Arca Aquino 7 214.72 +25) PT00038 EL NINO PERDIDO Giovana Mejia Zegarra 3 80.23 +26) FY82455 LA GUERRA DEL FIN DE SIGLO Milena Zarate Acuna 13 352.36 +27) KW25071 LA RESURRECCIóN DE ROCAMBOLE Francisco Zimic Salas 4 313.22 +28) ZK87496 BEAT THE DEVIL Miguel Landeo Estrada 19 178.81 +29) BH96036 LOS TESOROS DEL RAJAH Delicia Arca Leiva 6 360.73 +30) LM05731 LE CHEVALIER DE MAISON - ROUGE Yliana Ortiz Guevara 12 352.26 +31) XQ03477 LES RESSOURCES DE QUINOLA Johan Ayala Zevallos 19 369.37 +32) ZM20053 THE FENCING MASTER Felicita Castillo Chung 5 26.41 +33) MG75057 UN VIAJE DE 75 DIAS Victoria Shirakawa Saona 18 350.67 + + +Total cantidad libros: 420 +Total valor libros: 97236.25 |
