CS301 Assignment No 2 Solution Fall 2023
Home VU Fall Assignment Solution CS301 Assignment No 2 Solution Fall 2023

CS301 Assignment No 2 Solution Fall 2023

by Adeel Ikram
1 comment

CS301 Assignment No 2 Solution Fall 2023 – VU Assignment Solution – VU Fall Assignment Solution

The CS301 Assignment No 2 Solution Fall 2023 of Virtual University (VU) course assignment and I will share with you today the solution I came up with. Always come back to StudySolution for the most recent updates regarding the answers to your assignments.

CS301 Assignment No 2 Solution Fall 2023

Please visit our GDB section to traverse the Fall GDB Solution page if you find any GDB solutions for the Spring of 2024 and bring them to our attention. You are welcome to share your thoughts with us in the space provided below, and we will get back to you as quickly as possible.

Study Solution is an educational platform that offers students a free VU assignment solution to further their education. The solutions to the VU assignments provided by this site are the product of the professional and extensive experience of educators who are acknowledged authorities in their respective areas.

CS301 Assignment No 2 Solution Fall 2023 This assignment solution for Virtual University has been crafted with careful consideration given to the particular needs of the students as well as the course material. Study Solution provides a solution for completing assignments associated with Virtual University that is dependable, accurate, and up-to-date.

The VU assignment solution file will be available at no cost during the Fall 2023 semester. You can use all VU assignment solution files for your VU assignments. We can guarantee that if you use our VU assignment help, you will improve the grades that you receive on your assignments.

The Virtual University can be a complex learning environment, particularly for starting students. That is why we provide the Virtual University Assignment Solution to assist you. Don’t hesitate to contact us using the comment box to let us know about any Virtual University Assignment Solution requirements you may have.

CS301 Assignment No 2 Solution Fall 2023 The assignments play a significant role in the educational experience at VU, which is consistently ranked among the nation’s best universities. There are a lot of students who struggle to finish their VU assignments on time; this is where Study Solution comes in.

Assignment No. 2

Solution Fall 2023

CS301

Please Note this Before Submit Your Assignment:

  • Begin brainstorming ideas for your unique solution.
  • Quickly correct any errors you notice before submitting your assignment.
  • Please verify that your job meets all criteria before submitting it.
  • Notify us in the comments section if the Solution file contains any errors, and we will promptly make the necessary corrections.
  • Please ensure that your work meets all requirements before submitting it.
  • Do not submit the same file for the solution; incorporate the suggestions below to create a higher-quality solution file.
  • If there are any issues with the solution file or other errors, please inform us so we can address them immediately.
  • Make necessary corrections and double-check that your file functions correctly before submitting it.
  • Before submitting any of your tasks, ensure they have been thoroughly reviewed.
Students Can Get CS301 Assignment No 2 Solution Fall 2023 just By Visiting below.

Solution

#include<iostream>
#include<stack>
#include<string>
using namespace std;
class Book
{
public:
string title;
string ISBN;
Book (string t , string isbn) : title(t) , ISBN(isbn){}
};
class BSTNode
{
public:
Book book;
BSTNode* right;
BSTNode* left;
BSTNode(Book b) : book(b) , left(NULL) , right(NULL){}
};
class BookStack
{
private:
stack<Book> bookStack;
BSTNode* root;
BSTNode* insertBST (BSTNode* node , Book newBook)
{
if ( node == NULL)
{
return new BSTNode(newBook);
}
if (newBook.title < node->book.title)
{
node->left = insertBST(node->left , newBook);
}
else if(newBook.title > node->book.title)
{
node->right = insertBST(node->right , newBook);
}
return node;
}
    void inOrderTraversal(BSTNode* node)
    {
    if (node != NULL)
    {
    inOrderTraversal(node->left);
    cout<<“Book :”;
    cout<<node->book.title<<“(ISBN: “<<node->book.ISBN<<“)\n”;
    inOrderTraversal(node->right);
}
}
public:
BookStack() : root(NULL){}
void push(Book newBook)
{
bookStack.push(newBook);
root = insertBST(root , newBook);
}
void pop()
{
if (!bookStack.empty())
{
Book topBook = bookStack.top();
bookStack.pop();
BSTNode* currentNode = root;
BSTNode* parent = NULL;
while(currentNode != NULL && currentNode->book.title != topBook.title)
{
parent = currentNode;
if(topBook.title < currentNode->book.title)
{
currentNode = currentNode->left;
}
else
{
currentNode = currentNode->right;
}
}
if (currentNode != NULL)
{
if(currentNode->left == NULL && currentNode->right == NULL)
{
if(parent == NULL)
{
root = NULL;
}
else if(parent->left == currentNode)
{
parent->left = NULL;
}
cout<<“Book Removed :” <<currentNode->book.title<<“\n\n”;
delete currentNode;
}
else
//VUTEAMHADI 03087122922
{
BSTNode* successor = currentNode->right;
while(successor->left !=NULL)
{
successor = successor->left;
}
currentNode->book = successor->book;
popsuccessor(currentNode , successor);
}
}
}
}
//VUTEAMHADI 03087122922
void popsuccessor ( BSTNode* parent, BSTNode* node)
{
if(node->left == NULL && node->right == NULL)
{
if(parent->left == node)
{
parent->left == NULL;
}
else
{
parent->right == NULL;
}
delete node;
}
else if(node->left == NULL)
{
node->book = node->right->book ;
popsuccessor(node , node->right);
}
else
//VUTEAMHADI 03087122922
{
BSTNode* successor = node->left;
while(successor->right != NULL)
{
successor = successor->right;
}
node->book = successor->book;
popsuccessor(node , successor);
}
}
void listBook()
{
if(root == NULL)
{
cout<<“\n\n Library is empty”;
}
else
{
cout<<“Library Book list:\n”;
inOrderTraversal(root);
}
}
Book* search(string title)
{
BSTNode* currentNode = root;
while(currentNode != NULL)
{
if(title == currentNode->book.title)
{
return &currentNode->book;
}
else if(title < currentNode->book.title)
{
currentNode = currentNode->left;
}
else
{
currentNode = currentNode->right;
}
}
return NULL;
}
};
main()
{
//VUTEAMHADI 03087122922
BookStack library;
Book* foundBook;
int choice;
string title , ISBN;
library.push(Book(“Aladdin” , “BC220204894”)) ;
library.push(Book(“Bad Habbits” , “BC220204894”));
while(1)
{
cout<<“\n\n Enter 1 to LIst All Book”;
cout<<“\n\n Enter 2 To Add a New Book  “;
cout<<“\n\n Enter 3 to search for a Book”;
cout<<“\n\n Enter 4 to remove a Book “;
cout<<“\n\n Enter 5 to Exist\n “;
cin>>choice;
switch(choice)
{
case 1:
    library.listBook();
    cout<<“\n\n “;
    break;
    case 2:
        cout<<“\n\n Enter Book title: “;
        cin.ignore();
        getline(cin , title);
        cout<<“\n\n Enter ISBN: “;
        getline(cin , ISBN);
        library.push(Book(title , ISBN));
        cout<<“\n\n “;
        break;
    case 3:
    cout<<“\n\n Enter Book title :”;
    cin.ignore();
    getline(cin , title);
    foundBook = library.search(title);
    if(foundBook != NULL)
    {
    cout<<“\n\n Book found:  ” << foundBook->title;
    cout<<“\n\n (ISBN: “<<foundBook->ISBN<<“)\n\n”;
}
else
{
cout<<“\n\n Not Book found:”;
}
break;
case 4:
library.pop();
break;
case 5:
exit(0);
}
}
}

For More Latest Update Stay With Us.

1 comment

Saad Waleed January 7, 2024 - 5:16 pm

Thanks a lot cs301 solution perfect but there were few errors which i fixed.
your solution is very helpful thank you so much.

Reply

Leave a Comment