You are required to develop a C++ program using a Linked List data structure for this hiring scenario.
Requirements:
- You have to use only the Linked List data structure for this
assignment. Your marks will be deducted if any other data structure is
used
- Your program should perform the below-mentioned operations on
the output console:
§ Linked List will be used to store the
information of all candidates.
§ The
program will accept “Candidate Name”, “subject
test marks”, and “interview marks” as input parameters.
§ The candidate will only be considered eligible
for the post of lecturer if he/she secures more than 70 marks in the subject test
and more than 80 marks in the interview. Otherwise, he/she will be considered
‘ineligible’
§ The program should display the record of
eligible and ineligible candidates separately.
Solution
Guidelines:
1)
Understand
and practice the following topics before developing this assignment::
R Nodes
R List
R Linked List
RLinked List Methods
2) To save
candidate information, use the Linked List data structure. Each candidate will
be represented by a node that contains the following information: candidate
name, subject test score, interview marks, and status (eligible/ineligible).
3) Your solution should use these classes:
a.
Candidate
(Node) Class: To
save information about each candidate
b. List Class: To save all candidates in the linked list
Program:
#include<iostream>
using namespace std;
class Applicant{
private:
int Id, testScore, interviewmarks;
string name, status;
Applicant *nextCandidate;
public:
void setId(){
cin>>Id;
}
int getId(){
return Id;
}
void setName(){
cin>>name;
}
string getName(){
return name;
}
void setTestScore(){
cin>>testScore;
}
int getTestScore(){
return testScore;
}
void setInterviewmarks(int i){
interviewmarks=i;
}
int getInterviewmarks(){
return interviewmarks;
}
void setStatus(string s){
status=s;
}
string getstatus(){
return status;
}
void setNextApplicant( Applicant *ptr){
nextCandidate=ptr;
}
Applicant* getNextApplicant(){
return nextCandidate;
}
};
class Linked_List{
Applicant* head;
Applicant* current;
public:
Linked_List(){
head=NULL;
current=NULL;
}
void addApplicant(){
int i;
Applicant *newNode= new Applicant;
cout<<"Enter the ID of Applicant:"<<endl;
newNode->setId();
cout<<"Enter the Name of Applicant:"<<endl;
newNode->setName();
cout<<"Enter the Test Score of Applicant:"<<endl;
newNode->setTestScore();
if(newNode->getTestScore()>=80){
cout<<"Enter the Interview Marks of Applicant: "<<endl;
cin>>i;
newNode->setInterviewmarks(i);
if(newNode->getInterviewmarks()>50)
newNode->setStatus("Eligible");
else
newNode->setStatus("Ineligible");
}
else
{
newNode->setInterviewmarks(0);
newNode->setStatus("Ineligible");
cout<<"Applicant is not eligible for Job Interview"<<endl;
}
newNode->setNextApplicant(NULL);
if(head==NULL){
head=newNode;
current=newNode;
}
else{
current->setNextApplicant(newNode);
current=newNode;
}
}
void getInformation(){
if(next(head)==true){
cout<<"No Applicant added yet"<<endl;
}
else{
int count=0;
Applicant *ptr=head;
while(next(ptr)==false){
ptr=ptr->getNextApplicant();
count++;
}
cout<<"Total number of Applicant: "<<count<<endl;
}
}
bool next(Applicant *ptr){
if(ptr==NULL){
return true;
}
else{
return false;
}
}
void updateApplicant(){
if(next(head)==true){
cout<<"No Applicant Added Yet"<<endl;
}
else{
int t_id,found=0,i;
cout<<"Enter Applicant ID:";
cin>>t_id;
Applicant *ptr=head;
while(next(ptr)==false){
if(t_id==ptr->getId()){
cout<<"Enter the Name of Applicant:";
ptr->setName();
cout<<"Enter the Test Score of Applicant: ";
ptr->setTestScore();
if(ptr->getTestScore()>=80){
cout<<"Enter the Interview Marks os Applicant: ";
cin>>i;
cout<<endl;
ptr->setInterviewmarks(i);
if(ptr->getInterviewmarks()>50)
ptr->setStatus("Eligible");
else
ptr->setStatus("Ineligible");
}
else{
ptr->setInterviewmarks(0);
ptr->setStatus("Ineligible");
cout<<"Applicant is not Applicable for Job"<<endl ;
}
cout<<"Record Updated"<<endl;
found++;
}
ptr=ptr->getNextApplicant();
}
if(found==0){
cout<<"Applicant ID not found"<<endl;
}
}
}
friend void displayApplicant(Linked_List *obj, int choice){
if(obj->next(obj->head)==true){
cout<<"No Applicant Added Yet"<<endl;
}
else{
if(choice==3)
{
Applicant *ptr=obj->head;
while(obj->next(ptr)==false){
if(ptr->getstatus()=="Eligible"){
cout<<"======================================="<<endl<<endl;
cout<<"Applicant ID:"<<ptr->getId()<<endl;
cout<<"Applicant Name:"<<ptr->getName()<<endl;
cout<<"Applicant TestScore:"<<ptr->getTestScore()<<endl;
cout<<"Applicant Interview MArks:"<<ptr->getInterviewmarks()<<endl;
cout<<"Applicant Status: "<<ptr->getstatus()<<endl;
}
ptr=ptr->getNextApplicant();
}
}
else{
Applicant *ptr= obj->head;
while(obj->next(ptr)==false){
if(ptr->getstatus()=="Ineligible"){
cout<<"======================================="<<endl<<endl;
cout<<"Applicant ID: "<<ptr->getId()<<endl;
cout<<"Applicant Name: "<<ptr->getName()<<endl;
cout<<"Applicant TestScore: "<<ptr->getTestScore()<<endl;
cout<<"Applicant Interview MArks: "<<ptr->getInterviewmarks()<<endl;
cout<<"Applicant Status: "<<ptr->getstatus()<<endl;
}
ptr=ptr->getNextApplicant();
}
}
}
}
};
main(){
Linked_List L;
int choice,number;
do{
cout<<endl<<"Enter your Choice: "<<endl;
cout<<"1. To add Applicant data"<<endl;
cout<<"2.Total number of Applicants"<<endl;
cout<<"3.Display data of Eligible Applicants"<<endl;
cout<<"4.Display data of Ineligible Applicants"<<endl;
cout<<"5.Update Applicant Data"<<endl<<endl;
cin>>choice;
switch(choice){
case 1:
cout<<"Enter the number of Applicants you want to add or see result: ";
cin>>number;
for(int i=1;i<=number;i++){
L.addApplicant();
}
break;
case 2:
L.getInformation();
break;
case 3:
displayApplicant(&L,choice);
break;
case 4:
displayApplicant(&L,choice);
break;
case 5:
L.updateApplicant();
break;
default:
cout<<"Press other number to close the program"<<endl<<endl;
}
}
while(choice>=1 && choice<=5);
return 0;
}
Output
No comments