Question

In: Computer Science

I am having trouble fixing my build errors. The compiler I am using is Visual Studio.Thanks....

I am having trouble fixing my build errors. The compiler I am using is Visual Studio.Thanks.

#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

/*
* structure to store employee details
* employee details are stored as linked list
*/
struct Employee
{
private:

   string full_name; //full name
   double net_income; //income

public:
   struct Employee *next; //pointing to the next employee details in the list

                       /*
                       * create new employee node
                       */
   Employee(string full_name, double net_income)
   {
       this->full_name = full_name;
       this->net_income = net_income;
       this->next = NULL;
   }

   /*
   * display the details of this employee
   */
   void displayDetails()
   {
       cout << "\tFull name : " << full_name << endl;
       cout << "\tDaily salary: " << net_income << endl << endl;
   }
};

/*
* Implementation of Queue
*/
class EmployeeQueue
{
   struct Employee *front = NULL, *rear = NULL; // front and rear pointers of queue

public:
   /*
   * inset a new employee details into queue
   * this function take argument as a pointer to employee struct
   */
   void enqueue(struct Employee *newEmployee)
   {
       if (rear == NULL)
       {
           /*
           * empty wueue
           */
           rear = newEmployee;
           front = newEmployee;
       }
       else
       {
           /*
           * not empty
           * inseting new details at rear
           */
           rear->next = newEmployee;
           rear = newEmployee;
       }
   }

   /*
   * remove employee who is in front of the queue
   * this function return a pointer to employee struct
   */
   Employee* dequeue()
   {
       if (front == NULL)
       {
           /*
           * empty queue
           */
           return NULL;
       }

       /*
       * details of employee who is in front
       */
       struct Employee *leavingEmployee = front;

       front = front->next;

       if (front == NULL)
           rear = NULL;

       return leavingEmployee;
   }
};

int main()
{
   Employee * employee; //pointer of employee structure
   EmployeeQueue *queue = new EmployeeQueue(); //pointer of employee queue

   int ch = 0;
   string first_name;
   string last_name;
   string full_name;
   double work_hours;
   double hourly_rate;
   double tax_rate;
   double gross_salary;
   double net_salary;

   /*
   * iterate user inputs until exit command
   */

   while (ch != 3)
   {
       /*
       * displaying main menu
       */
       cout << endl << "1. Enter an employee information" << endl;
       cout << "2. Display information of employee who is leaving the work" << endl;
       cout << "3. Exit program" << endl;
       cout << "Enter your choice: ";
       cin >> ch; //getting choice

               /*
               * processing user choice
               */
   }

   switch (ch)
   {
   case 1:
   {   /*
       * choice to add new employee
       *
       * getting input of employee details
       */
       cout << "\tEnter first name of employee : ";
       cin >> first_name;
       cout << "\tEnter the last name of the employee : ";
       cin >> last_name;
       cout << "\tEnter working hours of the employee : ";
       cin >> work_hours;
       cout << "\tEnter the hourly working rate of the employee: ";
       cin >> hourly_rate;
       cout << "\tEnter the tax rate (%) of the employee : ";
       cin >> tax_rate;

       /*
       * finding full name
       *
       * full name = first name + last name
       */
       full_name = first_name + " " + last_name;

       /*
       * calculating gross salary
       *
       * gross salary = working hours * hourly rate
       */
       gross_salary = (work_hours * hourly_rate);

       /*
       * calculating net salary
       *
       * net salary = gross salary - (gross salary * (tax rate / 100)
       */
       net_salary = gross_salary - (gross_salary * tax_rate / 100.0);

       /*
       * creating new employee structure
       */
       employee = new Employee(full_name, net_salary);

       /*
       * inserting new employee details into queue
       */

       queue->enqueue(employee);
   }
   break;
   {case 2:
       /*
       * choice to display details
       */
       /*
       * getting details of employee who is leaving
       */
       employee = queue->dequeue();
   }
   if (employee != NULL)
   {
       /*
       * if not null displaying details
       */
       cout << "\tDetails of employee who is leaving:" << endl;
       employee->displayDetails();
   }
   else
   {
       /*
       * queue is empty
       */
       cout << "Queue is empty." << endl;
   }
   break;
   {   case 3:
       /*
       * choice to exit
       *
       * free all memories allocated dynamically
       */

   Employee * employee = NULL;
   free(employee);
   free(queue);
   break;
  
   default:
       /*
       * invalid choice
       */
       cout << "Invalid choice. Please enter it again." << endl;
  
   }
   }
   system("pause");
   return 0;

};


Solutions

Expert Solution

//corrected program

#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

/*
* structure to store employee details
* employee details are stored as linked list
*/
struct Employee
{
private:

string full_name; //full name
double net_income; //income

public:
struct Employee *next; //pointing to the next employee details in the list

/*
* create new employee node
*/
Employee(string full_name, double net_income)
{
this->full_name = full_name;
this->net_income = net_income;
this->next = NULL;
}

/*
* display the details of this employee
*/
void displayDetails()
{
cout << "\tFull name : " << full_name << endl;
cout << "\tDaily salary: " << net_income << endl << endl;
}
};

/*
* Implementation of Queue
*/
class EmployeeQueue
{
struct Employee *front = NULL, *rear = NULL; // front and rear pointers of queue

public:
/*
* inset a new employee details into queue
* this function take argument as a pointer to employee struct
*/
void enqueue(struct Employee *newEmployee)
{
if (rear == NULL)
{
/*
* empty wueue
*/
rear = newEmployee;
front = newEmployee;
}
else
{
/*
* not empty
* inseting new details at rear
*/
rear->next = newEmployee;
rear = newEmployee;
}
}

/*
* remove employee who is in front of the queue
* this function return a pointer to employee struct
*/
Employee* dequeue()
{
if (front == NULL)
{
/*
* empty queue
*/
return NULL;
}

/*
* details of employee who is in front
*/
struct Employee *leavingEmployee = front;

front = front->next;

if (front == NULL)
rear = NULL;

return leavingEmployee;
}
};

int main()
{
Employee * employee; //pointer of employee structure
EmployeeQueue *queue = new EmployeeQueue(); //pointer of employee queue

int ch = 0;
string first_name;
string last_name;
string full_name;
double work_hours;
double hourly_rate;
double tax_rate;
double gross_salary;
double net_salary;

/*
* iterate user inputs until exit command
*/

while (ch != 3)
{
/*
* displaying main menu
*/
cout << endl << "1. Enter an employee information" << endl;
cout << "2. Display information of employee who is leaving the work" << endl;
cout << "3. Exit program" << endl;
cout << "Enter your choice: ";
cin >> ch; //getting choice

/*
* processing user choice
*/

switch (ch)
{
case 1:
{ /*
* choice to add new employee
*
* getting input of employee details
*/
cout << "\tEnter first name of employee : ";
cin >> first_name;
cout << "\tEnter the last name of the employee : ";
cin >> last_name;
cout << "\tEnter working hours of the employee : ";
cin >> work_hours;
cout << "\tEnter the hourly working rate of the employee: ";
cin >> hourly_rate;
cout << "\tEnter the tax rate (%) of the employee : ";
cin >> tax_rate;

/*
* finding full name
*
* full name = first name + last name
*/
full_name = first_name + " " + last_name;

/*
* calculating gross salary
*
* gross salary = working hours * hourly rate
*/
gross_salary = (work_hours * hourly_rate);

/*
* calculating net salary
*
* net salary = gross salary - (gross salary * (tax rate / 100)
*/
net_salary = gross_salary - (gross_salary * tax_rate / 100.0);

/*
* creating new employee structure
*/
employee = new Employee(full_name, net_salary);

/*
* inserting new employee details into queue
*/

queue->enqueue(employee);

break;}
case 2:{

/*
* choice to display details
*/
/*
* getting details of employee who is leaving
*/
employee = queue->dequeue();

if (employee != NULL)
{
/*
* if not null displaying details
*/
cout << "\tDetails of employee who is leaving:" << endl;
employee->displayDetails();
}
else
{
/*
* queue is empty
*/
cout << "Queue is empty." << endl;
}
break;}
case 3:{
  
/*
* choice to exit
*
* free all memories allocated dynamically
*/

Employee * employee = NULL;
free(employee);
free(queue);
break;}
  
default:
/*
* invalid choice
*/
cout << "Invalid choice. Please enter it again." << endl;
  
}
}
system("pause");
return 0;

};

//sample output


Related Solutions

