# include # include using namespace std; class Candidate { private: int id; string name; int marks; string status; Candidate * nextCandidate; public: void setId(int); int getId(); void setName(string); string getName(); void setMarks(int mark); int getMarks(); void setStatus(string); string getStatus(); void setNext(Candidate *); Candidate * getNext(); }; void Candidate::setId(int nId) { id = nId; } int Candidate::getId() { return this->id; } void Candidate::setName(string nName) { name = nName; } string Candidate::getName() { return this->name; } void Candidate::setMarks(int mark) { marks = mark; } int Candidate::getMarks() { return this->marks; } void Candidate::setStatus(string nStatus) { status = nStatus; } string Candidate::getStatus() { return this->status; } void Candidate::setNext(Candidate *nNextCandidate) { nextCandidate = nNextCandidate; } Candidate * Candidate::getNext() { return nextCandidate; } // Linked_List class Scorpio class Linked_List { friend void showCandidate(); public: Candidate * head; Candidate * current; static int counter; Linked_List(); void add(); void getInfo(); bool next(); void UpdateCandidate(int id); }; int Linked_List::counter = 0; Linked_List::Linked_List() { head = new Candidate(); current = new Candidate(); head->setNext(NULL); current->setNext(NULL); } void Linked_List::add() { Candidate *ptr = new Candidate(); ptr->setNext(NULL); string name, status; int id, marks; cout << "\nEnter the ID of Candidate: "; cin >> id; cout << "\n"; cout << "Enter the name of Candidate: "; cin >> name; cout << "\n"; cout << "Enter the marks of Candidate: "; cin >> marks; cout << "\n"; ptr->setId(id); ptr->setName(name); ptr->setMarks(marks); if(marks >= 50) { ptr->setStatus("Pass"); counter++; } else { ptr->setStatus("Fail"); } if(head == NULL) { head = ptr; } else { Candidate *ptr1 = head; while(ptr1->getNext() != NULL) { ptr1 = ptr1->getNext(); } ptr1->setNext(ptr); } } void Linked_List::UpdateCandidate(int sId) { Candidate *ptr = head; while(ptr != NULL) { if(ptr->getId() == sId) { string name; int marks; cout << "\nEnter the name of Candidate: "; cin >> name; cout << "\n"; cout << "Enter the marks of Candidate: "; cin >> marks; cout << "\n"; ptr->setName(name); ptr->setMarks(marks); if(marks >= 50) { ptr->setStatus("Pass"); counter++; } else { ptr->setStatus("Fail"); } } ptr = ptr->getNext(); } } bool Linked_List::next() { if (current == NULL) return false; current = head; current = current->getNext(); return true; }; // friend Function Scorpio void showCandidate(Linked_List obj, bool b) { Candidate *ptr = new Candidate(); ptr = obj.head; while(ptr != NULL) { if(ptr->getStatus() == "Pass" && b == true) { cout << "Candidate ID: " << ptr->getId() << endl; cout << "Candidate Name: " << ptr->getName() << endl; cout << "Interview Marks: " << ptr->getMarks() << endl; cout << "Candidate Status: " << ptr->getStatus() << endl << endl; } else if(ptr->getStatus() == "Fail" && b == false) { cout << "Candidate ID: " << ptr->getId() << endl; cout << "Candidate Name: " << ptr->getName() << endl; cout << "Interview Marks: " << ptr->getMarks() << endl; cout << "Candidate Status: " << ptr->getStatus() << endl << endl; } ptr = ptr->getNext(); } } int main() { Linked_List myList; //Main progam Main-Menu int run = 1, option; bool status; while(run) { cout << " Enter Your Choice" << endl; cout << "1 : To add candidate data" << endl; cout << "2 : Total number of candidates" << endl; cout << "3 : Display data of passed candidates" << endl; cout << "4 : Display data of failed candidates" << endl; cout << "5 : Update Candidate Data" << endl; cout << "Press other number to close program" << endl; cin >> option; if(option == 1) { int num = 0; cout << "Enter the number of students to add: " << endl; cin >> num; for(int i = 0; i < num; i++) { myList.add(); } } else if(option == 2) { cout << "\nTotal number of Candidates are: " << Linked_List::counter << endl << endl; } else if(option == 3) { status = true; showCandidate(myList, status); } else if(option == 4) { status = false; showCandidate(myList, status); } else if(option == 5) { int id; cout << "\nEnter the Id of Candidate: "; cin >> id; myList.UpdateCandidate(id); } else { run = 0; } } return 0; }