hi folks - i'm quite new to c++ and have written a program where i have used a linked list to simulate 3 printers working in a queue according to their priority. After much blood, sweat and tears I got that bit working.
Now I'm onto the second "easy" bit...I have to save the information as an array and display the data in various sorts ie in order of page numbers, priority and print order.

my struct looks like this
typedef struct //the structure of each print job
{
int jobNo;
int priority;
int noOfPages;
int printOrder;
}aJOB;

my array...\\using 10 items to test
aJOB arrayPrint [10];

int main()
{

srand( (unsigned int) time( NULL ));
int jobNumber = 1;
printQ theQ;
int i=0; //counter for modulus and keeping time
int noOfPages = 1;
int choice;
int x=1;
int printer1 = 0;
int tempNo = 0;
aJOB* ptrArray = NULL; //declare a pointer to an int
ptrArray = arrayPrint;

cout<<"select an order to display"<<endl;
cout<<"**************************"<<endl;
cout<<"Job Number - press 1"<<endl;
cout<<"Number of Pages - press 2"<<endl;
cout<<"Print Order - press 3"<<endl;

cin >> choice;
cout<<endl;

switch (choice)
{

case 1:
cout<<"Job Number"<<endl<<endl;
break;
case 2:
cout<<"Number of Pages"<<endl<<endl;

break;
case 3:
cout<<"Print Order"<<endl<<endl;

break;
default:
cout<<"you did not make a valid choice"<<endl;
break;
}

cout<<"job no\t\tno of pages\torder\t\tpriority"<<endl<<endl;
while ((jobNumber <= 3) || (!theQ.isEmpty()) || (printer1!=0)) //every minute a new job is sent
{
tempNo = jobNumber;

if ((i % 10 == 0) && (jobNumber <= 3))
{
theQ.insert(jobNumber);
jobNumber++;
}

if ((printer1 == 0) && (!theQ.isEmpty()))
{
printer1 = theQ.getNoOfPages();
theQ.ptrHead->printItem.printOrder = x++;
arrayPrint->jobNo = theQ.ptrHead->printItem.jobNo;
arrayPrint->noOfPages = theQ.ptrHead->printItem.noOfPages;
arrayPrint->printOrder = theQ.ptrHead->printItem.printOrder;
arrayPrint->priority = theQ.ptrHead->printItem.priority;
theQ.remove();
}

if (printer1 !=0) //printer holds the number of pages
printer1--;

if ((i % 10 == 0) && (tempNo != jobNumber) )
cout<<arrayPrint->jobNo<<"\t\t"<<arrayPrint->noOfPages<<"\t\t"<<arrayPrint->printOrder<<"\t\t"<<arrayPrint->priority<<endl<<endl;
//}
i++;//i also represents no of minutes the simulation is running

}
// delete [] arrayPrint;
return 0;

}

the menu is not properly set up yet - i know i am going to use a quick sort function, but at the moment i can only "extract" the first index of my array, and i need to be able to view the entire array. i thought that using [] would work, but because i am working with -> it appears not.

help and advice is much needed and would be much appreciated - i feel like i am so close!

thanks!

Member Avatar for iamthwee

First of all learn to use code tags.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.