I am having trouble with my assignment and getting compile errors on the following code. The...
I am having trouble with my assignment and getting compile errors on the following code. The instructions are in the initial comments. /* Chapter 5, Exercise 2 -Write a class "Plumbers" that handles emergency plumbing calls. -The company handles natural floods and burst pipes. -If the customer selects a flood, the program must prompt the user to determine the amount of damage for pricing. -Flood charging is based on the numbers of damaged rooms. 1 room costs $300.00, 2 rooms...
I am currently having trouble understanding/finding the errors in this python code. I was told that...
I am currently having trouble understanding/finding the errors in this python code. I was told that there are 5 errors to fix. Code: #!/usr/bin/env python3 choice = "y" while choice == "y": # get monthly investment monthly_investment = float(input(f"Enter monthly investment (0-1000):\t")) if not(monthly_investment > 0 and monthly_investment <= 100): print(f"Entry must be greater than 0 and less than or equal to 1000. " "Please start over.")) #Error 1 extra ")" continue # get yearly interest rate yearly_interest_rate = float(input(f"Enter...
I am having a trouble with a python program. I am to create a program that...
I am having a trouble with a python program. I am to create a program that calculates the estimated hours and mintutes. Here is my code. #!/usr/bin/env python3 #Arrival Date/Time Estimator # # from datetime import datetime import locale mph = 0 miles = 0 def get_departure_time():     while True:         date_str = input("Estimated time of departure (HH:MM AM/PM): ")         try:             depart_time = datetime.strptime(date_str, "%H:%M %p")         except ValueError:             print("Invalid date format. Try again.")             continue        ...
Using dev c++ I'm having trouble with classes. I think the part that I am not...
Using dev c++ I'm having trouble with classes. I think the part that I am not understanding is sending data between files and also using bool data. I've been working on this program for a long time with many errors but now I've thrown in my hat to ask for outside help. Here is the homework that has given me so many issues: The [REDACTED] Phone Store needs a program to compute phone charges for some phones sold in the...
Hello, I am having trouble getting started on my project and building these functions. How do...
Hello, I am having trouble getting started on my project and building these functions. How do I build a function that continuously adds new "slices" to the list if they are below/above the size limit? I didn't copy the entire problem, but just for reference, when the code is run it will take user input for size limit (L), time cost for a random slice(R), and time cost for an accurate slice(A). Question: In real life, a steak is a...
I was able to calculate (a) but I am having trouble with the calculations of (b)....
I was able to calculate (a) but I am having trouble with the calculations of (b). Thanks! The following are New York closing rates for A$/US$ and $/£:                                     A$/$ = 1.5150;               $/£ = $1.2950             (a) Calculate the cross rate for £ in terms of A$ (A$/£).             (b) If £ is trading at A$1.95/£ in London (cross market) on the same day, is there an arbitrage opportunity?  If so, show how arbitrageurs with £ could profit from this opportunity and calculate the arbitrage...
Hello, I am having trouble with my Advanced Accounting Ch 18 homework. Accounting for nonprofts. Here...
Hello, I am having trouble with my Advanced Accounting Ch 18 homework. Accounting for nonprofts. Here are a few questions: At the beginning of the year, Nutrition Now, a health and welfare not-for-profit entity, had the following equity balances: Net assets without donor restriction $400,000 Net assets with donor restriction $290,000 1. Unrestricted contributions (pledges) of $250,000, to be collected in cash in thirty days, before the end of the year, are received. 2. Salaries of $27,000 are paid with...
TCP client and server using C programming I am having trouble on how to read in...
TCP client and server using C programming I am having trouble on how to read in the IP adress and port number from the terminal Example: Enter IP address: 127.0.0.1 Enter Port Number: 8000 in both client and server code. How do can I make I can assign the Ip address and port number using the example above. the error I get is that the client couldn't connect with the server whenever i get the port number from the user...
I am working through this solution in rstudio and am having trouble fitting this table into...
I am working through this solution in rstudio and am having trouble fitting this table into a linear regression analysis. an answer with corrosponding r code used would be greatly appreciated A study was conducted to determine whether the final grade of a student in an introductory psychology course is linearly related to his or her performance on the verbal ability test administered before college entrance. The verbal scores and final grades for all 1010 students in the class are...
I am taking a Data Structures and Program Design class. BUT, I am having trouble getting...
I am taking a Data Structures and Program Design class. BUT, I am having trouble getting access to the vectors so that I can compare the guesses with the random numbers. I’ve been working on this for several days and don't feel any closer to a solution and could really use some help as I really don't know how to get this to work. Thank you! The assignment is: Design an ADT for a one-person guessing game that chooses 4...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT