For example, it should be like this: Write a program that defines a Print Job st
ID: 3833146 • Letter: F
Question
For example, it should be like this:Write a program that defines a Print Job structure as follows: 1) An integer job Id 2) A string user name (maximum 25 characters) 3) An integer tray (tray will hold the tray number 1 for 8 by 11 paper, number 2 4) An integer for paper size (this will hold a percentage: 100% is normal, 150% is 1.5 times the size) 5) A string for whether the pages are to be sorted (all the page 1's together, all the page 2's together) or stacked (1, 2, 1, 2, 1, 2, etc.) 6) A character for whether the documents should be stapled (Y or N) 7) An integer coded for side (221 means to be printed double sided, taking 2 pages and turning it into 1 page, front and back; 121 means to be printed double sided, from a double sided document; 111 means 1 side only to 1 side only or a normal copy) 8) An integer number of copies 9) An integer status (1 means not printed, 0 means printed) Your program will load information from the file jobs.txt. Your program will read in an unknown number of jobs into an array (max of 10). The reading of the files may be done in main), or you may create a function for this. Your program will utilize four functions: displayMenu(): Will print the following menu and ask for the user's option. This function will return the choice to main. You must validate the users entry with a loop zooooRocks Copy Menu Press 1 to print the next job Press 2 to see the jobs in the print queue Press 3 to see the job have finished printing Press 0 to quit Enter choice: printJob(): Will print the job from the top of the list. This function will turn the status from 1 (not printed) to 0 (printed) display Job(): Will display all the jobs in the list still to be printed finishedJobs(): Will display all the jobs that have been printed.
Explanation / Answer
program:-
#include <stdio.h>
#include <stdlib.h>
typedef struct //defination of structure for jobs
{
//elements in job
int jobId;
char userName[10];
int tray;
int paperSize;
char sort[5];
char stapled[1];
int sideCode;
int copies;
int status;
}job;
int diaplayMenu() //display menu
{
int ch;
printf(" ZooooRocks Copy Menu Press 1 to print the next job Press 2 to see the jobs in print Queue Press 3 to see the job have finished printing Press 0 to Quit ");
scanf("%d",&ch);
return ch;
}
int printJob(job jobs[10],int i)//printing the jon
{
int j;
for(j=0;j<i;j++)
{
if(jobs[j].status==1)//check for job already print
{
printf(" %d %s %d %d %s %s %d %d %d", jobs[j].jobId, jobs[j].userName, jobs[j].tray, jobs[j].paperSize, jobs[j].sort, jobs[j].stapled, jobs[j].sideCode, jobs[j].copies, jobs[j].status);
return j;
}
}
}
void diaplayJob(job jobs[10],int i) //display all jobs
{
int j;
for(j=0;j<i;j++)
{
printf(" %d %s %d %d %s %s %d %d %d", jobs[j].jobId, jobs[j].userName, jobs[j].tray, jobs[j].paperSize, jobs[j].sort, jobs[j].stapled, jobs[j].sideCode, jobs[j].copies, jobs[j].status);
}
}
void finishedJob(job jobs[10],int i) //printing finished jobs
{
int j;
for(j=0;j<i;j++)
{
if(jobs[j].status==0)
printf(" %d %s %d %d %s %s %d %d %d", jobs[j].jobId, jobs[j].userName, jobs[j].tray, jobs[j].paperSize, jobs[j].sort, jobs[j].stapled, jobs[j].sideCode, jobs[j].copies, jobs[j].status);
}
}
int main(void)
{
job jobs[10];
int i=0,ch,j;
FILE *fPtr;
if ((fPtr = fopen("jobs.txt", "r")) == NULL) //open file jobs.txt
{
puts("cant open file to read");
}
else
{
while (!feof(fPtr)) //reading until end of file
{
fscanf(fPtr, "%d%s%d%d%s%s%d%d%d", &jobs[i].jobId, &jobs[i].userName, &jobs[i].tray, &jobs[i].paperSize, &jobs[i].sort, &jobs[i].stapled, &jobs[i].sideCode, &jobs[i].copies, &jobs[i].status);
i++;
}
fclose(fPtr);
}
do
{// performing job operations
ch=diaplayMenu();
switch(ch)
{
case 1:
j=printJob(jobs,i);
jobs[j].status=0;
break;
case 2:
diaplayJob(jobs,i);
break;
case 3:
finishedJob(jobs,i);
break;
case 0:
exit(0);
}
}while(ch!=0);
return 0;
}
input jobs.txt:-
100 kim 1 100 stack y 221 25 1
101 jim 2 150 sort y 121 100 1
102 jjj 1 100 stack n 221 30 1
103 hnh 2 100 stack y 121 30 1
output:-
ZooooRocks Copy Menu
Press 1 to print the next job
Press 2 to see the jobs in print Queue
Press 3 to see the job have finished printing
Press 0 to Quit
2
100 kim 1 100 stacky y 221 25 1
101 jim 2 150 sort y 121 100 1
102 jjj 1 100 stackn n 221 30 1
103 hnh 2 100 stacky y 121 30 1
ZooooRocks Copy Menu
Press 1 to print the next job
Press 2 to see the jobs in print Queue
Press 3 to see the job have finished printing
Press 0 to Quit
1
100 kim 1 100 stacky y 221 25 1
ZooooRocks Copy Menu
Press 1 to print the next job
Press 2 to see the jobs in print Queue
Press 3 to see the job have finished printing
Press 0 to Quit
2
100 kim 1 100 stacky y 221 25 0
101 jim 2 150 sort y 121 100 1
102 jjj 1 100 stackn n 221 30 1
103 hnh 2 100 stacky y 121 30 1
ZooooRocks Copy Menu
Press 1 to print the next job
Press 2 to see the jobs in print Queue
Press 3 to see the job have finished printing
Press 0 to Quit
3
100 kim 1 100 stacky y 221 25 0
ZooooRocks Copy Menu
Press 1 to print the next job
Press 2 to see the jobs in print Queue
Press 3 to see the job have finished printing
Press 0 to Quit
1
101 jim 2 150 sort y 121 100 1
ZooooRocks Copy Menu
Press 1 to print the next job
Press 2 to see the jobs in print Queue
Press 3 to see the job have finished printing
Press 0 to Quit
2
100 kim 1 100 stacky y 221 25 0
101 jim 2 150 sort y 121 100 0
102 jjj 1 100 stackn n 221 30 1
103 hnh 2 100 stacky y 121 30 1
ZooooRocks Copy Menu
Press 1 to print the next job
Press 2 to see the jobs in print Queue
Press 3 to see the job have finished printing
Press 0 to Quit
3
100 kim 1 100 stacky y 221 25 0
101 jim 2 150 sort y 121 100 0
ZooooRocks Copy Menu
Press 1 to print the next job
Press 2 to see the jobs in print Queue
Press 3 to see the job have finished printing
Press 0 to Quit
0
Process exited normally.
Press any key to continue . . .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.