Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "lista.hh"
- #include "komentorivi.h"
- #include <iostream>
- #include <string>
- using namespace std;
- string aja_komentorivi() {
- Lista listaa;
- while (true) {
- string komento{""};
- cout << "tehtavalista> ";
- getline(cin, komento);
- if (komento == "listaa") {
- if ( listaa.onko_tyhja() ) {
- cout << "Tehtavalista on tyhja!" << endl;
- continue;
- }
- else {
- listaa.tulosta();
- }
- }
- else if(komento == "lisaa") {
- string prioriteetti{0};
- string tehtavan_nimi{""};
- int oikeaprioriteetti{0};
- while (true) {
- cout << "syota kiireellisyystaso: ";
- getline(cin,prioriteetti);
- try {
- oikeaprioriteetti = stoi(prioriteetti);
- if (oikeaprioriteetti > 0 and oikeaprioriteetti < 6 and prioriteetti.length() == 1 ) {
- break;
- }
- else if( prioriteetti.length() != 1) {
- cout << "Virhe: syote virheellinen (Kiireellisyystaso tulee olla kokonaisluku 1-5)!" << endl;
- }
- else {
- cout << "Virhe: syote virheellinen (Kiireellisyystaso 1-5)!" << endl;
- continue;
- }
- }
- catch (...) {
- cout << "Virhe: syote virheellinen (Kiireellisyystaso 1-5)!" << endl;
- continue;
- }
- }
- cout << "syota tehtava: ";
- getline(cin,tehtavan_nimi);
- listaa.lisaa_alkio_loppuun(oikeaprioriteetti,tehtavan_nimi);
- cout << "Lisatty tasolle " << oikeaprioriteetti << " tehtava " << "\"" << tehtavan_nimi << "\"" << endl;
- continue;
- }
- else if(komento == "suorita") {
- listaa.poista_alkio_alusta();
- continue;
- }
- else if(komento == "poista") {
- if (listaa.onko_tyhja()) {
- cout << "Virhe: tehtavalista on tyhja!" << endl;
- continue;
- }
- string jarjestysnro{""};
- int oikeajarjestysnro{0};
- while (true) {
- cout << "syota jarjestysnumero: ";
- getline(cin, jarjestysnro);
- int pituus = listaa.pituus();
- try {
- oikeajarjestysnro = stoi(jarjestysnro);
- if (oikeajarjestysnro > 0 and oikeajarjestysnro < pituus ) {
- break;
- }
- else {
- cout << "Virhe: syote virheellinen (jarjestysnumero tulee olla kokonaisluku 0-" << pituus << ")!" << endl;
- continue;
- }
- }
- catch (...) {
- cout << "Virhe: syote virheellinen (jarjestysnumero tulee olla kokonaisluku 0-" << pituus << ")!"<< endl;
- continue;
- }
- }
- if (oikeajarjestysnro == 1) {
- listaa.poista_alkio_alusta();
- }
- else {
- listaa.poista_alkio(oikeajarjestysnro);
- }
- continue;
- }
- else if(komento == "lopeta") {
- cout << "Loppu!" << endl;
- return "";
- }
- else {
- cout << "Virhe: tuntematon komento!" << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement