Question: Seperating C++ Code Into Multiple Files I have the below code in one file. I need to seperate it into the below files. Please tell
Seperating C++ Code Into Multiple Files
I have the below code in one file.
I need to seperate it into the below files.
Please tell me how to seperate it and what goes in which file.
FIles that i need to seperate below code into:
1. heap.h - declaration file for heap.
2. heap.cpp - implementation file for heap.
3. pqtype.h - declaration file for priority queue.
4. pqtype.cpp - implementation file for priority queue.
5. test.cpp - driver file.
Code i currently have in one file:
#include
using namespace std;
struct node { int priority; int snumber; string jobName; struct node *next; };
class PriorityQueue { private: node *front; public:
PriorityQueue() { front = NULL; }
void addJob(string item, int priority, int number)
{ node *temp, *q; temp = new node; temp->jobName = item; temp->priority = priority; temp->snumber = number; //whether queue is empty
if (front == NULL || priority < front->priority) { temp->next = front; front = temp; } else { q = front; while (q->next != NULL && q->next->priority <= priority) q = q->next; temp->next = q->next; q->next = temp; } }
void printJob()
{ node *temp; if (front == NULL) cout << "No print jobs in queue. "; else { temp = front; cout << "Now printing Job # " << temp->snumber << " " << temp->jobName << endl; front = front->next; free(temp); } }
void viewJob() { node *ptr; ptr = front; if (front == NULL) cout << "No print jobs in queue "; else { while (ptr != NULL) { cout << "Job #: " << ptr->snumber << " " << ptr->jobName << endl; ptr = ptr->next; } } } };
int main() { int choice, priority; PriorityQueue pq; char ch; string jobName; int number = 0; cout << "Printer queue" << endl; cout << "=============" << endl; do { cout << " 1.Add Job "; cout << "2.Print Job "; cout << "3.View Job "; cout << "4.Exit "; cout << "Enter choice : "; cin >> choice;
switch (choice) { case 1: cout << "Instructor (I or i), TA (T or t), or Student (S or s)? "; cin >> ch; if (ch == 'i' || ch == 'I') { priority = 1; jobName = "Instructor"; } else if (ch == 't' || ch == 'T') { priority = 2; jobName = "TA"; } else if (ch == 's' || ch == 'S') { priority = 3; jobName = "Student"; } number++; pq.addJob(jobName, priority, number); break;
case 2: pq.printJob(); break; case 3: pq.viewJob(); break; case 4: break; default: cout << "Invalid choice. "; } } while (choice != 4); system("PAUSE"); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
