cummings15 0 Newbie Poster

I need some help my code repeats the add new employee and is not asking for index.

What I was supposed to do.
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. 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


B-2 ) : Use selection sort to sort the array in descending order by pay rate. Print out the sorted array.

B-3): 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.

#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 addOne (employeeType list[], int& length);
 
  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++)
          addOne(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 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 3
  void addOne (employeeType list[], int& length)
{
     int where;
     employeeType what;
     
     cout<<"Enter the index for new employee.";
     cin>>where;
     if (length >=0 && where <= length ) {
                what = newemployee();
                for (int i = length -1; i >=where; i++)
                
     list [i+1] = list [i];
     
     list [where] = what;
     
     length++;
     }
     
     else 
     cout <<"illegal subscript " << endl;
     }
     
 
 
      /////////// 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;
    }
}

 ////////////////// Task 5
   void cutBacks(employeeType list[],int n)
       {int i;
       for(i=0;i<n;i++)
            list[i].payrate=list[i].payrate * 0.10;
       }   
 
    ///////////////////////////////////////
// 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;
  }
Be a part of the DaniWeb community

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