0% found this document useful (0 votes)
38 views

CS301P Lab 1 Solution

Uploaded by

hejaz589
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)
38 views

CS301P Lab 1 Solution

Uploaded by

hejaz589
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

// CS301P Lab 1 Problem KST Learning

#include<iostream>
#include<conio.h>
using namespace std;

class Faculty
{
private:
string name, post;
int age;
public:
void setName(string n)
{
name = n;
}

void setPost(string p)
{
post = p;
}

void setAge(int a)
{
age = a;
}

string getName()
{
return name;
}

string getPost()
{
return post;
}

int getAge()
{
return age;
}
};

class Node
{
private:
Faculty object;
Node *nextAdd;

public:
void set(Faculty obj)
{
object = obj;
}

void setNext(Node *ptr)


{
nextAdd = ptr;
}
Faculty get()
{
return object;
}

Node* getNext()
{
return nextAdd;
}
};

class List
{
private:
Node *Head;
Node *Tail;

public:
List()
{
Head = NULL;
Tail = NULL;
}

void add(Faculty obj)


{
Node *newNode = new Node;
newNode -> set(obj);
newNode -> setNext(NULL);

if(Head == NULL)
{
Head = newNode;
Tail = newNode;
}
else
{
Tail -> setNext(newNode);
Tail = newNode;
}
}

void traverse()
{
Node *ptr = Head;
Faculty obj;

while(ptr -> getNext() != NULL)


{
obj = ptr -> get();
cout << "Faculty Name : " << obj.getName();
cout << "\nFaculty Age : " << obj.getAge();
cout << "\nFaculty Post : " << obj.getPost();
cout << "\n\n----------------------------\n\n";
ptr = ptr -> getNext();
}
}
};
main()
{
List L;
Faculty F;
string name, post;
int age;

cout << "***** Taking Faculty Records *****\n\n";


for(int i=1; i<=5; i++)
{
cout << "Enter Faculty Name : ";
cin >> name;
cout << "\nEnter Faculty Age : ";
cin >> age;
if(age >= 25 && age <= 35)
{
post = "Lecturer";
}
if(age >= 36 && age <= 45)
{
post = "Assistant Professor";
}
if(age >= 46 && age <= 60)
{
post = "Professor";
}

F.setName(name);
F.setAge(age);
F.setPost(post);

L.add(F);
cout << "\n\n----------------------------\n\n";
}

cout << "***** Display Faculty Records *****\n\n";


L.traverse();
getch();
return 0;
}

You might also like