Question

In: Computer Science

Write a menu-driven program to read 3 employees' information from a text file called “ EmployeeFile”...

Write a menu-driven program to read 3 employees' information from a text file called “ EmployeeFile” for this example but that can be edited to add more employees later.
Each employee has a name field, ID fields, and a Salary Record.
The Salary Record has weekly hours, rate per hour, gross salary, Tax, and net salary field.

1.1 Implement the project with queue using pointers

1.2 Write push and pop functions for queue using pointers

C++

EmployeeField.txt example


John_Doe 123456 40 45 4500 200 4300
Billy_Bob 654321 40 200 4000 200 3800
Kate_Johnson 531642 40 300 12000 200 11800

please make sure it works on free compilers online like https://repl.it/languages/cpp to be tested.

Solutions

Expert Solution

Solution ::

I am adding the code with comments so that you can understand easily...

if you have any doubt, please let me know in the comment box...

thank you...

#include<iostream>
#include<cstdio>      //Header file
#include<stdlib.h>
using namespace std;
struct node{   //structure
        char  name[80];
        int id,w_hours,rate,gross,tax,netsal;
        struct node *link;
        };
void push(struct node **top,struct node data){        //push function
        struct node *temp;
        temp=(struct node *)malloc(sizeof(struct node));   //Allocating memory dynamically for new node
        for(int i=0;data.name[i]!='\0';i++)
                temp->name[i]=data.name[i];


        temp->id=data.id;
        temp->w_hours=data.w_hours;
        temp->rate=data.rate;
        temp->gross=data.gross;
        temp->tax=data.gross;
        temp->netsal=data.netsal;
        temp->link=*top;    //making link with top node
        *top=temp;   //storing address of top in temp
        }
void pop(struct node **top){   //pop function
        struct node *temp;
        if(*top==NULL){           //checking if stack is empty
                cout<<"\nStack is empty";
                return;
                }
        temp=*top;
        char*  name=temp->name;    //storing the name whose data will be popped
        *top = (*top)->link;
        free(temp);   //deallocating temp
        cout<<"\n Data of "<<name<<" is popped";
        }
void display(struct node *top){   //function display
        while(top!=NULL){   //loop will continue until top becomes null
                cout<<top->name<<"  "<<top->id<<"  "<<top->w_hours<<"  "<<top->rate<<"  "<<top->gross<<"  "<<top->tax<<"  "<<top->netsal<<endl;
                top=top->link;
                }
        }
int main(){
struct node *top=NULL,data;   //declaring variable
char c;
int choice;  //choice for menu
FILE *fp;   //fp is a file pointer
data.link=NULL;   //we do not need link part for storing data temporary
fp=fopen("EmployeeField.txt","r");   //opening file in read mode
do {            //loop will skip the first line of the file
  c = fgetc(fp);
} while (c != '\n');
while(!feof(fp)){    //loop will continue until end of file
                fscanf(fp,"%s%d%d%d%d%d%d",data.name,&data.id,&data.w_hours,&data.rate,&data.gross,&data.tax,&data.netsal);//reading from file
                push(&top,data);   //push operation
                }
display(top);  //display
while(1){   //menu loop
        cout<<"\nFor push,press 1...\nFor pop,press 2...\nEsle for exit press any key...   ";
        cin>>choice;   //taking input choice
        if(choice==1){    //if choice ==1 then push
                cout<<"\nEnter Data seperated by space \n";
                cin>>data.name>>data.id>>data.w_hours>>data.rate>>data.gross>> data.tax>>data.netsal;
                push(&top,data);
                display(top);
                }
        else if(choice == 2){    //if choice == 2 then pop
                pop(&top);
                display(top);
                }
        else
                break;
        }
return 0;
    Thank you::::

Related Solutions

Write a modularized, menu-driven program to read a file with unknown number of records. Input file...
Write a modularized, menu-driven program to read a file with unknown number of records. Input file has unknown number of records of inventory items, but no more than 100; one record per line in the following order: item ID, item name (one word), quantity on hand , and a price All fields in the input file are separated by a tab (‘\t’) or a blank ( up to you) No error checking of the data required Create a menu which...
C++ programming question Write a program that will read input from a text file called "theNumbers.txt"...
C++ programming question Write a program that will read input from a text file called "theNumbers.txt" (you will have to provide your own when debugging). The text file that is to be opened is formatted a certain way, namely, there is always one integer, one character (representing an operation), another integer, and then a new line character, with spaces between each item. A sample text file is provided below. theNumbers.txt 144 + 26 3 * 18 88 / 4 22...
Please write a java program to write to a text file and to read from a...
Please write a java program to write to a text file and to read from a text file.
Write a java program that will read a file called stateinfo.txt and will store the information...
Write a java program that will read a file called stateinfo.txt and will store the information of the file into a map. The stateinfo.txt file contains the names of some states and their capitals. The format of stateinfo.txt file is as follows. State                Capital ---------                         ----------- NSW               Sydney VIC                 Melbourne WA                 Perth TAS                 Tasmania QLD                Brisbane SA                   Adelaide The program then prompts the user to enter the name of a state. Upon receiving the user input, the program should...
Your assignment is to write a C++ program to read a text file containing the information...
Your assignment is to write a C++ program to read a text file containing the information of the employees of a company, load them into memory and perform some basic human resources operations. This assignment will help you practice: multiple file programming, classes, public and private methods, dynamic memory allocation, constructors and destructors, singly linked list and files. Implementation This lab assignment gives you the opportunity to practice creating classes and using dynamic memory in one of the required classes....
The Menu-driven Program: Write a menu-driven program to implement a roomsboard for a classroom reservations system....
The Menu-driven Program: Write a menu-driven program to implement a roomsboard for a classroom reservations system. The menu includes the following options: Add new room. The program will prompt the user to enter the roomID, courseID and time of the new reserved room, then will call the add() method from the RoomsBoard class. Remove all occurrences of a room. The program will prompt the user to input the room ID to be removed, then call the remove() method from the...
Write a program that reads a file called document.txt which is a text file containing an...
Write a program that reads a file called document.txt which is a text file containing an excerpt from a novel. Your program should print out every word in the file that contains a capital letter on a new line to the stdout. For example: assuming document.txt contains the text C++
Write a simple menu-driven program called “Million Dollar Game”. The dice that we are using for...
Write a simple menu-driven program called “Million Dollar Game”. The dice that we are using for this game are special oriental dice. Each die has six different patterns. The six possible patterns are: Fish, Shrimp, Crab, Chicken, goldenCoin, Barrel. This game has three dice. In this game, the player can place his or her bet on any die-pattern. The amount of the winning prize is directly proportional to the number of matched dice after the two dice have been tossed...
Complete the program to read in values from a text file. The values will be the...
Complete the program to read in values from a text file. The values will be the scores on several assignments by the students in a class. Each row of values represents a specific student's scores. Each column represents the scores of all students on a specific assignment. So a specific value is a specific student's score on a specific assignment. The first two values in the text file will give the number of students (number of rows) and the number...
Complete the program to read in values from a text file. The values will be the...
Complete the program to read in values from a text file. The values will be the scores on several assignments by the students in a class. Each row of values represents a specific student's scores. Each column represents the scores of all students on a specific assignment. So a specific value is a specific student's score on a specific assignment. The first two values in the text file will give the number of students (number of rows) and the number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT