#include<iostream>
using namespace std;
class Doc
{
public:
static int doc_no;
int D_seq;
char D_name[20],u_name[20],Printer_No[20];
int D_page;
Doc *next_D;
Doc *sorted_Doc;
public:
Doc() {doc_no++; D_seq =0; u_name[0] = NULL;D_name[0] =NULL; Printer_No[0]=NULL; D_page =0; sorted_Doc= next_D =NULL;}
void get_Dinfo();
void set_Dinfo(char [],int,int);
void show_Dinfo();
};
int Doc::doc_no=0;
void Doc::get_Dinfo()
{
cout<<"\n Enter the Doument name: ";
cin>>D_name;
cout<<"\n Enter the number of document pages: ";
cin>>D_page;
cout<<"\n Enter Priority of document ";
cin>>D_seq;
}
void Doc::set_Dinfo (char N[],int P,int per)
{
strcpy(D_name,N);
D_page=P;
D_seq=per;
}
void Doc::show_Dinfo()
{
//cout<<"\nUser name : "<<u_name<<endl;
cout<<"\n Document priority is:"<<D_seq<<endl<<"\n Document name is:"<<D_name<<endl<<"\n Number of pages are:"<<D_page<<"\n\n";
}
class User
{
public:
int U_id;
char U_name[20];
User *next_U;
Doc *F_docu;
User(){U_id=0; U_name[0]=NULL; next_U=NULL; F_docu =NULL;}
void get_name();
void set_name(char []);
void show_info();
};
void User::get_name()
{
cout<<"\n Enter your name: ";
cin>>U_name;
cout<<"\n Enter your ID ";
cin>>U_id;
}
void User::set_name(char Z[])
{
strcpy(U_name,Z);
}
void User::show_info()
{
cout<<"\n User ID: "<<U_id<<"\n";
cout<<"\n User Name: "<<U_name<<"\n";
}
class PrinterSpooler
{
User *head;
User *current_U;
Doc * Sorted_doc;
Doc * Current_SD;
public:
PrinterSpooler (){head=NULL; current_U=NULL; Current_SD = Sorted_doc=NULL ;}
Doc * printer1;
Doc * printer2;
Doc * printer3;
void choose_printer(Doc*);
void printer_command();
void printing();
void print();
void show_allInfo();
};
void PrinterSpooler::printer_command()
{
system("CLS");
int id,Uid=0;
cout<<"\n Have you already a user ID .? \n\n if \"Yes\" then enter your ID else to create new id enter 0 "; cin>>id; cout<<"\n\n";
if (id==0)
{
User *new_Uid= new User ;
Doc * new_doc = new Doc;
choose_printer(new_doc );
if (head==NULL)
{
head=new_Uid ;
current_U=new_Uid;
Sorted_doc = new_doc ;
Current_SD = new_doc;
}
else
{
Current_SD->sorted_Doc = new_doc;
Current_SD=Current_SD->sorted_Doc ;
current_U = head;
while(current_U->next_U !=NULL)
{
current_U= current_U->next_U ;
}
current_U->next_U =new_Uid ;
current_U=new_Uid;
}
current_U->get_name();
new_doc->get_Dinfo ();
strcpy(new_doc->u_name ,current_U->U_name );
current_U->F_docu =new_doc ;
system("CLS");
current_U ->show_info ();
new_doc->show_Dinfo ();
system("PAUSE");
}
else
{
current_U = head;
while(current_U != NULL )
{
if(current_U->U_id == id)
{
Uid=id;
Doc *current_doc = head->F_docu;
//current_U ->F_docu->show_Dinfo() ;
Doc* new_doc= new Doc;
while(current_doc->next_D != NULL)
{
current_doc=current_doc ->next_D ;
}
Current_SD->sorted_Doc = new_doc;
Current_SD=Current_SD->sorted_Doc ;
current_doc->next_D=new_doc;
new_doc->get_Dinfo ();
strcpy(new_doc->u_name ,current_U->U_name );
strcpy(new_doc->Printer_No,current_U->F_docu->Printer_No );
}
current_U=current_U->next_U ;
}
if (Uid !=id)
{
cout<<"\n Id not found Plz create a new Id ...\n";
system("PAUSE");
printer_command ();
}
}
}
void PrinterSpooler::print()
{
system("CLS");
cout<<"All documents are to be printed ... \n";
Current_SD=Sorted_doc;
Doc *del=Sorted_doc;
while(Current_SD )
{
cout<<"\n\nCurrent printing document \n";
cout<<"\n\t\tPrinter : "<<Current_SD->Printer_No <<endl;
cout<<"\n\n User Name : "<<Current_SD->u_name <<endl;
Current_SD->show_Dinfo ();
Current_SD= Current_SD->sorted_Doc;
_sleep(5000);
system("CLS");
Doc *Cdel=del;
del=del->sorted_Doc;
delete (Cdel);
}
current_U = head;
User *Del=head;
del->doc_no =0;
User *Cdel=NULL;
while(Del)
{
Cdel = Del;
Del =Del->next_U;
delete(Cdel);
}
}
void PrinterSpooler::show_allInfo()
{
system("CLS");
cout<<"\n Info of all current user & documents";
cout<<"\n\n\n";
Current_SD=Sorted_doc;
while(Current_SD)
{
Current_SD->u_name ;
Current_SD->show_Dinfo ();
Current_SD = Current_SD->sorted_Doc;
}
system("PAUSE");
}
void PrinterSpooler::choose_printer(Doc* temp)
{
if (temp->doc_no%3 == 1)
strcpy(temp->Printer_No,"Printer 1\0");
else if (temp->doc_no%3 == 2)
strcpy(temp->Printer_No,"Printer 2\0");
else
strcpy(temp->Printer_No,"Printer 3\0");
}
void main()
{
char N='0';
while(N == '0')
{
char n='z';
PrinterSpooler test;
do
{
system("CLS");
cout<<"\n\n To print documents Press 0. OR \n\n To Show Info of All uers Press 1. OR \n\n To send commands to printer Press 2. OR \n\n To Exit Press 3 ";
cin>>n;
if(n=='2')
test.printer_command ();
if(n=='1')
test.show_allInfo();
if(n=='3')
exit(0);
}
while(n != '0');
test.show_allInfo ();
test.print ();
system("CLS");
cout<<"\n To proceed further press \"0\" or exit press any key ...\n";
cin>>N;
}
}
0 comments: