Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1 A company database needs to store information about employees (identi

ID: 3783994 • Letter: Q

Question

Question 1 A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments (identified by dno, with dname and budget as attributes), and children of employees (with name and age as attributes). Employees work in departments; each department is managed by an employee; a child must be identified uniquely by name when the parent (who is an employee; assume that only one parent works for the company) is known. We are not interested in information about a child once the parent leaves the company.

Explanation / Answer

#include<iostream.h>

#include<conio.h>

#include<string.h>

#include <dos.h>

#include<process.h>

#include<fstream.h>

#include<stdio.h>

#include<graphics.h>//FOR GRAPHICS

#include<stdlib.h>

#include<dos.h>//FOR DELAY ETC.

#include<string.h>

//#include "box.h"int gdriver = DETECT, gmode, errorcode; //Meant for the opening page//For the Welcome Screenvoid smile(void)

{

     int midx,midy;

initgraph(&gdriver, &gmode, "d:\turboc3");

errorcode = graphresult();

if (errorcode != grOk) /* an error occurred */

{

      printf("Graphics error: %s ", grapherrormsg(errorcode));

      printf("Press any key to halt:");

      getch();

      exit(0);

}

setlinestyle(USERBIT_LINE,1,1);

rectangle(4,6,620,460);

midx = getmaxx() / 2;

midy = getmaxy() / 2;

settextjustify(CENTER_TEXT,CENTER_TEXT);

setbkcolor(9);

settextstyle(5,HORIZ_DIR,5);

outtextxy(midx,midy,"MASTERMIND PVT.LTD");

  getch();

closegraph();

}

//structure declaration struct employee {

           long code;

       char name[30];

           char address[60];

           char dob[10];

           char doj[10];

           char desg[20];

           char dept;

           float sal;

           char qlfn[20];

           char flag;

           }erec;

//function prototype declaration void newdata();

void accept_screen();

int generate_code();

void tabular_display();

void update();

void deldata();

void query();

void reports();

void gen_report();

void grp_report();

void pay_slip();

void smile();

fstream temp;       //global open mode void main(void)

{

clrscr();

smile(); //to call the opening page fn // structure for implementing date struct date d;

   getdate(&d);

   int choice;

   temp.open("emp.dat",ios::binary|ios::in|ios::out);

   do

     {

    clrscr();

//    mybox(2,1,4,77,3);

    gotoxy(20,3);textcolor(YELLOW);cprintf("EMPLOYEE DATABASE MANAGEMENT SYSTEM");

    gotoxy(2,5);textcolor(10);cprintf("Dated : %d/%d/%d",d.da_day,d.da_mon,d.da_year);

//    mybox(6,1,21,77,3);//    mybox(22,1,25,77,3);// section to set up a menu

    gotoxy(33,7);textcolor(YELLOW); cprintf("M E N U");

    gotoxy(27,12); textcolor(WHITE);cprintf("1. New Employee");

    gotoxy(27,13); cprintf("2. Update Employee");

    gotoxy(27,14); cprintf("3. Delete Employee");

    gotoxy(27,15); cprintf("4. Query Information");

    gotoxy(27,16); cprintf("5. Reports/Salary Slip");

    gotoxy(27,17); cprintf("6. Quit");

    // section to read and implement choice

    gotoxy(24,23); textcolor(YELLOW); cprintf("Enter Choice 1/2/3/4/5/6 ?");

    cin>>choice;

    switch(choice)

      {

         case 1 : newdata();break;

     case 2 : update(); break;

         case 3 : deldata();break;

         case 4 : query(); break;

         case 5 : reports();break;

         case 6 : exit(1);

      }

     }

     while (choice != 6);

}

//function to add new data to the table void newdata(void)

{

      char ch;

      long emp_code;

      //make the data Entry Screen Available

      emp_code=generate_code();

      accept_screen();

      //open the file in append mode //Read the contents into the Records

      erec.code=emp_code;

      gotoxy(28,6);   cout<<erec.code;

      gotoxy(28,8);   fflush(stdin); gets(erec.name);

      gotoxy(28,10); fflush(stdin); gets(erec.address);

      gotoxy(28,12); fflush(stdin); gets(erec.dob);

      gotoxy(28,14); fflush(stdin); gets(erec.doj);

      gotoxy(28,16); fflush(stdin); gets(erec.desg);

      gotoxy(37,18); fflush(stdin); cin>>erec.dept;

      gotoxy(28,20); fflush(stdin); cin>>erec.sal;

      gotoxy(28,22); fflush(stdin); gets(erec.qlfn);

      //write the record in to the table

      gotoxy(20,24); cprintf("Confirm Y/N?"); fflush(stdin); cin>>ch;

      if( ch=='y'|| ch=='Y')

      {

       erec.flag=' ';

       temp.seekp(0L,ios::end);

       temp.write((char*)&erec,sizeof(erec));

       temp.clear();

       }

      getch();

}

