I have to do this :
Task 2 (23%): Write a function that prompts the user to input data for a new employee; the function should return an employeeType struct to the caller. Declare employeeType variables him and her in the main function. Call your function with actual parameter him and again with actual parameter her. Call function printOne from the main to print out the values of him and her. Your lab TA will tell you what input values to use in the output you hand in.

Task 3 (23%) : Write a function name hireOne whose parameters are the array of structs, and the size of the list; the function should prompt the user to input a new employee and an index. ( you can call the function you wrote in Task 2 to prompt for the new person)If the index is within the correct limits, add the new employee to that index in the array.(Do not erase any employees; move data items to make room for the new one.) Call hireOne three times from the main function; print out the array after the calls. Hand in output for:
Jack Sprat, male, 2 dependents, $25.00, id 1212 added to index 5
Hillary Hacker, female, 1 dependent, $25.00, id 1113 added to index 1.
Thomas Trouble, male, 1 dependent, $5.00, id 9898 added to index 30.

Task 4 (23%): Use selection sort to sort the array in ascending order by pay rate. Print out the sorted array. ( code for selection sort is listed with project 4).

Task 5 (23%): Write a function named cutBacks. The parameters should be the array of structs and the size of the list. This function decreases the salary for each employee by 10%. Call your function from the main function. Print out the array after cutBacks is called.

and I have this as a code so far:

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
struct employeeType
{
       int id;
       string first;
       string last;
       char gender;
       double payrate;     
       int dependents;   
};
const int MAX_EMPLOYEES = 50;
  void getData(ifstream& inFile, employeeType list[], int& listSize);
  void printList(const employeeType list[],  int listSize) ;
  void printOne ( employeeType one);
  employeeType getOne ( ifstream& dataIn );
  employeeType newemployee();
  void selectionsort(employeeType list[], int);
  void cutBacks(employeeType list[], int);
  void hireOne(employeeType list[],int&);
  
  int main ()
    { employeeType him,her;
      employeeType list [MAX_EMPLOYEES ] ;
       int number ;      // number of employees in the file
       int i;
      ifstream dataFile;
      dataFile.open ( "Employees.txt");
      if (!dataFile)
      {
         cout << "bummer file\n\n";
         system ("pause");
         return 1;
      }  
      
      getData (dataFile,  list, number);
      cout << "There were " << number << " employees input. \n\n\n";
      printList(  list,  number) ; 
      him=newemployee();  
      her=newemployee();
      printOne(him);
      printOne(her);
      for(i=0;i<3;i++)
          hireOne(list,number);
      cout<<"before sort\n";
      printList(  list,  number) ; 
      selectionsort(list,number);  
        cout<<"after sort\n";
      printList(  list,  number) ; 
      cutBacks(list,number);  
        cout<<"after cutbacks\n";
      printList(  list,  number) ; 
      system ("pause" );
      return 0;
     }                //end of main
     
     ////////////////// Task 5
   void cutBacks(employeeType list[],int n)
       {int i;
       for(i=0;i<n;i++)
            list[i].payrate=list[i].payrate * 0.10;
       }   
       
       
       ////////////////// Task 3
   void hireOne(employeeType list[],int& n) 
       {int index,i;
       cout<<"\nenter the index for the new employee ";
       cin>>index;
       if(index<=n)
            {for(i=n;i>=index;i--)
                list[i+1]=list[i];
             list[index]=newemployee();
             n++;
            }
       else
           cout<<"Invalid index\n";
       } 
       
       
       /////////////// task 2
  employeeType newemployee()
      {employeeType p;
      cout<<"\nFor the New Employee:\n";
      cout<<"Enter ID: ";
      cin>>p.id;
       cout<<"Enter First Name: ";
      cin>>p.first;
      cout<<"Enter Last Name: ";
      cin>>p.last; 
      cout<<"Enter Gender: ";
      cin>>p.gender;
       cout<<"Enter Pay Rate:$ ";
      cin>>p.payrate;
      cout<<"Enter Number of Dependents: ";
      cin>>p.dependents;       
      return p;
      } 
      
      
      /////////// Task 4


void selectionsort( employeeType list[], int n)
{
    int i;
    int index;
    int min;
    employeeType temp;

    for (i = 0; i < n - 1; i++)
    {
            //Step a
        index = i; 

        for (min = i + 1; min < n; min++)
            if (list[min].payrate < list[i].payrate)
                i = min; 

            //Step b
        temp = list[i];
        list[index] = list[i];
        list[i] = temp;
    }
}
    ///////////////////////////////////////
// Input employees from the input file
    void getData(ifstream& inFile, employeeType list[], int& listSize) 
   {
       employeeType item ;
       listSize = 0;
       item = getOne (inFile) ;
       while (inFile && listSize < MAX_EMPLOYEES  )
      {
        list [listSize ] = item ;
        listSize++;
         item = getOne (inFile) ;
      } 
      if (inFile )
         cout << "not all data items were input; array too small\n\n";         
      inFile.close () ;
   }
  ///////////////////////////////////////
// Print out the list of employeeType structs 
    void printList(const employeeType list[],  int listSize)
    {
        int looper ;
         for ( looper = 0; looper <  listSize ; looper++)
         {
              printOne ( list [looper]  );
               cout << endl ;
         }    
   }
 ///////////////////////////////////////
// Input one employee from the input file
employeeType getOne ( ifstream& dataIn )
 { 
    employeeType one;
      dataIn >> one.first >> one.last >> one.gender
             >> one.id >> one.payrate >> one.dependents;
      return one;  
 } 
//////////////////////
  //print out one menuItemType struct
 void printOne ( employeeType one)
 {   
      cout << fixed << showpoint << setprecision (2);
      cout << "ID: " << one.id << endl;
      cout << "Name: " <<one.first << " " << one.last<< endl;
      cout << "Gender: " << one.gender <<endl;
      cout << "Pay Rate:$" << one.payrate << endl;
      cout << "Number of Dependents: " << one.dependents <<endl;
  }

Recommended Answers

All 4 Replies

Can you explain the problem that you are having? If you have a specific problem, if you could trim the code down to < 20 compliable lines that demonstrates the problem, that would me much easier for us to look at than just dumping 200 lines on us!

Dave

It is fine, I have found my answer while looking through it last night

If the answer could be helpful to others, could you please explain it here?

yes sure!
However, I am really new to this computer science stuff so let me find the right words that will not make me sound stupid! Or, if people have a specific question then maybe I can answer it that way

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.