0% found this document useful (0 votes)
20 views3 pages

Task

The document describes a C++ program that implements a linked list to store employee data. The program defines an Employee class to store employee details like ID, name, salary etc. A Node class is used to create nodes of the linked list with an Employee object. A LinkedList class implements functions to insert, remove, update salary and display nodes of the linked list. The main function tests the LinkedList class by inserting sample Employee objects and calling its functions.

Uploaded by

i227438
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Task

The document describes a C++ program that implements a linked list to store employee data. The program defines an Employee class to store employee details like ID, name, salary etc. A Node class is used to create nodes of the linked list with an Employee object. A LinkedList class implements functions to insert, remove, update salary and display nodes of the linked list. The main function tests the LinkedList class by inserting sample Employee objects and calling its functions.

Uploaded by

i227438
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <iostream>

using namespace std;


class employe{
public:
int id;
string name;
string nic;
double salary;
double bonus;
employe()//default constructor
{
id=0;
name="Null";
nic=" ";
salary=0;
bonus=0;
}
employe(int id,string name,string nic, double salary, double
bonus)//parametrized constructor
{
this-> id=id;
this-> name=name;
this-> nic=nic;
this-> salary=salary;
this-> bonus=bonus;
}
void display() const {
cout << "Employee ID: " << id<<endl;
cout << "Employee Name: " << name<<endl;
cout << "NIC: " << nic<<endl;
cout << "Salary: " << salary <<endl;
cout << "Bonus: " << bonus << endl;}
};
class Node {
public:
employe data;
Node* next;
// Default constructor
Node()
{
data;
next;
}
// parametrized Constructor
Node(const employe & val) {
data = val;
next = NULL;
}
};
class linked_list
{
private:
Node*head;
public:
linked_list()
{
head=NULL;
}
~linked_list()
{ }
//insert at end
void insert(const employe& p) {//p person
Node* newNode = new Node(p);

if (head == NULL) {
head = newNode;
return;
}
Node* temp = head;
while (temp->next != NULL) {
temp = temp->next;
}

temp->next = newNode;
}
void remove (int id)
{
if(head==0)
{
cout<<"ID doesnot exist!"<<endl;//epmty list
}
if (head->data.id == id)
{
Node *ptr=head;
head=head->next;
delete ptr;
return;
}
Node* current = head;
while (current->next) {
if (current->next->data.id == id) {
Node* temp = current->next;
current->next = temp->next;
delete temp;
return;
}
current = current->next;
}

}
void updatesalary(const int& salary, int id) {
if(head==0)
{
cout<<"List is empty, cannot modify salary"<<endl;
}
Node* ptr = head;
while (ptr) {
if (ptr->data.id == id) {
ptr->data.salary = salary;
return;
}
ptr = ptr->next;
}
}
void display() {
Node* temp = head;
while (temp) {
temp->data.display();
cout << endl << endl;
temp = temp->next;
}
}

void clear() {
while (head) {
Node* temp = head;
head = head->next;
delete temp;
}
}
};

int main() {
employe emp1(101, "John Doe", "12345", 50000.0, 2000.0);
employe emp2(102, "Jane Smith", "67890", 60000.0, 2500.0);
employe emp3(103, "Bob Johnson", "54321", 55000.0, 2100.0);
employe emp4(104, "Alice Brown", "98765", 70000.0, 3000.0);
employe emp5(105, "Eva White", "45678", 52000.0, 1900.0);
linked_list l;
l.insert(emp1);
l.insert(emp2);
l.insert(emp3);
l.insert(emp4);
l.insert(emp5);
cout<<"Before updation: "<<endl;
l.display();
//cout<<"kk";
l.updatesalary(605000, 102);
l.display();
cout<<endl;
l.remove(104);
l.display();
return 0;
}

You might also like