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
|
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
struct employee
{
string EGN;
string name;
string position;
int intership;
float salary;
}a[20];
void create(int i);
void add(int &i);
int main()
{
int i;
create(i);
add(i);
}
void create(int i)
{
int n;
ofstream f;
cout<<"Enter the number of employees: ";
cin>>n;
f.open("Employees.txt");
for(i=0;i<n;i++)
{
cout<<"Enter EGN: ";
getline(cin,a[i].EGN,',');
cin.get();
cout<<"Enter name: ";
getline(cin,a[i].name,',');
cin.get();
cout<<"Enter position: ";
getline(cin,a[i].position,',');
cout<<"Enter intership: ";
cin>>a[i].intership;
cout<<"Enter salary: ";
cin>>a[i].salary;
f<<a[i].EGN<<", "<<a[i].name<<", "<<a[i].position<<", "<<a[i].intership<<" "<<a[i].salary<<endl;
}
f.close();
}
void add(int &i)
{
fstream f;
f.open("Employees.txt",ios::app);
while(cin)
{
cout<<"Enter EGN: ";f.get();
getline(cin,a[i].EGN,',');
cin.get();
cout<<"Enter name: ";
getline(cin,a[i].name,',');
cin.get();
cout<<"Enter position: ";
getline(cin,a[i].position,',');
cout<<"Enter intership: ";
cin>>a[i].intership;
cout<<"Enter salary: ";
cin>>a[i].salary;
f<<a[i].EGN<<", "<<a[i].name<<", "<<a[i].position<<", "<<a[i].intership<<" "<<a[i].salary<<endl;
}
f.close();
}
|