diff options
| author | Mitsuo Tokumori <[email protected]> | 2023-09-18 15:47:57 -0500 |
|---|---|---|
| committer | Mitsuo Tokumori <[email protected]> | 2023-09-18 15:47:57 -0500 |
| commit | e283be2be6910d8378c35056937d46c1b54297b0 (patch) | |
| tree | d23b462f7b8d6082a2b152b0d350fc95fcd82d4c /2023-2/L00/mitsuo | |
| parent | be34531e5a29be4d4c0a313e23aaf36850e4eb62 (diff) | |
| download | LP1-e283be2be6910d8378c35056937d46c1b54297b0.tar.gz LP1-e283be2be6910d8378c35056937d46c1b54297b0.tar.bz2 LP1-e283be2be6910d8378c35056937d46c1b54297b0.zip | |
Very smol update
Diffstat (limited to '2023-2/L00/mitsuo')
| -rw-r--r-- | 2023-2/L00/mitsuo/fun.cpp | 72 | ||||
| -rw-r--r-- | 2023-2/L00/mitsuo/fun.h | 5 | ||||
| -rw-r--r-- | 2023-2/L00/mitsuo/main.cpp | 21 | ||||
| -rw-r--r-- | 2023-2/L00/mitsuo/reporte.txt | 39 |
4 files changed, 137 insertions, 0 deletions
diff --git a/2023-2/L00/mitsuo/fun.cpp b/2023-2/L00/mitsuo/fun.cpp new file mode 100644 index 0000000..e317db3 --- /dev/null +++ b/2023-2/L00/mitsuo/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/L00/mitsuo/fun.h b/2023-2/L00/mitsuo/fun.h new file mode 100644 index 0000000..4277ab4 --- /dev/null +++ b/2023-2/L00/mitsuo/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/L00/mitsuo/main.cpp b/2023-2/L00/mitsuo/main.cpp new file mode 100644 index 0000000..fc150df --- /dev/null +++ b/2023-2/L00/mitsuo/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/L00/mitsuo/reporte.txt b/2023-2/L00/mitsuo/reporte.txt new file mode 100644 index 0000000..649dda1 --- /dev/null +++ b/2023-2/L00/mitsuo/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 |
