This calculator starts operation with showing output "Enter a Number" and afterwards, it asks for a mathematical symbol and if user doesn't input any valid mathematical symbols, it will show "Invalid Input" and ask for a valid mathematical symbol. After this, it takes input of another number and performs the mathematical operation and shows output.
The variables are taken as double so that we can input any kind of numbers.Â
The program first takes an integer n as input, which represents the number of tasks.
The priority_queue named Lia is declared. It stores objects of the Task class, where each task has a name and a priority. The tasks are ordered based on a custom comparator (compare), determining their priority.
For each task (loop runs n times), the program takes a name and a priority_serial (priority number). It creates a Task object and pushes it into the priority queue.
After all tasks are added, the program retrieves tasks in order of their priority (as determined by the comparator), prints each task's name and priority_serial, and removes them from the queue.
This code effectively sorts and outputs tasks based on their priority.
The Task class represents a task with two attributes:
name: A string representing the name of the task.
priority_serial: An integer representing the task's priority.
It has a constructor that initializes these attributes using the provided values. The this-> keyword is used to differentiate between the class member variables and the constructor parameters.
The compare class defines a custom comparison function used to order Task objects in the priority queue:
It overloads the () operator to compare two Task objects based on their priority_serial.
If one task's priority_serial is greater, it returns true (indicating that task should be lower in priority).
If the priorities are equal, it prompts the user to decide the order between the two tasks. Based on input, it returns true or false to adjust the order.