Incomplete Task3
Incomplete Task3
#include<fstream>
using namespace std;
int main()
{
char choice;
do{
if(choice=='s'||choice=='S')
{
ofstream write("source.txt",ios::app);
if(!write)
{
cout << "Error" << endl;
return 0;
}
cin.ignore();
for(int i=1;i<=5;i++)
{
char name[50], department[50];
int salary;
int i=0,j=0;
while(department[i]==' ')
{
i++;
}
while(search_department[j]==' ')
{
j++;
}
bool match=true;
for(; department[i]!='\0'&&search_department[j]!='\0'; i++, j++)
{
if(search_department[j]!=department[i])
{
match=false;
break;
}
}
if(match)
{
cout<<name<<", "<<salary<<", "<<department<<endl;
found=true;
}
if(!found)
{
cout<<"No match found";
}
}
read.close();
}
else if(choice=='r'||choice=='R')
{
cout<<"Enter the name of the employee who is leaving: ";
cin.ignore();
char leaving_employee[100];
cin.getline(leaving_employee,100);
ifstream read("source.txt");
ofstream write("result.txt");
if (!read)
{
cout<<"Error"<<endl;
return 1;
}
int i = 0;
while(name[i] == ' ')
{
i++;
}
int j = 0;
while(leaving_employee[j] == ' ')
{
j++;
}
bool match = true;
for(;name[i] != '\0'&&leaving_employee[j]!='\0';i++,j++)
{
if(leaving_employee[j]!=name[i])
{
match=false;
break;
}
}
if(!match)
{
write<<name<<", "<<salary<<", "<<department<<endl;
write<<name<<", "<<salary<<", "<<department<<endl;
}
}
read.close();
write.close();
}
cout<<endl;
}while(choice!='x'&&choice!='X');