//function to create data entry screen void accept_screen(void)

{   clrscr();

// mybox(2,1,4,77,11);

gotoxy(27,3); textcolor(YELLOW); cprintf("New Employee details");

// mybox(5,1,23,77,11);// mybox(23,1,25,77,11);//DETAILS

textcolor(WHITE);

gotoxy(10,6); cprintf("Code     ");

gotoxy(10,8); cprintf("Name     ");

gotoxy(10,10); cprintf("Address ");

gotoxy(10,12); cprintf("Date of Birth   ");

gotoxy(10,14); cprintf("Date of Joining ");

gotoxy(10,16); cprintf("Designation :");

gotoxy(10,18); cprintf("Department [S/T/R/M/A ] ");

gotoxy(10,20); cprintf("Basic Pay               ");

gotoxy(10,22); cprintf("Qualification           ");

//selection to accept details

textbackground(BLUE); textcolor(WHITE);

gotoxy(28,6); cprintf("        ");

gotoxy(28,8); cprintf("                             ");

gotoxy(28,10); cprintf("                                ");

gotoxy(28,12); cprintf("                ");

gotoxy(28,14); cprintf("                ");

gotoxy(28,16); cprintf("                       ");

gotoxy(37,18); cprintf("    ");

gotoxy(28,20); cprintf("                  ");

gotoxy(28,22); cprintf("                 ");

textbackground(BLACK);

}

//function to track the Employee code; int generate_code(void)

{

     temp.seekg(0L,ios::beg);

     if(!temp.read((char*)&erec,sizeof(erec)))

     {

    temp.clear();

    return(100);

     }

     else

     {

     temp.seekg(0L,ios::beg); //point the pointer to the begining of the file while(temp.read((char*)&erec,sizeof(erec)));

     { }

     temp.clear();

     return(erec.code+1);

     }

}

//function to query record void query(void)

    { int ch,row=9;

    float tsal=0.0;

    char dpt;

    clrscr();

//    mybox(2,1,4,77,3);

    gotoxy(25,3); textcolor(YELLOW); cprintf("View/Query Employee Details");

//    mybox(4,1,6,77,3);

    textcolor(LIGHTGREEN);

    gotoxy(10,5); cprintf(" (1) All Records      (2) Criteria Based   Choce[1/2] ?");

    gotoxy(73,5); fflush(stdin); cin>>ch;

    switch(ch)

    {

    case 1:

        {

        //create a tabular format for display using boxes

        tabular_display();

        //call file for display

      temp.seekg(0L,ios::beg);

        textcolor(WHITE);

        while (temp.read((char *)&erec,sizeof(erec)))

        {

          gotoxy(2,row); cprintf("%d",erec.code);

          gotoxy(6,row); cprintf("%s",erec.name);

          gotoxy(28,row); cprintf("%s",erec.dob);

      gotoxy(38,row); cprintf("%s",erec.doj);

          gotoxy(48,row); cprintf("%s",erec.desg);

          gotoxy(58,row); cprintf("%c",erec.dept);

          gotoxy(62,row); cprintf("%8.2f",erec.sal);

          gotoxy(71,row); cprintf("%s",erec.qlfn);

          row++;

          if(row>22)

          {

              gotoxy(25,25);

              cprintf("More.....");

              getch();

              textcolor(WHITE);

              clrscr();

//              mybox(2,1,4,77,3);

              gotoxy(25,3); textcolor(YELLOW);

              cprintf("View/Query Employee Details");

              textcolor(LIGHTGREEN);

              gotoxy(10,5); cprintf(" (1) All Records    (2) Criteria based   Choice[1/2] ??");

              gotoxy(73,5);

              cout<<ch;

              tabular_display();

              row=9;

              }

          }

      temp.clear();

          }break;

    case 2: {

            tabular_display();

            textcolor(WHITE);

            gotoxy(26,6); cprintf("Department S/T/R/M/A >");

            gotoxy(48,6); cprintf(" ");

            fflush(stdin);

            gotoxy(48,6);

            cin>>dpt;

            //call the file for display

        temp.seekg(0L,ios::beg);

            textcolor(WHITE);

            //display section while(temp.read((char *)&erec,sizeof(erec)))

            {

              if(erec.dept==dpt)

              {

              tsal=tsal+erec.sal;

          gotoxy(2,row); cprintf("%d",erec.code);

          gotoxy(6,row); cprintf("%s",erec.name);

          gotoxy(28,row); cprintf("%s",erec.dob);

          gotoxy(38,row); cprintf("%s",erec.doj);

          gotoxy(48,row); cprintf("%s",erec.desg);

      gotoxy(58,row); cprintf("%c",erec.dept);

          gotoxy(62,row); cprintf("%8.2f",erec.sal);

          gotoxy(71,row); cprintf("%s",erec.qlfn);

          row++;

          if(row>22)

          {

              gotoxy(25,25);

              cprintf("More.....");

              getch();

              textcolor(WHITE);

              clrscr();

//          mybox(2,1,4,77,3);

          gotoxy(25,3); textcolor(YELLOW);

              cprintf("View/Query Employee Details");

              textcolor(LIGHTGREEN);

              gotoxy(10,5); cprintf(" (1) All Records    (2) Criteria based   Choice[1/2] ??");

              gotoxy(73,5);

              cout<<ch;

              tabular_display();

              row=9;

              }

          }

          }

      temp.clear();

          }

          //display the grand total

          textcolor(WHITE);

          gotoxy(20,25); cprintf("Departmentwise Total");

          gotoxy(60,25); cprintf("Rs.%.2f ",tsal);

          }

    getch();

    }

           void tabular_display(void)

           {

              //draw boxes //              mybox(6,1,24,5,3);//              mybox(6,5,24,27,3);//              mybox(6,27,24,37,3);//              mybox(6,37,24,47,3);//              mybox(6,47,24,57,3);//              mybox(6,57,24,61,3);//              mybox(6,61,24,70,3);//              mybox(6,70,24,77,3);//display headings

          textcolor(YELLOW);

          gotoxy(2,7); cprintf("ID#");

          gotoxy(12,7); cprintf("Name");

              gotoxy(30,7); cprintf("DOB");

          gotoxy(41,7); cprintf("DOJ");

              gotoxy(51,7); cprintf("Desg");

              gotoxy(58,7); cprintf("Dept");

              gotoxy(63,7); cprintf("Pay");

              gotoxy(72,7); cprintf("Qlfn");

              textcolor(WHITE);

           }

           //section to delete a record from the table void deldata(void)

           {

             int check = 0;

         long mcode;

             longint pos;

             int count=0;

             clrscr();

//             mybox(2,1,4,77,3);

         gotoxy(25,3); textcolor(YELLOW); cprintf("Delete Employee Details");

//             mybox(5,1,8,77,3);

         textcolor(LIGHTGREEN);

             gotoxy(25,7);

             cprintf("Enter the Search Code:"); cin>>mcode;

             temp.seekg(0L,ios::beg); //position the pointer to the begining of the file //search the employee code while(temp.read((char *)&erec,sizeof(erec)))

             {

               if(erec.code==mcode)

               {   erec.flag='*';

               check = 1;

               pos=count*sizeof(erec);

               temp.seekp(pos,ios::beg);

               temp.write((char *)&erec,sizeof(erec));

               break;

               }

             count++;

       }

           temp.clear();

           //section to permanently remove the matching record if (check == 0)

            {

             gotoxy(25,15); cprintf("No matching Records For Deletion");

             getch();

            }

           else

           {

             ofstream tp;

             tp.open("temp.dat",ios::binary|ios::out);

        //position the pointer to the begining of the file

             temp.seekg(0L,ios::beg);

            //search the record marked for deletion while(temp.read((char *)&erec,sizeof(erec)))

             {

              if(erec.flag!='*')

              tp.write((char *)&erec,sizeof(erec));

             }

             tp.clear();

             tp.close();

             temp.close();

         remove("emp.dat");

             rename("temp.dat","emp.dat");

             temp.open("emp.dat",ios::binary|ios::in|ios::out);

             textcolor(YELLOW);

             gotoxy(25,15); cprintf("Record Successfully Deleted");

             getch();

           }

    }

    //section to update record void update(void)

    {

    int count=0,check=0;

    longint pos;

    long mcode;

    clrscr();

//    mybox(2,1,4,77,3);

    gotoxy(25,3); textcolor(YELLOW); cprintf("Update Employee Details");

//    mybox(5,1,8,77,3);

    textcolor(WHITE); gotoxy(25,7); cprintf("Enter Update Code >");

    cin>>mcode;

//    mybox(9,1,25,77,3);//read File, display the original details & provide space to update //position to the begining of the file

    temp.seekg(0L,ios::beg);

    textcolor(WHITE);

    while(temp.read((char *)&erec,sizeof(erec)))

    {

       if(erec.code==mcode)

       {

       //first Display the original Contents

       check=1;

       gotoxy(2,12); cprintf("Code : %ld ",erec.code);

       gotoxy(2,13); cprintf("Name : %s ",erec.name);

       gotoxy(2,14); cprintf("Addr : %s ",erec.address);

       gotoxy(2,15); cprintf("Dob : %s ",erec.dob);

       gotoxy(2,16); cprintf("Doj : %s ",erec.doj);

       gotoxy(2,17); cprintf("Desg : %s ",erec.desg);

       gotoxy(2,18); cprintf("Dept : %c ",erec.dept);

       gotoxy(2,19); cprintf("Sal : %.2f ",erec.sal);

       gotoxy(2,20); cprintf("qlfn : %s ",erec.qlfn);

       //section to display pads for data entry

       textbackground(BLUE);

       textcolor(WHITE);

       gotoxy(30,12); cprintf("        ");

       gotoxy(30,13); cprintf("                         ");

       gotoxy(30,14); cprintf("                                   ");

       gotoxy(30,15); cprintf("            ");

       gotoxy(30,16); cprintf("            ");

       gotoxy(30,17); cprintf("            ");

       gotoxy(30,18); cprintf("   ");

       gotoxy(30,19); cprintf("              ");

       gotoxy(30,19); cprintf("              ");

       //section to read data

       gotoxy(30,12); cin>>erec.code;

       gotoxy(30,13); fflush(stdin); gets(erec.name);

       gotoxy(30,14); fflush(stdin); gets(erec.address);

       gotoxy(30,15); fflush(stdin); gets(erec.dob);

       gotoxy(30,16); fflush(stdin); gets(erec.doj);

       gotoxy(30,17); fflush(stdin); gets(erec.desg);

       gotoxy(30,18); fflush(stdin); cin>>erec.dept;

       gotoxy(30,19); fflush(stdin); cin>>erec.sal;

       gotoxy(30,20); fflush(stdin); gets(erec.qlfn);

       textbackground(BLACK);

       erec.flag=' ';

       //position the put pointer so that the //existing record is qverwitten

       pos=count*sizeof(erec);

       temp.seekp(pos,ios::beg);

       temp.write((char *)&erec,sizeof(erec));

       break;

       } //end of if statement

       count++;

    }//end of while loop if(check==0)

    {

    gotoxy(15,15); cprintf("No employee in File with matching code");

    gotoxy(15,16); cprintf("Press Any Key .........");

    getch();

    }

    temp.clear();

    }

    //section to print reports void reports(void)

    { int opt;

   do

    {

      clrscr();

//      mybox(2,1,4,77,3);

      gotoxy(35,3); textcolor(YELLOW);

      cprintf("R E P O R T S");

//     mybox(5,1,20,77,3);

      textcolor(WHITE);

      gotoxy(27,9); cprintf("1> General Report");

      gotoxy(27,11); cprintf("2> Grouped Report");

      gotoxy(27,13); cprintf("3> Salary Slip");

      gotoxy(27,15); cprintf("4> Exit");

      gotoxy(27,18); cprintf("Option 1/2/3/4 ?");   cin>>opt;

      switch(opt)

    {

      case 1:gen_report();break;

      case 2:grp_report();break;

      case 3:pay_slip();break;

    }

   }

   while (opt != 4);

} // end of reportsvoid gen_report(void)

{

    float tsum=0.0;

    struct date d;

    char stng[80];

    ofstream temp_write_file;

    getdate(&d);

    // open the Report.dat file for reading

    temp_write_file.open("temp.dat",ios::out);

    temp_write_file<<"                         MASTERMIND PVT.LTD"<<endl;

    temp_write_file<<"                     GENERAL EMPLOYEE REPORT"<<endl;

    temp_write_file<<"ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ"<<endl;

    // section to implement Date

    sprintf(stng," Dated:%d/%d/%d ",d.da_day,d.da_mon,d.da_year);

    temp_write_file<<stng<<endl;

    temp_write_file<<endl;

    strcpy(stng," ");

    temp_write_file<<"       Code               Name        Dept          Designation           Salary"<<endl;

    temp_write_file<<"ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ"<<endl;

    strcpy(stng," ");

    temp.seekg(0L,ios::beg); // reset the pointer to ther begining of the file while(temp.read((char *)&erec,sizeof(erec)))

     {

    sprintf(stng,"%11ld%19s%12c%21s%17.2f ",erec.code,erec.name,erec.dept,erec.desg,erec.sal);

    temp_write_file<<stng;

    tsum = tsum + erec.sal;

    strcpy(stng," ");

     }

    temp_write_file<<endl;

    temp_write_file<<"ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ"<<endl;

    //section to implement the grand Total

    sprintf(stng,"                                                   Grand total Rs.%.2f ",tsum);

    temp_write_file<<stng<<endl;

    temp_write_file<<"ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ"<<endl;

    temp_write_file<<"#"<<endl;

    temp_write_file.close();

    system("edit.com temp.dat");

    remove("temp.dat");

    temp.clear();

} // end of general report function void pay_slip(void)

