Advertisement
Guest User

komentorivi

a guest
Nov 21st, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. #include "lista.hh"
  2. #include "komentorivi.h"
  3. #include <iostream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. string aja_komentorivi() {
  9. Lista listaa;
  10. while (true) {
  11. string komento{""};
  12. cout << "tehtavalista> ";
  13. getline(cin, komento);
  14. if (komento == "listaa") {
  15. if ( listaa.onko_tyhja() ) {
  16. cout << "Tehtavalista on tyhja!" << endl;
  17. continue;
  18. }
  19. else {
  20. listaa.tulosta();
  21. }
  22. }
  23. else if(komento == "lisaa") {
  24. string prioriteetti{0};
  25. string tehtavan_nimi{""};
  26. int oikeaprioriteetti{0};
  27. while (true) {
  28. cout << "syota kiireellisyystaso: ";
  29. getline(cin,prioriteetti);
  30.  
  31. try {
  32. oikeaprioriteetti = stoi(prioriteetti);
  33. if (oikeaprioriteetti > 0 and oikeaprioriteetti < 6 and prioriteetti.length() == 1 ) {
  34. break;
  35. }
  36. else if( prioriteetti.length() != 1) {
  37. cout << "Virhe: syote virheellinen (Kiireellisyystaso tulee olla kokonaisluku 1-5)!" << endl;
  38. }
  39. else {
  40. cout << "Virhe: syote virheellinen (Kiireellisyystaso 1-5)!" << endl;
  41. continue;
  42. }
  43. }
  44. catch (...) {
  45. cout << "Virhe: syote virheellinen (Kiireellisyystaso 1-5)!" << endl;
  46. continue;
  47. }
  48.  
  49. }
  50. cout << "syota tehtava: ";
  51. getline(cin,tehtavan_nimi);
  52.  
  53. listaa.lisaa_alkio_loppuun(oikeaprioriteetti,tehtavan_nimi);
  54. cout << "Lisatty tasolle " << oikeaprioriteetti << " tehtava " << "\"" << tehtavan_nimi << "\"" << endl;
  55. continue;
  56. }
  57. else if(komento == "suorita") {
  58. listaa.poista_alkio_alusta();
  59. continue;
  60. }
  61. else if(komento == "poista") {
  62. if (listaa.onko_tyhja()) {
  63. cout << "Virhe: tehtavalista on tyhja!" << endl;
  64. continue;
  65. }
  66. string jarjestysnro{""};
  67. int oikeajarjestysnro{0};
  68. while (true) {
  69. cout << "syota jarjestysnumero: ";
  70. getline(cin, jarjestysnro);
  71. int pituus = listaa.pituus();
  72. try {
  73. oikeajarjestysnro = stoi(jarjestysnro);
  74. if (oikeajarjestysnro > 0 and oikeajarjestysnro < pituus ) {
  75. break;
  76. }
  77. else {
  78. cout << "Virhe: syote virheellinen (jarjestysnumero tulee olla kokonaisluku 0-" << pituus << ")!" << endl;
  79. continue;
  80. }
  81.  
  82. }
  83. catch (...) {
  84. cout << "Virhe: syote virheellinen (jarjestysnumero tulee olla kokonaisluku 0-" << pituus << ")!"<< endl;
  85. continue;
  86. }
  87. }
  88. if (oikeajarjestysnro == 1) {
  89. listaa.poista_alkio_alusta();
  90. }
  91. else {
  92. listaa.poista_alkio(oikeajarjestysnro);
  93. }
  94. continue;
  95. }
  96. else if(komento == "lopeta") {
  97. cout << "Loppu!" << endl;
  98. return "";
  99. }
  100. else {
  101. cout << "Virhe: tuntematon komento!" << endl;
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement