Gracias, la verdad es que funciona, se lo he enviado al profesor a ver si acepta funciones de C en estas prácticas de C++.
Gracias a todos.
Gracias a todos.
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú#ifndef __HELPCLASS_H__
#define __HELPCLASS_H__
class Help {
private:
int _option;
public:
Help();
int getoption();
void setoption(int option);
void showmenu();
bool helpon(char option);
bool isvalid(char option);
};
#endif
#include "helpclass.h"
#include <iostream>
#include <cstdlib> //Para system()
#include <cstdio>
using namespace std;
Help::Help() {
setoption(1);
}
int Help::getoption() {
return _option;
}
void Help::setoption(int option) {
_option = option;
}
void Help::showmenu() {
cout << endl << "Sistema de ayuda en modo texto en la consola" << endl << endl;
cout << "0.- Se mostrara la ultima ayuda" << endl;
cout << "1.- if" << endl;
cout << "2.- switch" << endl;
cout << "3.- for" << endl;
cout << "4.- while" << endl;
cout << "5.- do-while" << endl;
cout << "6.- Salir del programa" << endl << endl;
}
bool Help::helpon(char option) {
setoption(option);
switch(option) {
case '0': option = getoption();
break;
case '1': cout << endl << "Bucle if" << endl << endl;
cout << " if(condition)" << endl;
cout << " {" << endl;
cout << " statements;" << endl;
cout << " }" << endl << endl << endl;
break;
case '2': cout << endl << "Bucle switch" << endl << endl;
cout << " switch(expression)" << endl;
cout << " {" << endl;
cout << " case constant-expression:" << endl;
cout << " statements;" << endl;
cout << " break; //optional" << endl;
cout << " case constant-expression:" << endl;
cout << " statements;" << endl;
cout << " break; //optional" << endl << endl;
cout << " // you can have any number of case statements." << endl;
cout << " default : //Optional" << endl;
cout << " statements;" << endl;
cout << " }" << endl << endl;
break;
case '3': cout << endl << "Bucle for" << endl << endl;
cout << " for(init; condition; increment)" << endl;
cout << " {" << endl;
cout << " statements;" << endl;
cout << " }" << endl << endl;
break;
case '4': cout << endl << "Bucle while" << endl << endl;
cout << " while(condition)" << endl;
cout << " {" << endl;
cout << " statements;" << endl;
cout << " }" << endl << endl;
break;
case '5': cout << endl << "Bucle do-while" << endl << endl;
cout << " do" << endl;
cout << " {" << endl;
cout << " statements;" << endl;
cout << " } while(contidion);" << endl << endl;
break;
default: return false;
}
return true;
}
/*
bool Help::isvalid(int option) {
if(option < 0 || option > 6) {
return false;
}
//No haría falta el else, porque si se cumple bucle if, sale de la funcion
//devolviendo false, si no se cumple, no entra y al final devuelve true;
return true;
}*/
bool Help::isvalid(char option) {
if(option >= '0' || option <= '6') {
cout << "TRUE" << endl;
getchar();
getchar();
return true;
}
//No haría falta el else, porque si se cumple bucle if, sale de la funcion
//devolviendo false, si no se cumple, no entra y al final devuelve true;
else {
cout << "FALSE" << endl;
getchar();
getchar();
return false;
}
}
#include "helpclass.h"
#include <iostream>
#include <cstdlib> //Para system()
#include <cstdio> //Para getchar();
using namespace std;
int main() {
Help h;
char option;
bool continuar = true;
do {
system("clear");
option = h.getoption();
cout << option << endl; //borrar
h.showmenu();
cout << "Introduce opcion: ";
cin >> option;
if(h.isvalid(option)) {
system("clear");
continuar = h.helpon(option);
cout << "Pulsa ENTER para continuar ...";
getchar();
getchar();
}
else {
cout << "Por favor, introduzca valor valido" << endl;
}
} while(continuar);
return 0;
}
bool Help::isvalid(int option) {
if(option < '0' || option > '6') {
return false;
}
return true;
}
BSSID PWR Beacons #Data, #/s CH MB ENC CIPHER AUTH ESSID
XX:XX:XX:XX:XX:XX -83 69 0 0 9 54 . WEP WEP WLAN_3D
23:53:23 Sending Authentication Request (Open System) [ACK]
23:53:23 Authentication successful
23:53:23 Sending Association Request [ACK]
23:53:23 Association successful :-) (AID: 1)
23:53:33 Sending Authentication Request (Open System) [ACK]
23:53:33 Authentication successful
23:53:33 Sending Association Request [ACK]
23:53:33 Association successful :-) (AID: 1)
23:53:43 Sending Authentication Request (Open System) [ACK]
23:53:43 Authentication successful
23:53:43 Sending Association Request
23:53:48 Sending Authentication Request (Open System)
23:53:50 Sending Authentication Request (Open System)
23:53:52 Sending Authentication Request (Open System)
23:53:54 Sending Authentication Request (Open System)
23:53:56 Sending Authentication Request (Open System)
23:53:58 Sending Authentication Request (Open System)
23:54:00 Sending Authentication Request (Open System)
23:54:02 Sending Authentication Request (Open System)
23:54:04 Sending Authentication Request (Open System)^C
Read 39628 packets (got 1 ARP requests and 32 ACKs), sent 40131 packets...(499 p
Read 39685 packets (got 1 ARP requests and 32 ACKs), sent 40183 packets...(500 p
Read 39735 packets (got 1 ARP requests and 32 ACKs), sent 40233 packets...(500 p
Read 39785 packets (got 1 ARP requests and 32 ACKs), sent 40283 packets...(500 p
Read 39822 packets (got 1 ARP requests and 32 ACKs), sent 40332 packets...(499 p
Read 548912 packets (got 2 ARP requests and 211 ACKs), sent 595677 packets...(499 pps)