{

    char stng[80];

    char line[80];

    float hra,gp,tax,np;

    int check = 0;

    int mcode;

    struct date d;

    getdate(&d);

    clrscr();

    gotoxy(10,10);

    textcolor(YELLOW);

    cprintf("Salary Slip for code # :");

    cin>>mcode;

    textcolor(WHITE);

    clrscr();

    ofstream temp_file;

    temp_file.open("temp.dat",ios::out);

    temp.seekg(0L,ios::beg);

    sprintf(stng,"                        MASTERMIND PVT.LTD");

    temp_file<<stng<<endl;

    strcpy(stng," ");

    sprintf(stng,"                          SALARY SLIP");

    temp_file<<stng<<endl;

    strcpy(stng," ");

    temp_file<<endl<<endl;

    sprintf(stng," Dated : %d/%d/%d ",d.da_day,d.da_mon,d.da_year);

    temp_file<<stng<<endl;

    temp_file<<"     ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ";

    // Now open the main file

    temp.seekg(0L,ios::beg);

    check = 0;

    while(temp.read((char *)&erec,sizeof(erec)))

      {

     if (erec.code == mcode)

     {

      check = 1;

      break; // if matching record is found break out

     }

      }

    if (check == 0)

     {

    gotoxy(20,25);

    cout<<"Sorry ! No matching Record!!!"<<endl;

    getch();

     }

    elseif (check == 1)

    {

    sprintf(stng, "       Name : %s                  Department   : %c ",erec.name,erec.dept);

    temp_file<<stng;

    temp_file<<"     ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ";

    // calculation section for hra,gp,tax and net pay switch(erec.dept)

      {

     case's':

     case'S': hra = 15 * erec.sal/100; break;

     case'T':

     case't': hra = 18 * erec.sal/100;break;

     case'R':

     case'r': hra = 24 * erec.sal/100; break;

     case'M':

     case'm': hra = 16 * erec.sal/100;break;

     case'A':

     case'a': hra = 19 * erec.sal/100;break;

    }

      gp = erec.sal + hra;

      // section to determine tax switch(erec.dept)

     {

       case'S':

       case's': tax = 3.5 * gp/100; break;

       case'T':

       case't': tax = 5 * gp/100;break;

       case'R':

       case'r': tax = 7 * gp/100;break;

       case'M':

       case'm': tax = 4.5 * gp/100;break;

       case'A':

       case'a': tax = 5.5 * gp/100;break;

     }

    np = gp- tax;

    // section to implement the remaining part of the file

    sprintf(stng,"                          Basic Salary Rs%12.2f ",erec.sal);

    temp_file<<stng;

    strcpy(stng," ");

    sprintf(stng,"                          HRA          Rs%12.2f ",hra);

    temp_file<<stng;

    strcpy(stng," ");

    sprintf(stng,"                          Gross Salary Rs%12.2f ",gp);

    temp_file<<stng;

    strcpy(stng," ");

    sprintf(stng, "                          Tax Deducted Rs%12.2f ",tax);

    temp_file<<stng;

    strcpy(stng," ");

    temp_file<<"     ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ";

    sprintf(stng,"                          Net Amount   Rs%12.2f ",np);

    temp_file<<stng;

    strcpy(stng," ");

    temp_file<<"     ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ";

    temp_file<<"#"<<endl;

    strcpy(stng," ");

    temp_file.close();

    system("edit.com temp.dat");

    remove("temp.dat");

    }

      temp.clear();

      temp.seekg(0L,ios::beg);

   } // end of function body void grp_report(void)     //for a grouped report

{

     // Here the complete file is read into a linked list. The // linked list is read repeatedly for each group seperately struct date d;

      getdate(&d);

      float sub_total=0.0;

      float grand_total =0.0;

      // structure for the linked list struct lemp

    {

      int code;

      char name[30];

      char desg[30];

      char dept;

      float sal;

      struct lemp *link;

    }*p,*q,*r;   // pointers to the structure // the first node is dummy

    p = new lemp; q=p; r=p;p->link = NULL;

    temp.seekg(0L,ios::beg);

    while (temp.read((char *)&erec, sizeof(erec)))

      {

        p = new lemp;

        p->code = erec.code;

        strcpy(p->name,erec.name);

        strcpy(p->desg,erec.desg);

        p->dept = erec.dept;

        p->sal = erec.sal;

        //cout<<p->code<<" "<<p->name<<" "<<p->desg<<" "<<p->dept<<" "<<p->sal<<endl;

        grand_total = grand_total + erec.sal;

        q->link = p;

        q = p;

      }

      q->link = NULL; // completed the linked list here

      getch();

      // open the file and prepare the grouped Report

      ofstream temp_file;

      temp_file.open("temp.dat",ios::out);

      char ndept[5] = {'S','T','R','M','A'};

      int i;

      char line[80];

      char stng[80];

      //........... implement the top heading of the Report..........

     sprintf(stng,"                         MASTERMIND PVT.LTD");

     temp_file<<stng<<endl;

     strcpy(stng," ");

     sprintf(stng,"                          GROUPED REPORT");

     temp_file<<stng<<endl;

     strcpy(stng," ");

     temp_file<<endl<<endl;

     sprintf(stng," Dated : %d/%d/%d ",d.da_day,d.da_mon,d.da_year);

     temp_file<<stng<<endl;

     temp_file<<"       Code               Name        Dept          Designation           Salary"<<endl;

     temp_file<<"ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ";

     // ............end of Heading of Report................... // Now to read the linked list based on Array for(i=0;i<5;++i)

       {

         p = r->link;

          if (ndept[i] == 'S')

              temp_file<<"Sales"<<endl;

            elseif (ndept[i] == 'T')

              temp_file<<"Training"<<endl;

            elseif (ndept[i] == 'R')

              temp_file<<"Research"<<endl;

            elseif (ndept[i] == 'M')

              temp_file<<"Marketing"<<endl;

            elseif (ndept[i] == 'A')

              temp_file<<"Administration"<<endl;

         while (p->link != NULL)

          {

           if(p->dept == ndept[i])

         {

           sub_total = sub_total + p->sal;

           sprintf(stng,"%11d%19s%12c%21s%17.2f ",p->code,p->name,p->dept,p->desg,p->sal);

           cout<<stng;

           temp_file<<stng;

           strcpy(stng," ");

         }

         p = p->link;

          }

          temp_file<<"ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ"<<endl;

          sprintf(stng,"                                                        Subtotal Rs %0.2f ",sub_total);

          temp_file<<stng;

          strcpy(stng," ");

          sub_total = 0;

        }

       temp_file<<"ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ"<<endl;

       sprintf(stng,"                                                    GrandTotal Rs. %0.2f ",grand_total);

       temp_file<<stng<<endl;

       strcpy(stng," ");

       temp_file<<"#"<<endl;

       temp_file.close();

       system("edit.com temp.dat");

       remove("temp.dat");

       temp.clear();

     }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote