In: Computer Science
Please complete following c++ code asap
using following prototypes complete each missing part
/ Linked list operations
int getLength() const {return length;}
void insertNode(College);
bool deleteNode(string);
void displayList() const;
bool searchList(string, College &) const;
};
main.cpp
/*
Build and procees a sorted linked list of College
objects.
The list is sorted in ascending order by the college code.
Assume that the college code is unique.
*/
#include <iostream>
#include <fstream>
#include <string>
#include "LinkedList.h"
using namespace std;
void buildList(const string &filename, LinkedList
&list);
void deleteManager(LinkedList &list);
void searchManager(const LinkedList &list);
void displayManager(const LinkedList &list);
int main()
{
string inputFileName = "colleges.txt";
LinkedList list;
buildList(inputFileName, list);
displayManager(list);
searchManager(list);
deleteManager(list);
displayManager(list);
return 0;
}
/*****************************************************************************
This function reads data about colleges from a file and inserts
them
into a sorted linked list. The list is sorted in ascending order by
code
*****************************************************************************/
void buildList(const string &filename, LinkedList
&list)
{
ifstream fin(filename);
cout << "Reading data from \"" << filename <<
"\"";
if(!fin)
{
cout << "Error opening the input file: \""<< filename
<< "\"" << endl;
exit(EXIT_FAILURE);
}
int rank, cost;
string code, name;
while(fin >> rank)
{
fin >> code;
fin.ignore(); // to ignore space in front of name
getline(fin, name, ';');
fin >> cost;
// create a College object and initialize it with data from
file
College aCollege(rank, code, name, cost);
/* Write your code here: call insertNode */
}
fin.close();
}
/*****************************************************************************
Delete manager: delete items from the list until the user enters Q
to quit
deleting
Input Parameter: list
*****************************************************************************/
void deleteManager(LinkedList &list)
{
string targetCode = "";
cout << "\n Delete\n";
cout << "=======\n";
while(targetCode != "Q")
{
cout << endl << "Enter a college code (or Q to stop
deleting) : \n";
cin >> targetCode;
cout << endl;
if(targetCode != "Q")
{
if(/* Write your code here: call deleteNode
*/)
cout << targetCode << " has been deleted!\n";
else
cout << "College \"" << targetCode << "\" was not
found in this list." << endl;
}
}
cout << "___________________END DELETE SECTION_____\n";
}
/*****************************************************************************
Search manager: search the list until the user enters Q to quit
searching
Input Parameter: list
*****************************************************************************/
void searchManager(const LinkedList &list)
{
string targetCode = "";
College aCollege;
cout << "\n Search\n";
cout << "=======\n";
while(targetCode != "Q")
{
cout << "\nEnter a college code (or Q to stop searching) :
\n";
cin >> targetCode;
if(targetCode != "Q")
{
if(/* Write your code here: call searchList
*/)
aCollege.vDisplay();
else
cout << "College \"" << targetCode << "\" was not
found in this list." << endl;
}
}
cout << "___________________END SEARCH SECTION
_____\n";
}
/*****************************************************************************
Display manager: diplay a header, formatted list content, and
footer,
depending on the user's choice;
displays the number of nodes (always)
Input Parameter: list
*****************************************************************************/
void displayManager(const LinkedList &list)
{
string action;
cout << "\nDisplay list [Y/N]? ";
cin >> action;
if(action == "Y" || action == "y")
{
cout << "\n====== ==== =============================
=========\n"
<< " Code Rank Name Cost \n"
<< "====== ==== =============================
=========\n";
/* Write your code here: call displayList */
cout << "====== ==== =============================
=========\n";
}
cout << "Number of colleges in this list: " << /*
Write your code here: call getLength */
endl;
}
Linked list operations :
int getLength() const {return length;}
void insertNode(College);
bool deleteNode(string);
void displayList() const;
bool searchList(string, College &) const;
main.cpp :
/*
Build and process a sorted linked list of College objects.
The list is sorted in ascending order by the college code.
Assume that the college code is unique.
*/
#include <iostream>
#include <fstream>
#include <string>
#include "LinkedList.h"
using namespace std;
void buildList(const string &filename, LinkedList
&list);
void deleteManager(LinkedList &list);
void searchManager(const LinkedList &list);
void displayManager(const LinkedList &list);
int main()
{
string inputFileName = "colleges.txt";
LinkedList list;
buildList(inputFileName, list);
displayManager(list);
searchManager(list);
deleteManager(list);
displayManager(list);
return 0;
}
/*****************************************************************************
This function reads data about colleges from a file and inserts
them
into a sorted linked list. The list is sorted in ascending order by
code
*****************************************************************************/
void buildList(const string &filename, LinkedList
&list)
{
ifstream fin(filename);
cout << "Reading data from \"" << filename <<
"\"";
if(!fin)
{
cout << "Error opening the input file: \""<< filename
<< "\"" << endl;
exit(EXIT_FAILURE);
}
int rank, cost;
string code, name;
while(fin >> rank)
{
fin >> code;
fin.ignore(); // to ignore space in front of name
getline(fin, name, ';');
fin >> cost;
// create a College object and initialize it with data from
file
College aCollege(rank, code, name, cost);
list.insertNode(aCollege); // The list object of
LinkedList calls insert method to insert College
object in the sorted order of the code
}
fin.close();
}
/*****************************************************************************
Delete manager: delete items from the list until the user enters Q
to quit
deleting
Input Parameter: list
*****************************************************************************/
void deleteManager(LinkedList &list)
{
string targetCode = "";
cout << "\n Delete\n";
cout << "=======\n";
while(targetCode != "Q")
{
cout << endl << "Enter a college code (or Q to stop
deleting) : \n";
cin >> targetCode;
cout << endl;
if(targetCode != "Q")
{
if(list.deleteNode(targetCode)==true) //
The list object of LinkedList calls delete method to delete College
object of given code and returns true if code is present //
otherwise returns false
cout << targetCode << " has been deleted!\n";
else
cout << "College \"" << targetCode << "\" was not
found in this list." << endl;
}
}
cout << "___________________END DELETE SECTION_____\n";
}
/*****************************************************************************
Search manager: search the list until the user enters Q to quit
searching
Input Parameter: list
*****************************************************************************/
void searchManager(const LinkedList &list)
{
string targetCode = "";
College aCollege;
cout << "\n Search\n";
cout << "=======\n";
while(targetCode != "Q")
{
cout << "\nEnter a college code (or Q to stop searching) :
\n";
cin >> targetCode;
if(targetCode != "Q")
{
if(list.searchList(targetCode, College(0, targetCode, "",
0))== true) // The list object of
LinkedList calls searchlist method for given code and College
object
aCollege.vDisplay();
else
cout << "College \"" << targetCode << "\" was not
found in this list." << endl;
}
}
cout << "___________________END SEARCH SECTION
_____\n";
}
/*****************************************************************************
Display manager: diplay a header, formatted list content, and
footer,
depending on the user's choice;
displays the number of nodes (always)
Input Parameter: list
*****************************************************************************/
void displayManager(const LinkedList &list)
{
string action;
cout << "\nDisplay list [Y/N]? ";
cin >> action;
if(action == "Y" || action == "y")
{
cout << "\n====== ==== =============================
=========\n"
<< " Code Rank Name Cost \n"
<< "====== ==== =============================
=========\n";
list.displayList() // The list object of LinkedList calls
the display method to display College objects in the sorted order
of the code
cout << "====== ==== =============================
=========\n";
}
cout << "Number of colleges in this list: " << /* Write
your code here: call getLength */ endl;
}
Explanation :