CS201 Assignment 3 Solution 2019 Free Download

Are you looking for the solution to CS201 Assignment 3 2019?  I am your guide here who you will provide you its solution very easily.

CS201-Assignment-3-Solution-2019

 

CS201 Assignment 3 Solution

You will able to download the file of the solution. Moreover,  you will also watch a video to understand its solution. The video and download link of the file is available below. If you want solutions to other subjects then click on Assignment Solution for All Subjects.

#include<iostream>
#include<fstream>
#include<string.h>

using namespace std;
void addemployee();
void showemployee();

class employee {

int employee_id;
string employee_name;
int employee_salary;
public:
employee(){

}
void setid(int id){
employee_id=id;
}
void setname(string name){
employee_name=name;
}
void setsalary(int salary){
employee_salary=salary;
}
int getid(){
return this->employee_id;
}
string getname(){
return this->employee_name;
}
int getsalary(){
return this->employee_salary;
}
};
employee anEmployee;
void addemployee(){
int id;
cout<<"enter employee ID: ";
cin>>id;
anEmployee.setid(id);
cout<<"enter employee Name: ";
string name;
cin>>name;
anEmployee.setname(name);
int salry;
cout<<"enter employee Salary: ";
cin>>salry;
anEmployee.setsalary(salry);
ofstream empfile("employee.txt",ios::binary|ios::app);

if(!empfile) {
cout << "Cannot open file!" << endl;
return ;
}
empfile.write((char*)&anEmployee, sizeof(employee));
//cout<<anEmployee.getid()<<" "<<anEmployee.getname()<<"  """<<anEmployee.getsalary();
empfile.close();
if(!empfile.good()) {
cout << "Error occurred at writing time!" << endl;
return ;
}
cout << "Employee Recored added Sucessfully!" << endl;
}

void displayRecord() {
// employee anEmployee;
ifstream file("employee.txt",ios::binary);
if(!file) {
cout<<"Error in opening file.\n";
return;
} else {
cout<<"ID"<<"  "<<"Name"<<"\t"<<"Salary"<<endl;
cout<<"======================================================="<<endl;
while(file.read((char*)&anEmployee,sizeof(employee))) {

cout<<anEmployee.getid()<<"  "<<anEmployee.getname()<<"\t"<<anEmployee.getsalary();
cout<<endl;
}
file.close();
}
}


// function to show employee data
void updateSalary() {
fstream file("employee.txt",ios::binary|ios::in|ios::out);
if(!file) {
cout<<"Error in opening file.\n";
return;
}
int eCode,sHike;
cout<<"Enter employee code\n";
cin>>eCode;
cout<<"Salary hike? ";
cin>>sHike;
file.seekg(sizeof(anEmployee)*(eCode-1),ios::beg);
file.read((char*)&anEmployee,sizeof(employee));
anEmployee.setsalary(sHike+anEmployee.getsalary());
file.seekp(sizeof(anEmployee)*(eCode-1),ios::beg);
file.write((char*)&anEmployee,sizeof(employee));
cout<<"Salary updated successfully.\n";
}
main()
{
ifstream file("employee.txt");
if(file) {
file.close();
remove("employee.txt");
}
int programOption;
while(true){

cout<<"\n\n\n";
cout<<"Please select the option Below,.\n";
cout<<"Please enter  1 To ADD AN EMPLOYEE.\n";
cout<<"Please enter  2 To DISPLAY FILE DATA..\n";
cout<<"Please enter  3 To INCREASE EMPLOYEE SALARY..\n";
cout<<"Please enter  4 To Exit Program..\n";

cout<<"==================================================================\n";
cout<<"Please enter program option :";
cin>>programOption;

switch(programOption){
case 1 :
cout<<"ADD AN EMPLOYEE DATA.\n";
addemployee();
break;
case 2 :
cout<<"Showing Employee Data.\n";
displayRecord();
break;
case 3 :
cout<<"Update salary .\n";
updateSalary();
break;
case 4 :
cout<<"Shuting Down the Program..... .\n";
exit(1);
break;

}
}
}

How to Download Solution?

The download button of the CS201 Assignment 3 Solution 2019 is available below. Tap the button and it will be downloaded on your phone.

CS201 Assignment 3 Solution

I hope you downloaded the file of the solution. If you are facing any difficulty then let me know via contact us page. Follow me on Facebook to ask any questions.

Leave a Reply

Your email address will not be published. Required fields are marked *