-
Notifications
You must be signed in to change notification settings - Fork 0
/
first_task.cpp
61 lines (58 loc) · 1.3 KB
/
first_task.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <string>
#include "tasks.hpp"
#include "QueueWithPriority.hpp"
void lab3::doFirstTask()
{
QueueWithPriority<std::string> queue{};
std::string value="";
while(std::cin >> value)
{
if(value=="add")
{
std::string priority="";
std::cin >> priority;
std::cin.ignore();
std::string data="";
std::getline(std::cin,data);
if(data.empty())
{
std::cout << "<INVALID COMMAND>" << std::endl;
}
if(priority=="high")
{
queue.putElementToQueue(data,ElementPriority::HIGH);
} else if(priority=="normal")
{
queue.putElementToQueue(data,ElementPriority::NORMAL);
} else if(priority=="low")
{
queue.putElementToQueue(data,ElementPriority::LOW);
} else
{
std::cout << "<INVALID COMMAND>" << std::endl;
}
} else if(value=="get")
{
try
{
std::cout << queue.getElementFromQueue() << std::endl;
}
catch(std::out_of_range& e)
{
std::cout << "<EMPTY>" << std::endl;
}
} else if(value=="accelerate")
{
queue.accelerate();
}
else
{
std::cout << "<INVALID COMMAND>" << std::endl;
}
}
if (!std::cin.eof())
{
throw std::ios_base::failure("Reading error");
}
}