Professional Documents
Culture Documents
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 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;
}
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");