Apr 6, 2013 at 2:37am UTC  
 
in my program /i want to save employees data /using fstream as file employees.txt
and reading the data from the file of employees.txt to choosing the number of employees whose salaries are over (12000)
any one can help me to add this im my prgram.
I tried to do it in more ways than one, but there are many errors,I do not know what way
Is there a good way ?
thanks
Required of me is writing and reading of this file
If only in writing is easier but that writing and reading
I do not know how to start.
my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 
#include<iostream> 
#include <vector> 
#include <fstream> 
 
struct  employee                   //ahmed.ha.hnd 
{
    char  name[20];
    float   salary;
    int  birthday;
    char  sex [10];
};
 
int  main()
{
   employee emp[100];
    {
        int  n;
ofstream SaveFile;
SaveFile.open ("employees.txt" );
    
        std::cout << "A program for collecting employee information" ;
        std::cout << std::endl;
        std::cout << "And displaying the collected information" ;
        std::cout << std::endl << std::endl;
        std::cout << "How many employees:" ;
        std::cin >> n;
        std::cout << std::endl;
        std::cout << "Enter the following information:" <<std::endl;
        std::cout << std::endl;
    
        for (int  i=0; i<n; i++)
        {
            std::cout << "Enter information for employee no: "  << i<< std::endl;
            std::cout << "================================="  << std::endl;
            std::cout<<"Enter the Employee name :"  ;std::cin>>emp[i].name;
            std::cout<<"Enter the salary :" ;std::cin>>emp[i].salary;
            std::cout<<"Enter the birthday :" ;std::cin>>emp[i].birthday ;
            std::cout<<"Enter the sex :" ;std::cin>>emp[i].sex;
            std::cout<<std::endl;
	SaveFile << " " << emp[i].name,emp[i].salary,emp[i].birthday,emp[i].sex;
			
        }
        {
            employee temp;
            for (int  i = 0; i < n; i++)
            {
                for (int  j = i+1; j < n; j++)
                {
                    if (emp[i].salary<emp[j].salary)
                    {
                        temp=emp[i];
                        emp[i]=emp[j];
                        emp[j]=temp;
                    }
                }
            }
 
                std::cout << "Employee entered information:" << std::endl;
                std::cout << "============================"  << std::endl;
                std::cout << "Name  salary birthday   Sex       "  << std::endl;
 
            for (i = 0; i < n; i++)
            {
                        std::cout << emp[i].name                << "\t" ;
                        std::cout << emp[i].salary << "\t" ;
                        std::cout << emp[i].birthday; std::cout << "\t" ;
                        std::cout << emp[i].sex    ;
                        std::cout << std::endl;
            
            }
 
            int  highest_salary=0; 
            int  total_salary=0; 
            for (i = 0; i < n; i++)
            {
                if (emp[i].salary > highest_salary)
                {
                    highest_salary = emp[i].salary;
                }
                total_salary += emp[i].salary;
            }
            std::cout<<std::endl;
            std::cout << "Total Salary: "    << total_salary <<std::endl;
            std::cout << "============" <<std::endl;
            std::cout << "Highest Salary: "  << highest_salary << std::endl;
            std::cout << "==============" <<std::endl;
            std::cout<<std::endl;
    
int  number = 0;
for (i = 0; i < n; i++)
{
    if (emp[i].salary>=15000) 
	{
        number++;
	}
}
std::cout<<"Number of employees who salary more than 15000 :" <<std::endl;
std::cout<<"==============================================" <<std::endl;
std::cout<<number<<std::endl;
std::cout<<std::endl;
            float  tax=0;      
            
    for (i = 0; i < n; i++)
	{
            if (emp[i].salary <= 1999)
            {
                tax = (emp[i].salary*5)/100.0;
            }
            else  if  (emp[i].salary<=2999)
            {
                tax=(emp[i].salary*7.5)/100.0;
            }
    
            else  if  (emp[i].salary<=3999)
            {
                tax=(emp[i].salary*10)/100.0;
            }
            else   if  (emp[i].salary>4000)
            {
                tax=(emp[i].salary*15)/100.0;
            }
 
            emp[i].salary -= tax;
	}
            std::cout<<"Salary after tax :" <<"  Employee Name :   " <<std::endl;
            std::cout<<"================ "  <<"   =============" <<std::endl;
            for (i = 0; i < n; i++)
            std::cout <<  emp[i].salary<<"                   "   <<  emp[i].name << std::endl;                    
            std::cout<<std::endl;
	
}
}
}
 
 
Last edited on Apr 6, 2013 at 7:00pm UTC  
 
 
 
 
  Apr 6, 2013 at 4:35am UTC  
 
If you want to write your output to the file "employees.txt", replace "cout" with your filehandle.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 
#include <fstream> 
using  namespace  std;
ofstream outfile; // This is your filehandle 
int  main()
{
     outfile.open("employees.txt" );
     outfile << "Whatever you want in the file\n" ;
     outfile.close();
     return  0;
}
 
 
Last edited on Apr 6, 2013 at 5:04am UTC  
 
 
 
 
  Apr 6, 2013 at 4:56am UTC  
 
Pay attention to my code. You left out "using namespace std" in your code. Without "using namespace std", you have to use the scope operator when you define your filehandle.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 
#include <fstream> 
std::ofstream outfile;
int  main()
{
    outfile.open("employee.txt" );
    outfile << "My output\n" ;
    outfile.close();
    return  0;
}
 
In your case, you really should consider putting "using namespace std" at the top of your code, as it would save you a lot of typing.
Also, I'm not sure what the stuff outside of your main function is (the employee emp[100]; and ............). Your code will never compile with random junk sitting at the bottom below main.
 
Last edited on Apr 6, 2013 at 5:03am UTC  
 
 
 
 
  Apr 6, 2013 at 5:11am UTC  
 
too ,gave me an  2 error
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 
#include<iostream> 
#include <vector> 
#include <fstream> 
 
std::ofstream outfile;
struct  employee                   //ahmed.ha.hnd 
{
    char  name[20];
    float   salary;
    int  birthday;
    char  sex [10];
};
 
