Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (c) 2014 Sergi Granell
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
- #include "Cjt_estudiants.hpp"
- void redondear_e_a(Estudiant & est);
- /* Pre: est tiene nota */
- /* Post: est pasa a tener su nota original redondeada */
- #define opcio_func_declr(n) \
- void opcio_##n(Cjt_estudiants &cjt);
- #define opcio_nom(n) \
- opcio_##n
- opcio_func_declr(1);
- opcio_func_declr(2);
- opcio_func_declr(3);
- opcio_func_declr(4);
- opcio_func_declr(5);
- typedef void (*vtable_entry)(Cjt_estudiants &cjt);
- vtable_entry vtable[] = {
- opcio_nom(1),
- opcio_nom(2),
- opcio_nom(3),
- opcio_nom(4),
- opcio_nom(5),
- };
- int main()
- {
- Cjt_estudiants cjt;
- cout << "Escriu la mida del conjunt i els elements" << endl;
- cjt.llegir_cjt_estudiants();
- int opcio = 0;
- while (opcio != -6) {
- cout << "Escriu una opcio: " << endl;
- opcio = readint();
- if (opcio < 0 && opcio > -6) {
- vtable[-opcio-1](cjt);
- }
- }
- }
- void opcio_1(Cjt_estudiants &cjt)
- {
- cout << "Escriu un estudiant:" << endl;
- Estudiant e;
- e.llegir_estudiant();
- cjt.afegir_estudiant(e);
- }
- void opcio_2(Cjt_estudiants &cjt)
- {
- int dni = readint();
- if (cjt.existeix_estudiant(dni)) {
- Estudiant e = cjt.consultar_estudiant(dni);
- if (e.te_nota())
- cout << "El estudiant " << dni << " te nota " << e.consultar_nota() << endl;
- else
- cout << "El estudiant " << dni << " no te nota" << endl;
- } else {
- cout << "El estudiant " << dni << " no existeix" << endl;
- }
- }
- void opcio_3(Cjt_estudiants &cjt)
- {
- cout << "Escriu el DNI i la nova nota: ";
- int dni = readint();
- double nota = readdouble();
- if (cjt.existeix_estudiant(dni)) {
- Estudiant e = cjt.consultar_estudiant(dni);
- if (e.te_nota())
- e.modificar_nota(nota);
- else
- e.afegir_nota(nota);
- cjt.modificar_estudiant(e);
- } else {
- cout << "El estudiant " << dni << " no existeix" << endl;
- }
- }
- void opcio_4(Cjt_estudiants &cjt)
- {
- for (int i = 1; i <= cjt.mida(); ++i) {
- Estudiant e = cjt.consultar_iessim(i);
- if (e.te_nota()) {
- redondear_e_a(e);
- cjt.modificar_iessim(i, e);
- }
- }
- }
- void opcio_5(Cjt_estudiants &cjt)
- {
- cjt.escriure_cjt_estudiants();
- }
- void redondear_e_a(Estudiant & est)
- {
- est.modificar_nota(((int) (10. * (est.consultar_nota() + 0.05))) / 10.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement