Question
//C++ circular doubly linked list. Please edit and compile. It throws a couple of syntax errors. #include #include using namespace std; struct QB{ public: string
//C++ circular doubly linked list. Please edit and compile. It throws a couple of syntax errors.
#include
#include
using namespace std;
struct QB{
public:
string firstName, lastName;
int numWins;
int years[4];
public:
QB* next;
QB* prev;
QB(string n1, string n2, int year)
{
firstName = n1;
lastName = n2;
numWins = 1;
years[0]=year;
}
void add_year(int year)
{
years[numWins]=year;
numWins++;
}
};
class QBList
{
private:
QB* head;
QB* tail;
public:
QBList()
{
head = NULL;
tail = NULL;
}
void add_to_list(string fname, string lname, int year)
{
if(head==NULL)
{
QB* newQB = new QB(fname,lname,year);
head = newQB;
tail = newQB;
}
else if(head == tail)
{
QB* newQB = new QB(fname,lname,year);
tail = newQB;
head->next= tail;
tail->prev= head;
}
else
{
bool found = 0;
QB* temp;
temp = head;
while(temp->next!= NULL)//this will break the loop
{
if(fname == temp->firstName && lname == temp->lastName)
{
found = 1;
break;
}
temp=temp->next; //so that the loop goes on
}
if(found)
{
temp->add_year(year);
}
else
{
QB* newQB = new QB(fname,lname,year);
newQB->prev = tail;
tail->next = newQB;
tail = newQB;
}
}
}
void search_name(string fname, string lname){
QB* temp = head;
while(temp->next!=NULL)
{
if(fname == temp->firstName && lname == temp->lastName)
{
cout< } temp=temp->next; } cout<<"The quareterback is not found."; } void search_num(int n){ QB* temp = head; bool found =0; while(temp->next!=NULL) { if(n==temp->numWins) { cout< found=1; } temp=temp->next; } if(!found) cout<<"The quarterback is not found."; } // searching year void search_year(int year){ QB* temp = head; while(temp->next!=NULL) { for(int i = 0; i { if(temp->years[i] == year){ cout<< temp->numWins<< endl; } temp=temp->next; } cout<<"The quareterback is not found."; } void search_num(int n){ QB* temp = head; bool found =0; while(temp->next!=NULL) { if(n==temp->numWins) { cout< found=1; } temp=temp->next; } if(!found) cout<<"The quarterback is not found."; } void deleteList(){ QB* temp = head; head=temp->next; while(head->next!=NULL) { temp=head; head=temp->next; delete temp; } delete head; } void deleteEntry(string fname, string lname){ QB* temp = head; while(temp->next!=NULL) { if(fname == temp->firstName && lname == temp->lastName) { temp->prev->next = temp->next; temp->next->prev = temp->prev; delete temp; } temp=temp->next; } } }; // main #include #include using namespace std; int main() { string fname, lname; int year; ifstream qb_list("qblist.txt") while(qb_list >> fname >>lname>> year){ add_to_list(fname, lname, year); } cout<<"1- Search by Number: "; cout << "2- Search by Name: "; cout << "3- Search by Year: "; cout<< "4- Delete Entry: "; cout<<"5- Delete list: "; cout" 6- Exit: " do{ int choice; cin>>choice; if(choice==1) { int num; cin>>num; LL.search_num(num); } if(choice == 2) { string fname; cin>>fname; string lname; cin>>lname; LL.search_name(fname,lname); } if(choice ==3) { string fname; cin>>fname; string lname; cin>>lname; LL.deleteEntry(fname,lname); } if(choice ==4) { LL.deleteList(); } if(choice ==5) { break; } } while(1); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started