int  main()
{
outfile.open("employees.txt" );
  
     outfile.close();
     return  0;
   employee emp[100];
    {
        int  n;
    
        std::cout << "A program for collecting employee information" ;
        std::cout << std::endl;
        std::cout << "And displaying the collected information" ;
        std::cout << std::endl << std::endl;
        std::cout << "How many employees:" ;
        std::cin >> n;
        std::cout << std::endl;
        std::cout << "Enter the following information:" <<std::endl;
        std::cout << std::endl;
    
        for (int  i=0; i<n; i++)
        {
            std::cout << "Enter information for employee no: "  << i<< std::endl;
            std::cout << "================================="  << std::endl;
            std::cout<<"Enter the Employee name :"  ;std::cin>>emp[i].name;
            std::cout<<"Enter the salary :" ;std::cin>>emp[i].salary;
            std::cout<<"Enter the birthday :" ;std::cin>>emp[i].birthday ;
            std::cout<<"Enter the sex :" ;std::cin>>emp[i].sex;
            std::cout<<std::endl;
    outfile <<emp[i].name,emp[i].salary,emp[i].birthday,emp[i].sex \n;
        }
 
        {
            employee temp;
            for (int  i = 0; i < n; i++)
            {
                for (int  j = i+1; j < n; j++)
                {
                    if (emp[i].salary<emp[j].salary)
                    {
                        temp=emp[i];
                        emp[i]=emp[j];
                        emp[j]=temp;
                    }
                }
            }
 
                std::cout << "Employee entered information:" << std::endl;
                std::cout << "============================"  << std::endl;
                std::cout << "Name  salary birthday   Sex       "  << std::endl;
 
            for (i = 0; i < n; i++)
            {
                        std::cout << emp[i].name                << "\t" ;
                        std::cout << emp[i].salary << "\t" ;
                        std::cout << emp[i].birthday; std::cout << "\t" ;
                        std::cout << emp[i].sex    ;
                        std::cout << std::endl;
            
            }
 
            int  highest_salary=0; 
            int  total_salary=0; 
            for (i = 0; i < n; i++)
            {
                if (emp[i].salary > highest_salary)
                {
                    highest_salary = emp[i].salary;
                }
                total_salary += emp[i].salary;
            }
            std::cout<<std::endl;
            std::cout << "Total Salary: "    << total_salary <<std::endl;
            std::cout << "============" <<std::endl;
            std::cout << "Highest Salary: "  << highest_salary << std::endl;
            std::cout << "==============" <<std::endl;
            std::cout<<std::endl;
    
int  number = 0;
for (i = 0; i < n; i++)
{
    if (emp[i].salary>=15000) 
	{
        number++;
	}
}
std::cout<<"Number of employees who salary more than 15000 :" <<std::endl;
std::cout<<"==============================================" <<std::endl;
std::cout<<number<<std::endl;
std::cout<<std::endl;
            float  tax=0;      
            
    for (i = 0; i < n; i++)
	{
            if (emp[i].salary <= 1999)
            {
                tax = (emp[i].salary*5)/100.0;
            }
            else  if  (emp[i].salary<=2999)
            {
                tax=(emp[i].salary*7.5)/100.0;
            }
    
            else  if  (emp[i].salary<=3999)
            {
                tax=(emp[i].salary*10)/100.0;
            }
            else   if  (emp[i].salary>4000)
            {
                tax=(emp[i].salary*15)/100.0;
            }
 
            emp[i].salary -= tax;
	}
            std::cout<<"Salary after tax :" <<"  Employee Name :   " <<std::endl;
            std::cout<<"================ "  <<"   =============" <<std::endl;
            for (i = 0; i < n; i++)
            std::cout <<  emp[i].salary<<"                   "   <<  emp[i].name << std::endl;                    
            std::cout<<std::endl;
	
}
}
}
 
 
Last edited on Apr 6, 2013 at 5:13am UTC  
 
 
 
 
  Apr 6, 2013 at 5:17am UTC  
 
Now works without mistakes
But  the prgram  just gave me 
Press any key to continue
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 
#include<iostream> 
#include <vector> 
#include <fstream> 
 
std::ofstream outfile;
struct  employee                   //ahmed.ha.hnd 
{
    char  name[20];
    float   salary;
    int  birthday;
    char  sex [10];
};
 
int  main()
{
outfile.open("employees.txt" );
     
     outfile.close();
     return  0;
   employee emp[100];
    {
        int  n;
    
        std::cout << "A program for collecting employee information" ;
        std::cout << std::endl;
        std::cout << "And displaying the collected information" ;
        std::cout << std::endl << std::endl;
        std::cout << "How many employees:" ;
        std::cin >> n;
        std::cout << std::endl;
        std::cout << "Enter the following information:" <<std::endl;
        std::cout << std::endl;
    
        for (int  i=0; i<n; i++)
        {
            std::cout << "Enter information for employee no: "  << i<< std::endl;
            std::cout << "================================="  << std::endl;
            std::cout<<"Enter the Employee name :"  ;std::cin>>emp[i].name;
            std::cout<<"Enter the salary :" ;std::cin>>emp[i].salary;
            std::cout<<"Enter the birthday :" ;std::cin>>emp[i].birthday ;
            std::cout<<"Enter the sex :" ;std::cin>>emp[i].sex;
            std::cout<<std::endl;
 
        }
 
        {
            employee temp;
            for (int  i = 0; i < n; i++)
            {
                for (int  j = i+1; j < n; j++)
                {
                    if (emp[i].salary<emp[j].salary)
                    {
                        temp=emp[i];
                        emp[i]=emp[j];
                        emp[j]=temp;
                    }
                }
            }
 
                std::cout << "Employee entered information:" << std::endl;
                std::cout << "============================"  << std::endl;
                std::cout << "Name  salary birthday   Sex       "  << std::endl;
 
            for (i = 0; i < n; i++)
            {
                        std::cout << emp[i].name                << "\t" ;
                        std::cout << emp[i].salary << "\t" ;
                        std::cout << emp[i].birthday; std::cout << "\t" ;
                        std::cout << emp[i].sex    ;
                        std::cout << std::endl;
outfile <<emp[i].name,emp[i].salary,emp[i].birthday,emp[i].sex ;
            
            }
 
            int  highest_salary=0; 
            int  total_salary=0; 
            for (i = 0; i < n; i++)
            {
                if (emp[i].salary > highest_salary)
                {
                    highest_salary = emp[i].salary;
                }
                total_salary += emp[i].salary;
            }
            std::cout<<std::endl;
            std::cout << "Total Salary: "    << total_salary <<std::endl;
            std::cout << "============" <<std::endl;
            std::cout << "Highest Salary: "  << highest_salary << std::endl;
            std::cout << "==============" <<std::endl;
            std::cout<<std::endl;
    
int  number = 0;
for (i = 0; i < n; i++)
{
    if (emp[i].salary>=15000) 
	{
        number++;
	}
}
std::cout<<"Number of employees who salary more than 15000 :" <<std::endl;
std::cout<<"==============================================" <<std::endl;
std::cout<<number<<std::endl;
std::cout<<std::endl;
            float  tax=0;      
            
    for (i = 0; i < n; i++)
	{
            if (emp[i].salary <= 1999)
            {
                tax = (emp[i].salary*5)/100.0;
            }
            else  if  (emp[i].salary<=2999)
            {
                tax=(emp[i].salary*7.5)/100.0;
            }
    
            else  if  (emp[i].salary<=3999)
            {
                tax=(emp[i].salary*10)/100.0;
            }
            else   if  (emp[i].salary>4000)
            {
                tax=(emp[i].salary*15)/100.0;
            }
 
            emp[i].salary -= tax;
	}
            std::cout<<"Salary after tax :" <<"  Employee Name :   " <<std::endl;
            std::cout<<"================ "  <<"   =============" <<std::endl;
            for (i = 0; i < n; i++)
            std::cout <<  emp[i].salary<<"                   "   <<  emp[i].name << std::endl;                    
            std::cout<<std::endl;
	
}
}
}
 
 
Last edited on Apr 6, 2013 at 5:19am UTC  
 
 
 
 
  Apr 6, 2013 at 5:27am UTC  
 
