You are on page 1of 5

Ayesha raja

Bcs183201

Dated : 2oct,2020.

Data structure

Lab 2 tasks
Task 3
#include<iostream>
#include <string>
using namespace std;
class employee
{
public:
string name;
int id;
int salary;
string designation;
employee *next;

};
class list
{
int count;
employee *head;
employee *tail;
public:
list()
{
head = NULL;
tail = NULL;
count = 0;
}

void insert(string nam, int idd, int salar, string desig)


{
employee *n = new employee();
n->name = nam;
n->id = idd;
n->salary = salar;
n->designation = desig;
n->next = NULL;
if (head == NULL)
{
head = n;
tail = n;
}
else
{
tail->next = n;
tail = n;
}
}

void display()
{
employee *current = head;
if (current == NULL)
{
cout << "list is empty" << endl;
}
while (current != NULL)
{
num++;
cout << "Lab " << num << ":" << endl;
cout << "Name: " << current->name << endl;
cout << "Lab ID: " << current->id << endl;
cout << "salary: " << current->salary << endl;
cout << "designation is: " << current->designation
<< endl;
current = current->next;
}
}

Task 2
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
struct book
{
string book_title;
string author_book;
int cost_book;
};
int count = 0;
int average = 0;
string a;
int size = 0;
string c;
cout << "enter the number of books " << endl;
cin >> size;
book * b = new book[size];
int option;
cout << "enter the option you want to select" << endl;
cin >> option;
switch (option)
{
case 1:
for (int i = 0; i < size; i++)
{
cout << "enter the book title" << endl;
cin >> b[i].book_title;
cout << "enter the book author" << endl;
cin >> b[i].author_book;
cout << "enter the book cost" << endl;
cin >> b[i].cost_book;
}

break;
case 2:
for (int i = 0; i < size; i++)
{
cout << "enter the book title" << endl;
cin >> b[i].book_title;
cout << "enter the book author" << endl;
cin >> b[i].author_book;
cout << "enter the book cost" << endl;
cin >> b[i].cost_book;
}

for (int i = 0; i < size; i++)


{
cout << b[i].book_title << endl;
cout << b[i].author_book << endl;
cout << b[i].cost_book << endl;
}
break;
case 3:
for (int i = 0; i < size; i++)
{
cout << "enter the book title" << endl;
cin >> b[i].book_title;
cout << "enter the book author" << endl;
cin >> b[i].author_book;
cout << "enter the book cost" << endl;
cin >> b[i].cost_book;
}
for (int i = 0; i < size; i++)
{
c = b[i].book_title;
for (int j = i+1; j < size; j++)
{
if (c>b[j].book_title)
{
cout << b[i].book_title <<
endl;
}
}
}
break;
case 4:
for (int i = 0; i < size; i++)
{
cout << "enter the book title" << endl;
cin >> b[i].book_title;
cout << "enter the book author" << endl;
cin >> b[i].author_book;
cout << "enter the book cost" << endl;
cin >> b[i].cost_book;
}
cout << "enter the book title" << endl;
cin >> a;
for (int i = 0; i < size; i++)
{

if (a == b[i].book_title)
{
cout << b[i].book_title << endl;
cout << b[i].author_book << endl;
cout << b[i].cost_book << endl;
}
else
{
cout << "record not found" << endl;
}
}
break;

case 5:
for (int i = 0; i < size; i++)
{
cout << "enter the book title" << endl;
cin >> b[i].book_title;
cout << "enter the book author" << endl;
cin >> b[i].author_book;
cout << "enter the book cost" << endl;
cin >> b[i].cost_book;
}
for (int i = 0; i < size; i++)
{
average = average + b[i].cost_book;
count++;

}
average = average / count;
cout << "average cost is " << average << endl;
break;
case 6:
cout << "you have exit successfully" << endl;
}
system("pause");

You might also like