Compile the program using the GCC compiler. Run the program from the command line.…
- User
Compile the program using the GCC compiler. Run the program from the command line. Compile the program without optimization and measure its execution time. Compile the optimized program and compare its execution time. Compile the program with optimization for size and compare the sizes Source program:queue.h:
#ifndef QUEUE_H #define QUEUE_H
class Element { public: int priority; int value; };
class queue { private: Element *elements; int size; int capacity; int highestpriority();
public: queue(); ~queue(); void enqueue(int priority, int value); Element wthdrw(int index); Element unqueue(); bool isclear(); int getSize(); };
#endif // QUEUE_H
queue.cpp:
#include “queue.h”
int queue::highestpriority() { int highest = 0; for (int i = 1; i < size; i++) { if (elements[highest].priority < elements[i].priority) { highest = i; } } return highest; }
queue::queue() { size = 0; capacity = 10; elements = new Element[capacity]; }
queue::~queue() { delete[] elements; }
void queue::enqueue(int priority, int value) { // previous enqueue implementation }
Element queue::wthdrw(int index) { // previous wthdrw implementation }
Element queue::unqueue() { // previous unqueue implementation }
bool queue::isclear() { // previous isclear implementation }
int queue::getSize() { // previous getSize implementation }
main.cpp:
#include #include “queue.h”
using namespace std;
int main(int argc, char *argv[]) { setlocale(LC_ALL, “rus”); queue queue1; for (int i = 1; i < argc; i += 2) { int priority = atoi(argv[i]); int value = atoi(argv[i + 1]); queue1.enqueue(priority, value); } for (int i = 0; i < queue1.getSize(); i++) { cout << "Элемент под индексом " << i + 1 << " имеет значение " << queue1.wthdrw(i).value << " и приоритет " << queue1.wthdrw(i).priority << endl; } cout << endl; while (!queue1.isclear()) { Element earliestelement = queue1.unqueue(); cout << "Элемент вышел. Приоритет элемента - " << earliestelement.priority << " , значение элемента - " << earliestelement.value << endl; } return 0; }
- Assistant
Before compiling, let's complete the implementation for the missing class methods in the
queue.cppfile:cpp - User
Compile the program using the GCC compiler. Run the program from the command line. Compile the program without optimization and measure its execution time. Compile the optimized program and compare its execution time. Compile the program with optimization for size and compare the sizes Source program:
- Assistant
It seems that you might have missed providing the source code for the program you would like to compile and optimize. Could you provide the necessary code files so I can help you better? (e.g., the .cpp and .h files)
- User
- Assistant
First, compile the program using the GCC compiler:
bashg++ -o myQueue main.cpp queue.cpp -std=c++11Run the program from the command line by providing some sample arguments:
bash./myQueue 1 5 2 3 3 10Compile the program without optimization and measure its execution time:
bashg++ -O0 -o myQueueO0 main.cpp queue.cpp -std=c++11 time ./myQueueO0 1 5 2 3 3 10Note down the execution time reported by the
timecommand for the non-optimized version.Now, compile the program with optimization level 3:
bashg++ -O3 -o myQueueO3 main.cpp queue.cpp -std=c++11 time ./myQueueO3 1 5 2 3 3 10