This part of your code:
1 2 3 4 5 6 7 8 9 10 11 12 13 
int  main()
{
outfile.open("employees.txt" );
     
     outfile.close();
     return  0;
   employee emp[100];
    {
        int  n;
 
You are opening your file, then immediately closing it and returning 0 inside main, which tells the operating system the program is done. That is why you are not getting any results...
 
Last edited on Apr 6, 2013 at 5:27am UTC  
 
 
 
 
  Apr 6, 2013 at 5:40am UTC  
 
Here, I got it to compile. I have no idea if this is what you want.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 
#include <iostream> 
#include <vector> 
#include <fstream> 
using  namespace  std;
ofstream outfile;
struct  employee                   //ahmed.ha.hnd 
{
    char  name[20];
    float   salary;
    int  birthday;
    char  sex [10];
};
int  main()
{
outfile.open("employees.txt" );
   employee emp[100];
    {
        int  n;
        cout << "A program for collecting employee information" ;
        cout << endl;
        cout << "And displaying the collected information" ;
        cout << endl << endl;
        cout << "How many employees:" ;
        cin >> n;
        cin.ignore();
        cout << endl;
        cout << "Enter the following information:" <<endl;
        cout << endl;
        for (int  i=0; i<n; i++)
        {
            cout << "Enter information for employee no: "  << i<< endl;
            cout << "================================="  << endl;
            cout<<"Enter the Employee name :"  ;cin>>emp[i].name;
            cin.ignore();
            cout<<"Enter the salary :" ;cin>>emp[i].salary;
            cin.ignore();
            cout<<"Enter the birthday :" ;cin>>emp[i].birthday ;
            cin.ignore();
            cout<<"Enter the sex :" ;cin>>emp[i].sex;
            cin.ignore();
            cout<<endl;
        }
        {
            employee temp;
            for (int  o = 0; o < n; o++)
            {
                for (int  j = o+1; j < n; j++)
                {
                    if (emp[o].salary<emp[j].salary)
                    {
                        temp=emp[o];
                        emp[o]=emp[j];
                        emp[j]=temp;
                    }
                }
            }
                cout << "Employee entered information:" << endl;
                cout << "============================"  << endl;
                cout << "Name  salary birthday   Sex       "  << endl;
            for (int  x = 0; x < n; x++)
            {
                        cout << emp[x].name                << "\t" ;
                        cout << emp[x].salary << "\t" ;
                        cout << emp[x].birthday; cout << "\t" ;
                        cout << emp[x].sex    ;
                        cout << endl;
cout <<emp[x].name,emp[x].salary,emp[x].birthday,emp[x].sex ;
            }
            int  highest_salary=0;
            int  total_salary=0;
            for (int  y = 0; y < n; y++)
            {
                if (emp[y].salary > highest_salary)
                {
                    highest_salary = emp[y].salary;
                }
                total_salary += emp[y].salary;
            }
            cout<<endl;
            cout << "Total Salary: "    << total_salary <<endl;
            cout << "============" <<endl;
            cout << "Highest Salary: "  << highest_salary << endl;
            cout << "==============" <<endl;
            cout<<endl;
int  number = 0;
for (int  e = 0; e < n; e++)
{
    if (emp[e].salary>=15000)
	{
        number++;
	}
}
cout<<"Number of employees who salary more than 15000 :" <<endl;
cout<<"==============================================" <<endl;
cout<<number<<endl;
cout<<endl;
            float  tax=0;
    for (int  i = 0; i < n; i++)
	{
            if (emp[i].salary <= 1999)
            {
                tax = (emp[i].salary*5)/100.0;
            }
            else  if  (emp[i].salary<=2999)
            {
                tax=(emp[i].salary*7.5)/100.0;
            }
            else  if  (emp[i].salary<=3999)
            {
                tax=(emp[i].salary*10)/100.0;
            }
            else   if  (emp[i].salary>4000)
            {
                tax=(emp[i].salary*15)/100.0;
            }
            emp[i].salary -= tax;
	}
            cout<<"Salary after tax :" <<"  Employee Name :   " <<endl;
            cout<<"================ "  <<"   =============" <<endl;
            for (int  p = 0; p < n; p++)
            cout <<  emp[p].salary<<"                   "   <<  emp[p].name << endl;
            cout<<endl;
}
}
cin.get();
outfile.close();
     return  0;
}
 
You can make it output to a file if you want. It only runs in a console as of now.
 
Last edited on Apr 6, 2013 at 5:43am UTC  
 
 
 
 
  Apr 6, 2013 at 6:03am UTC  
 
I want to save all employee information 
Name, salary, sex, birth, total salaries and higher salary and the number of staff who larger salary over  15,000 and salaries after tax . 
you ar edited my code its good but the program gaves me this error : 
inking... 
fvf.obj : error LNK2005: _main already defined in hh.obj 
fvf.obj : error LNK2005: "class std::basic_ofstream<char,struct std::char_traits<char> > outfile" (?outfile@@3V?$basic_ofstream@DU?$char_traits@D@std@@@std@@A) already defined in hh.obj 
Debug/hh.exe : fatal error LNK1169: one or more multiply defined symbols found 
Error executing link.exe. 
 
hh.exe - 3 error(s), 0 warning(s) 
 
 
 
 
  Apr 6, 2013 at 6:07am UTC  
 
Look
In the previous code work well
But out of this:
ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ
What do you think?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 
#include<iostream> 
#include <vector> 
#include <fstream> 
 
std::ofstream outfile;
struct  employee                   //ahmed.ha.hnd 
{
    char  name[20];
    float   salary;
    int  birthday;
    char  sex [10];
};
 
int  main()
{
outfile.open("employees.txt" );
     
     
   employee emp[100];
    {
        int  n;
    
        std::cout << "A program for collecting employee information" ;
        std::cout << std::endl;
        std::cout << "And displaying the collected information" ;
        std::cout << std::endl << std::endl;
        std::cout << "How many employees:" ;
        std::cin >> n;
        std::cout << std::endl;
        std::cout << "Enter the following information:" <<std::endl;
        std::cout << std::endl;
    
        for (int  i=0; i<n; i++)
        {
            std::cout << "Enter information for employee no: "  << i<< std::endl;
            std::cout << "================================="  << std::endl;
            std::cout<<"Enter the Employee name :"  ;std::cin>>emp[i].name;
            std::cout<<"Enter the salary :" ;std::cin>>emp[i].salary;
            std::cout<<"Enter the birthday :" ;std::cin>>emp[i].birthday ;
            std::cout<<"Enter the sex :" ;std::cin>>emp[i].sex;
            std::cout<<std::endl;
 
        }
 
        {
            employee temp;
            for (int  i = 0; i < n; i++)
            {
                for (int  j = i+1; j < n; j++)
                {
                    if (emp[i].salary<emp[j].salary)
                    {
                        temp=emp[i];
                        emp[i]=emp[j];
                        emp[j]=temp;
                    }
                }
            }
 
                std::cout << "Employee entered information:" << std::endl;
                std::cout << "============================"  << std::endl;
                std::cout << "Name  salary birthday   Sex       "  << std::endl;
 
            for (i = 0; i < n; i++)
            {
                        std::cout << emp[i].name                << "\t" ;
                        std::cout << emp[i].salary << "\t" ;
                        std::cout << emp[i].birthday; std::cout << "\t" ;
                        std::cout << emp[i].sex    ;
                        std::cout << std::endl;
            
            }
 
            int  highest_salary=0; 
            int  total_salary=0; 
            for (i = 0; i < n; i++)
            {
                if (emp[i].salary > highest_salary)
                {
                    highest_salary = emp[i].salary;
                }
                total_salary += emp[i].salary;
            }
            std::cout<<std::endl;
            std::cout << "Total Salary: "    << total_salary <<std::endl;
            std::cout << "============" <<std::endl;
            std::cout << "Highest Salary: "  << highest_salary << std::endl;
            std::cout << "==============" <<std::endl;
            std::cout<<std::endl;
    
int  number = 0;
for (i = 0; i < n; i++)
{
    if (emp[i].salary>=15000) 
	{
        number++;
	}
}
std::cout<<"Number of employees who salary more than 15000 :" <<std::endl;
std::cout<<"==============================================" <<std::endl;
std::cout<<number<<std::endl;
std::cout<<std::endl;
            float  tax=0;      
            
    for (i = 0; i < n; i++)
	{
            if (emp[i].salary <= 1999)
            {
                tax = (emp[i].salary*5)/100.0;
            }
            else  if  (emp[i].salary<=2999)
            {
                tax=(emp[i].salary*7.5)/100.0;
            }
    
            else  if  (emp[i].salary<=3999)
            {
                tax=(emp[i].salary*10)/100.0;
            }
            else   if  (emp[i].salary>4000)
            {
                tax=(emp[i].salary*15)/100.0;
            }
 
            emp[i].salary -= tax;
	}
            std::cout<<"Salary after tax :" <<"  Employee Name :   " <<std::endl;
            std::cout<<"================ "  <<"   =============" <<std::endl;
            for (i = 0; i < n; i++)
            std::cout <<  emp[i].salary<<"                   "   <<  emp[i].name << std::endl;                    
            std::cout<<std::endl;
outfile <<emp[i].name,emp[i].salary,emp[i].birthday,emp[i].sex ;
outfile.close();
     return  0;
	
}
}
}
 
 
Last edited on Apr 6, 2013 at 6:08am UTC