SlideShare a Scribd company logo
1 of 31
Download to read offline
#include
#include
#include
#include "CityList.h"
using namespace std;
void welcome();
void readCityData(CityList *readList);
void printCityData(CityList *printList);
void searchCityData(CityList *searchList);
void deleteCityData(CityList *deleteList);
void goodbye();
int main()
{
CityList list;
// WELCOME FUNCTION
welcome();
// A. Read data from a text file
readCityData(&list);
// B. Print the list
printCityData(&list);
// C. Seach Function
searchCityData(&list);
// D. Delete Function
deleteCityData(&list);
// EXTRA. Check the Result (Inactive)
// list.displayList();
// GOODBYE FUNCTION
goodbye();
return 0;
}
//****************************************************************************
*
// Definition of function welcome
// This function displays the welcome screen
//****************************************************************************
*
void welcome()
{
cout << "Welcome to the Linked Lists Project" << endl;
cout << "___________________________________" << endl << endl;
}
//****************************************************************************
*
// Definition of function readCityData
// This function save the city list from the file to the linked list
//****************************************************************************
*
void readCityData(CityList *readList)
{
cout << endl << "A. Read City Data" << endl;
cout << "___________________" << endl;
Data import;
ifstream infile;
infile.open("cities.txt");
while(!infile)
{
cout << "FILE OPEN ERROR" << endl;
exit(111);
}
while(infile>>import.state)
{
//infile >> import.state;
infile >> import.year;
infile.ignore();
getline(infile, import.city);
// DEBUG //
/*
cout << import.state;
cout << import.year;
cout << import.city;
cout << endl;
*/
readList->insertNode(import);
}
infile.close();
cout << endl << "Complete to read data" << endl;
cout << "___________________" << endl;
}
//****************************************************************************
*
// Definition of function printCityData
// This function displays the city list
//****************************************************************************
*
void printCityData(CityList * printList)
{
cout << endl << endl << "B. Print City Data" << endl;
cout << "___________________" << endl << endl;
cout << left << setw(10) << "State" << setw(10) << "Year" << setw(20) << "City" <<
endl;
cout << setw(10) << "-----" << setw(10) << "-----" << setw(20) << "----------" << endl;
printList->displayList();
cout << "___________________" << endl;
}
//****************************************************************************
*
// Definition of function searchCityData
// This function search the city from the city data
//****************************************************************************
*
void searchCityData(CityList * searchList)
{
string searchCity;
cout << endl << "C. Search City Data" << endl;
cout << "___________________" << endl;
while(searchCity!="QUIT")
{
cout << endl << "Enter the city for search (QUIT for stop searching) : ";
getline(cin,searchCity);
if(searchCity!="QUIT")
{
searchList->searchList(searchCity);
}
}
cout << "___________________" << endl;
}
//****************************************************************************
*
// Definition of function deleteCityData
// This function delete the city from the city data
//****************************************************************************
*
void deleteCityData(CityList * deleteList)
{
string searchCity;
cout << endl << endl << "D. Delete City Data" << endl;
cout << "___________________" << endl;
while(searchCity!="QUIT")
{
cout << endl << "Enter the city for delete (QUIT for stop searching) : ";
getline(cin,searchCity);
if(searchCity!="QUIT")
{
deleteList->deleteNode(searchCity);
}
}
}
//****************************************************************************
*
// Definition of function goodbye
// This function displays the goodbye screen
//****************************************************************************
*
void goodbye()
{
cout << endl << endl << "______________________________________________" <<
endl << endl;
cout << "Thank you for using the Linked Lists Project" << endl;
}
CityList.h
// Specification file for the CityList class
#ifndef CITYLIST_H
#define CITYLIST_H
#include
using namespace std;
struct Data
{
string state;
int year;
string city;
// other fields could be added here
};
class CityList
{
private:
// Declare a structure for the list
struct ListNode
{
//double value; // The value in this node
Data data;
ListNode *next; // To point to the next node
};
ListNode *head; // List head pointer
public:
// Constructor
CityList()
{ head = NULL; }
// Destructor
~CityList();
// Linked list operations
void insertNode(Data); //void insertNode(double);
void deleteNode(string);
void searchList(string) const;
void displayList() const;
};
#endif
CityList.cpp
// Implementation file for the CityList class
#include // For cout and NULL
#include
#include "CityList.h"
using namespace std;
//**************************************************
// displayList shows the value *
// stored in each node of the linked list *
// pointed to by head. *
//**************************************************
void CityList::displayList() const
{
ListNode *nodePtr; // To move through the list
// Position nodePtr at the head of the list.
nodePtr = head;
// While nodePtr points to a node, traverse
// the list.
while (nodePtr)
{
// Display the value in this node.
cout << setw(10) << nodePtr->data.state;
cout << setw(10) << nodePtr->data.year;
cout << setw(20) << nodePtr->data.city << endl;
// Move to the next node.
nodePtr = nodePtr->next;
}
}
//**************************************************
// The insertNode function inserts a node with *
// data copied to its data member. *
//**************************************************
void CityList::insertNode(Data dataIn)
{
ListNode *newNode; // A new node
ListNode *nodePtr; // To traverse the list
ListNode *previousNode = NULL; // The previous node
// Allocate a new node and store num there.
newNode = new ListNode;
newNode->data.state = dataIn.state;
newNode->data.year = dataIn.year;
newNode->data.city = dataIn.city;
// If there are no nodes in the list
// make newNode the first node
if (!head)
{
head = newNode;
newNode->next = NULL;
}
else // Otherwise, insert newNode
{
// Position nodePtr at the head of list.
nodePtr = head;
// Initialize previousNode to NULL.
previousNode = NULL;
// Skip all nodes whose value is less than num.
while (nodePtr != NULL && nodePtr->data.city < dataIn.city)
{
previousNode = nodePtr;
nodePtr = nodePtr->next;
}
// If the new node is to be the 1st in the list,
// insert it before all other nodes.
if (previousNode == NULL)
{
head = newNode;
newNode->next = nodePtr;
}
else // Otherwise insert after the previous node.
{
previousNode->next = newNode;
newNode->next = nodePtr;
}
}
}
//**************************************************
// The searchList function searches for a node *
// with city as its value. The node, if found, is *
// print from the list. *
//**************************************************
void CityList::searchList(string city) const
{
ListNode *nodePtr; // To move through the list
// Position nodePtr at the head of the list.
nodePtr = head;
// While nodePtr points to a node and
// whose value member is not equal to city traverse
// the list.
while (nodePtr != NULL && nodePtr->data.city!=city)
{
// Move to the next node.
nodePtr = nodePtr->next;
}
// Display the value in this node.
if(nodePtr != NULL && nodePtr->data.city==city)
{
cout << endl << left << setw(10) << "State" << setw(10) << "Year" << setw(20) <<
"City" << endl;
cout << setw(10) << "-----" << setw(10) << "-----" << setw(20) << "----------" << endl;
cout << setw(10) << nodePtr->data.state;
cout << setw(10) << nodePtr->data.year;
cout << setw(20) << nodePtr->data.city << endl;
}
// Display error if there is no result in this node
else
{
cout << "<" << city << ">" << " was not found" << endl;
}
}
//**************************************************
// The deleteNode function searches for a node *
// with city as its value. The node, if found, is *
// deleted from the list and from memory. *
//**************************************************
void CityList::deleteNode(string city)
{
ListNode *nodePtr; // To traverse the list
ListNode *previousNode; // To point to the previous node
// If the list is empty, do nothing.
if (!head)
return;
// Determine if the first node is the one.
//if (head->value == num)
if (head->data.city == city)
{
cout << endl << left << setw(10) << "State" << setw(10) << "Year" << setw(20) <<
"City" << endl;
cout << setw(10) << "-----" << setw(10) << "-----" << setw(20) << "----------" << endl;
cout << setw(10) << head->data.state;
cout << setw(10) << head->data.year;
cout << setw(20) << head->data.city << endl;
cout << "** Delete the " << city << " **" << endl;
nodePtr = head->next;
delete head;
head = nodePtr;
}
else
{
// Initialize nodePtr to head of list
nodePtr = head;
// Skip all nodes whose value member is
// not equal to city.
while (nodePtr != NULL && nodePtr->data.city != city)
{
previousNode = nodePtr;
nodePtr = nodePtr->next;
}
// If nodePtr is not at the end of the list,
// link the previous node to the node after
// nodePtr, then delete nodePtr.
if (nodePtr)
{
cout << endl << left << setw(10) << "State" << setw(10) << "Year" << setw(20) <<
"City" << endl;
cout << setw(10) << "-----" << setw(10) << "-----" << setw(20) << "----------" << endl;
cout << setw(10) << nodePtr->data.state;
cout << setw(10) << nodePtr->data.year;
cout << setw(20) << nodePtr->data.city << endl;
cout << "** Delete the " << city << " **" << endl;
previousNode->next = nodePtr->next;
delete nodePtr;
}
// Display error if there is no result in this node
else
{
cout << "<" << city << ">" << " was not found" << endl;
}
}
}
//**************************************************
// Destructor *
// This function deletes every node in the list. *
//**************************************************
CityList::~CityList()
{
ListNode *nodePtr; // To traverse the list
ListNode *nextNode; // To point to the next node
// Position nodePtr at the head of the list.
nodePtr = head;
// While nodePtr is not at the end of the list...
while (nodePtr != NULL)
{
// Save a pointer to the next node.
nextNode = nodePtr->next;
// Delete the current node.
delete nodePtr;
// Position nodePtr at the next node.
nodePtr = nextNode;
}
}
cities.txt
TX 1837 San Antonio
CA 1850 Los Angeles
TX 1856 Dallas
AZ 1881 Phoenix
IL 1837 Chicago
PA 1701 Philadelphia
OH 1834 Columbus
WI 1846 Milwaukee
NY 1898 New York
IN 1832 Indianapolis
MD 1797 Baltimore
DC 1788 Washington
FL 1822 Jacksonville
TN 1826 Memphis
TX 1837 Huston
CA 1850 San Diego
CA 1850 San Jose
MI 1815 Detroit
CA 1850 San Francisco
MA 1822 Boston
Sample output
Welcome to the Linked Lists Project
___________________________________
A. Read City Data
___________________
Complete to read data
___________________
B. Print City Data
___________________
State Year City
----- ----- ----------
MD 1797 Baltimore
MA 1822 Boston
IL 1837 Chicago
OH 1834 Columbus
TX 1856 Dallas
MI 1815 Detroit
TX 1837 Huston
IN 1832 Indianapolis
FL 1822 Jacksonville
CA 1850 Los Angeles
TN 1826 Memphis
WI 1846 Milwaukee
NY 1898 New York
PA 1701 Philadelphia
AZ 1881 Phoenix
TX 1837 San Antonio
CA 1850 San Diego
CA 1850 San Francisco
CA 1850 San Jose
DC 1788 Washington
___________________
C. Search City Data
___________________
Enter the city for search (QUIT for stop searching) : Baltimore
State Year City
----- ----- ----------
MD 1797 Baltimore
Enter the city for search (QUIT for stop searching) : Washington
State Year City
----- ----- ----------
DC 1788 Washington
Enter the city for search (QUIT for stop searching) : Memphis
State Year City
----- ----- ----------
TN 1826 Memphis
Enter the city for search (QUIT for stop searching) : Cupertino
was not found
Enter the city for search (QUIT for stop searching) : QUIT
___________________
D. Delete City Data
___________________
Enter the city for delete (QUIT for stop searching) : Baltimore
State Year City
----- ----- ----------
MD 1797 Baltimore
** Delete the Baltimore**
Enter the city for delete (QUIT for stop searching) : Baltimore
was not found
Enter the city for delete (QUIT for stop searching) : Washington
State Year City
----- ----- ----------
DC 1788 Washington
** Delete the Washington**
Enter the city for delete (QUIT for stop searching) : Washington
was not found
Enter the city for delete (QUIT for stop searching) : Cupertino
was not found
Enter the city for delete (QUIT for stop searching) : QUIT
______________________________________________
Thank you for using the Linked Lists Project
Solution
#include
#include
#include
#include "CityList.h"
using namespace std;
void welcome();
void readCityData(CityList *readList);
void printCityData(CityList *printList);
void searchCityData(CityList *searchList);
void deleteCityData(CityList *deleteList);
void goodbye();
int main()
{
CityList list;
// WELCOME FUNCTION
welcome();
// A. Read data from a text file
readCityData(&list);
// B. Print the list
printCityData(&list);
// C. Seach Function
searchCityData(&list);
// D. Delete Function
deleteCityData(&list);
// EXTRA. Check the Result (Inactive)
// list.displayList();
// GOODBYE FUNCTION
goodbye();
return 0;
}
//****************************************************************************
*
// Definition of function welcome
// This function displays the welcome screen
//****************************************************************************
*
void welcome()
{
cout << "Welcome to the Linked Lists Project" << endl;
cout << "___________________________________" << endl << endl;
}
//****************************************************************************
*
// Definition of function readCityData
// This function save the city list from the file to the linked list
//****************************************************************************
*
void readCityData(CityList *readList)
{
cout << endl << "A. Read City Data" << endl;
cout << "___________________" << endl;
Data import;
ifstream infile;
infile.open("cities.txt");
while(!infile)
{
cout << "FILE OPEN ERROR" << endl;
exit(111);
}
while(infile>>import.state)
{
//infile >> import.state;
infile >> import.year;
infile.ignore();
getline(infile, import.city);
// DEBUG //
/*
cout << import.state;
cout << import.year;
cout << import.city;
cout << endl;
*/
readList->insertNode(import);
}
infile.close();
cout << endl << "Complete to read data" << endl;
cout << "___________________" << endl;
}
//****************************************************************************
*
// Definition of function printCityData
// This function displays the city list
//****************************************************************************
*
void printCityData(CityList * printList)
{
cout << endl << endl << "B. Print City Data" << endl;
cout << "___________________" << endl << endl;
cout << left << setw(10) << "State" << setw(10) << "Year" << setw(20) << "City" <<
endl;
cout << setw(10) << "-----" << setw(10) << "-----" << setw(20) << "----------" << endl;
printList->displayList();
cout << "___________________" << endl;
}
//****************************************************************************
*
// Definition of function searchCityData
// This function search the city from the city data
//****************************************************************************
*
void searchCityData(CityList * searchList)
{
string searchCity;
cout << endl << "C. Search City Data" << endl;
cout << "___________________" << endl;
while(searchCity!="QUIT")
{
cout << endl << "Enter the city for search (QUIT for stop searching) : ";
getline(cin,searchCity);
if(searchCity!="QUIT")
{
searchList->searchList(searchCity);
}
}
cout << "___________________" << endl;
}
//****************************************************************************
*
// Definition of function deleteCityData
// This function delete the city from the city data
//****************************************************************************
*
void deleteCityData(CityList * deleteList)
{
string searchCity;
cout << endl << endl << "D. Delete City Data" << endl;
cout << "___________________" << endl;
while(searchCity!="QUIT")
{
cout << endl << "Enter the city for delete (QUIT for stop searching) : ";
getline(cin,searchCity);
if(searchCity!="QUIT")
{
deleteList->deleteNode(searchCity);
}
}
}
//****************************************************************************
*
// Definition of function goodbye
// This function displays the goodbye screen
//****************************************************************************
*
void goodbye()
{
cout << endl << endl << "______________________________________________" <<
endl << endl;
cout << "Thank you for using the Linked Lists Project" << endl;
}
CityList.h
// Specification file for the CityList class
#ifndef CITYLIST_H
#define CITYLIST_H
#include
using namespace std;
struct Data
{
string state;
int year;
string city;
// other fields could be added here
};
class CityList
{
private:
// Declare a structure for the list
struct ListNode
{
//double value; // The value in this node
Data data;
ListNode *next; // To point to the next node
};
ListNode *head; // List head pointer
public:
// Constructor
CityList()
{ head = NULL; }
// Destructor
~CityList();
// Linked list operations
void insertNode(Data); //void insertNode(double);
void deleteNode(string);
void searchList(string) const;
void displayList() const;
};
#endif
CityList.cpp
// Implementation file for the CityList class
#include // For cout and NULL
#include
#include "CityList.h"
using namespace std;
//**************************************************
// displayList shows the value *
// stored in each node of the linked list *
// pointed to by head. *
//**************************************************
void CityList::displayList() const
{
ListNode *nodePtr; // To move through the list
// Position nodePtr at the head of the list.
nodePtr = head;
// While nodePtr points to a node, traverse
// the list.
while (nodePtr)
{
// Display the value in this node.
cout << setw(10) << nodePtr->data.state;
cout << setw(10) << nodePtr->data.year;
cout << setw(20) << nodePtr->data.city << endl;
// Move to the next node.
nodePtr = nodePtr->next;
}
}
//**************************************************
// The insertNode function inserts a node with *
// data copied to its data member. *
//**************************************************
void CityList::insertNode(Data dataIn)
{
ListNode *newNode; // A new node
ListNode *nodePtr; // To traverse the list
ListNode *previousNode = NULL; // The previous node
// Allocate a new node and store num there.
newNode = new ListNode;
newNode->data.state = dataIn.state;
newNode->data.year = dataIn.year;
newNode->data.city = dataIn.city;
// If there are no nodes in the list
// make newNode the first node
if (!head)
{
head = newNode;
newNode->next = NULL;
}
else // Otherwise, insert newNode
{
// Position nodePtr at the head of list.
nodePtr = head;
// Initialize previousNode to NULL.
previousNode = NULL;
// Skip all nodes whose value is less than num.
while (nodePtr != NULL && nodePtr->data.city < dataIn.city)
{
previousNode = nodePtr;
nodePtr = nodePtr->next;
}
// If the new node is to be the 1st in the list,
// insert it before all other nodes.
if (previousNode == NULL)
{
head = newNode;
newNode->next = nodePtr;
}
else // Otherwise insert after the previous node.
{
previousNode->next = newNode;
newNode->next = nodePtr;
}
}
}
//**************************************************
// The searchList function searches for a node *
// with city as its value. The node, if found, is *
// print from the list. *
//**************************************************
void CityList::searchList(string city) const
{
ListNode *nodePtr; // To move through the list
// Position nodePtr at the head of the list.
nodePtr = head;
// While nodePtr points to a node and
// whose value member is not equal to city traverse
// the list.
while (nodePtr != NULL && nodePtr->data.city!=city)
{
// Move to the next node.
nodePtr = nodePtr->next;
}
// Display the value in this node.
if(nodePtr != NULL && nodePtr->data.city==city)
{
cout << endl << left << setw(10) << "State" << setw(10) << "Year" << setw(20) <<
"City" << endl;
cout << setw(10) << "-----" << setw(10) << "-----" << setw(20) << "----------" << endl;
cout << setw(10) << nodePtr->data.state;
cout << setw(10) << nodePtr->data.year;
cout << setw(20) << nodePtr->data.city << endl;
}
// Display error if there is no result in this node
else
{
cout << "<" << city << ">" << " was not found" << endl;
}
}
//**************************************************
// The deleteNode function searches for a node *
// with city as its value. The node, if found, is *
// deleted from the list and from memory. *
//**************************************************
void CityList::deleteNode(string city)
{
ListNode *nodePtr; // To traverse the list
ListNode *previousNode; // To point to the previous node
// If the list is empty, do nothing.
if (!head)
return;
// Determine if the first node is the one.
//if (head->value == num)
if (head->data.city == city)
{
cout << endl << left << setw(10) << "State" << setw(10) << "Year" << setw(20) <<
"City" << endl;
cout << setw(10) << "-----" << setw(10) << "-----" << setw(20) << "----------" << endl;
cout << setw(10) << head->data.state;
cout << setw(10) << head->data.year;
cout << setw(20) << head->data.city << endl;
cout << "** Delete the " << city << " **" << endl;
nodePtr = head->next;
delete head;
head = nodePtr;
}
else
{
// Initialize nodePtr to head of list
nodePtr = head;
// Skip all nodes whose value member is
// not equal to city.
while (nodePtr != NULL && nodePtr->data.city != city)
{
previousNode = nodePtr;
nodePtr = nodePtr->next;
}
// If nodePtr is not at the end of the list,
// link the previous node to the node after
// nodePtr, then delete nodePtr.
if (nodePtr)
{
cout << endl << left << setw(10) << "State" << setw(10) << "Year" << setw(20) <<
"City" << endl;
cout << setw(10) << "-----" << setw(10) << "-----" << setw(20) << "----------" << endl;
cout << setw(10) << nodePtr->data.state;
cout << setw(10) << nodePtr->data.year;
cout << setw(20) << nodePtr->data.city << endl;
cout << "** Delete the " << city << " **" << endl;
previousNode->next = nodePtr->next;
delete nodePtr;
}
// Display error if there is no result in this node
else
{
cout << "<" << city << ">" << " was not found" << endl;
}
}
}
//**************************************************
// Destructor *
// This function deletes every node in the list. *
//**************************************************
CityList::~CityList()
{
ListNode *nodePtr; // To traverse the list
ListNode *nextNode; // To point to the next node
// Position nodePtr at the head of the list.
nodePtr = head;
// While nodePtr is not at the end of the list...
while (nodePtr != NULL)
{
// Save a pointer to the next node.
nextNode = nodePtr->next;
// Delete the current node.
delete nodePtr;
// Position nodePtr at the next node.
nodePtr = nextNode;
}
}
cities.txt
TX 1837 San Antonio
CA 1850 Los Angeles
TX 1856 Dallas
AZ 1881 Phoenix
IL 1837 Chicago
PA 1701 Philadelphia
OH 1834 Columbus
WI 1846 Milwaukee
NY 1898 New York
IN 1832 Indianapolis
MD 1797 Baltimore
DC 1788 Washington
FL 1822 Jacksonville
TN 1826 Memphis
TX 1837 Huston
CA 1850 San Diego
CA 1850 San Jose
MI 1815 Detroit
CA 1850 San Francisco
MA 1822 Boston
Sample output
Welcome to the Linked Lists Project
___________________________________
A. Read City Data
___________________
Complete to read data
___________________
B. Print City Data
___________________
State Year City
----- ----- ----------
MD 1797 Baltimore
MA 1822 Boston
IL 1837 Chicago
OH 1834 Columbus
TX 1856 Dallas
MI 1815 Detroit
TX 1837 Huston
IN 1832 Indianapolis
FL 1822 Jacksonville
CA 1850 Los Angeles
TN 1826 Memphis
WI 1846 Milwaukee
NY 1898 New York
PA 1701 Philadelphia
AZ 1881 Phoenix
TX 1837 San Antonio
CA 1850 San Diego
CA 1850 San Francisco
CA 1850 San Jose
DC 1788 Washington
___________________
C. Search City Data
___________________
Enter the city for search (QUIT for stop searching) : Baltimore
State Year City
----- ----- ----------
MD 1797 Baltimore
Enter the city for search (QUIT for stop searching) : Washington
State Year City
----- ----- ----------
DC 1788 Washington
Enter the city for search (QUIT for stop searching) : Memphis
State Year City
----- ----- ----------
TN 1826 Memphis
Enter the city for search (QUIT for stop searching) : Cupertino
was not found
Enter the city for search (QUIT for stop searching) : QUIT
___________________
D. Delete City Data
___________________
Enter the city for delete (QUIT for stop searching) : Baltimore
State Year City
----- ----- ----------
MD 1797 Baltimore
** Delete the Baltimore**
Enter the city for delete (QUIT for stop searching) : Baltimore
was not found
Enter the city for delete (QUIT for stop searching) : Washington
State Year City
----- ----- ----------
DC 1788 Washington
** Delete the Washington**
Enter the city for delete (QUIT for stop searching) : Washington
was not found
Enter the city for delete (QUIT for stop searching) : Cupertino
was not found
Enter the city for delete (QUIT for stop searching) : QUIT
______________________________________________
Thank you for using the Linked Lists Project

More Related Content

Similar to #include iostream #include fstream #include iomanip #.pdf

maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdf
adityastores21
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdf
kostikjaylonshaewe47
 
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docxProgram 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
wkyra78
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
michardsonkhaicarr37
 
Can someone solve the TODO parts of the following problem i.pdf
Can someone solve the TODO parts of the following problem i.pdfCan someone solve the TODO parts of the following problem i.pdf
Can someone solve the TODO parts of the following problem i.pdf
akshpatil4
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
fantoosh1
 
  import java.util.;import acm.program.;public class FlightPla.pdf
  import java.util.;import acm.program.;public class FlightPla.pdf  import java.util.;import acm.program.;public class FlightPla.pdf
  import java.util.;import acm.program.;public class FlightPla.pdf
anushasarees
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
anujmkt
 
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docxAvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
rock73
 
LISTINGS.txt345678 116900 0 80513-2918 Metro Brokers432395.docx
LISTINGS.txt345678 116900 0 80513-2918  Metro Brokers432395.docxLISTINGS.txt345678 116900 0 80513-2918  Metro Brokers432395.docx
LISTINGS.txt345678 116900 0 80513-2918 Metro Brokers432395.docx
SHIVA101531
 
CountryData.cppEDIT THIS ONE#include fstream #include str.pdf
CountryData.cppEDIT THIS ONE#include fstream #include str.pdfCountryData.cppEDIT THIS ONE#include fstream #include str.pdf
CountryData.cppEDIT THIS ONE#include fstream #include str.pdf
Aggarwalelectronic18
 
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
Getting the following errorsError 1 error C2436 {ctor}  mem.pdfGetting the following errorsError 1 error C2436 {ctor}  mem.pdf
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
herminaherman
 
Need help getting past an error in C++! I have all my code pasted down.docx
Need help getting past an error in C++! I have all my code pasted down.docxNeed help getting past an error in C++! I have all my code pasted down.docx
Need help getting past an error in C++! I have all my code pasted down.docx
Jason0x0Scottw
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
Malikireddy Bramhananda Reddy
 

Similar to #include iostream #include fstream #include iomanip #.pdf (20)

maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdf
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdf
 
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docxProgram 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
Can someone solve the TODO parts of the following problem i.pdf
Can someone solve the TODO parts of the following problem i.pdfCan someone solve the TODO parts of the following problem i.pdf
Can someone solve the TODO parts of the following problem i.pdf
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdf
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
 
  import java.util.;import acm.program.;public class FlightPla.pdf
  import java.util.;import acm.program.;public class FlightPla.pdf  import java.util.;import acm.program.;public class FlightPla.pdf
  import java.util.;import acm.program.;public class FlightPla.pdf
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx
 
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docxAvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
 
Write CC++ a program that inputs a weighted undirected graph and fi.pdf
Write CC++ a program that inputs a weighted undirected graph and fi.pdfWrite CC++ a program that inputs a weighted undirected graph and fi.pdf
Write CC++ a program that inputs a weighted undirected graph and fi.pdf
 
LISTINGS.txt345678 116900 0 80513-2918 Metro Brokers432395.docx
LISTINGS.txt345678 116900 0 80513-2918  Metro Brokers432395.docxLISTINGS.txt345678 116900 0 80513-2918  Metro Brokers432395.docx
LISTINGS.txt345678 116900 0 80513-2918 Metro Brokers432395.docx
 
CountryData.cppEDIT THIS ONE#include fstream #include str.pdf
CountryData.cppEDIT THIS ONE#include fstream #include str.pdfCountryData.cppEDIT THIS ONE#include fstream #include str.pdf
CountryData.cppEDIT THIS ONE#include fstream #include str.pdf
 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query Tuning
 
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
Getting the following errorsError 1 error C2436 {ctor}  mem.pdfGetting the following errorsError 1 error C2436 {ctor}  mem.pdf
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
 
Need help getting past an error in C++! I have all my code pasted down.docx
Need help getting past an error in C++! I have all my code pasted down.docxNeed help getting past an error in C++! I have all my code pasted down.docx
Need help getting past an error in C++! I have all my code pasted down.docx
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 

More from KARTIKINDIA

We first see what is the Small Intestine – It connects the stomach a.pdf
We first see what is the Small Intestine – It connects the stomach a.pdfWe first see what is the Small Intestine – It connects the stomach a.pdf
We first see what is the Small Intestine – It connects the stomach a.pdf
KARTIKINDIA
 
The same Mechanisms of genetic exchange in bacteria 1. Conjugation .pdf
The same Mechanisms of genetic exchange in bacteria 1. Conjugation .pdfThe same Mechanisms of genetic exchange in bacteria 1. Conjugation .pdf
The same Mechanisms of genetic exchange in bacteria 1. Conjugation .pdf
KARTIKINDIA
 
The cam material will be UHMW polyethylene because it had the lost c.pdf
The cam material will be UHMW polyethylene because it had the lost c.pdfThe cam material will be UHMW polyethylene because it had the lost c.pdf
The cam material will be UHMW polyethylene because it had the lost c.pdf
KARTIKINDIA
 
Ques-1 antinormative collective pro-social behaviorReasonOnlin.pdf
Ques-1 antinormative collective pro-social behaviorReasonOnlin.pdfQues-1 antinormative collective pro-social behaviorReasonOnlin.pdf
Ques-1 antinormative collective pro-social behaviorReasonOnlin.pdf
KARTIKINDIA
 
Physical properties can be observed or measured without changing the.pdf
Physical properties can be observed or measured without changing the.pdfPhysical properties can be observed or measured without changing the.pdf
Physical properties can be observed or measured without changing the.pdf
KARTIKINDIA
 
Please follow the data and description 1) An association indicate.pdf
Please follow the data and description 1) An association indicate.pdfPlease follow the data and description 1) An association indicate.pdf
Please follow the data and description 1) An association indicate.pdf
KARTIKINDIA
 
package chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdfpackage chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdf
KARTIKINDIA
 
Intelligence comes from the Latin verb intellegere, which means .pdf
Intelligence comes from the Latin verb intellegere, which means .pdfIntelligence comes from the Latin verb intellegere, which means .pdf
Intelligence comes from the Latin verb intellegere, which means .pdf
KARTIKINDIA
 
Initial compromise is the method that is adopted by intruders to ent.pdf
Initial compromise is the method that is adopted by intruders to ent.pdfInitial compromise is the method that is adopted by intruders to ent.pdf
Initial compromise is the method that is adopted by intruders to ent.pdf
KARTIKINDIA
 
A. 1.Virus modified exoxomes are specialized form of nano sized vesi.pdf
A. 1.Virus modified exoxomes are specialized form of nano sized vesi.pdfA. 1.Virus modified exoxomes are specialized form of nano sized vesi.pdf
A. 1.Virus modified exoxomes are specialized form of nano sized vesi.pdf
KARTIKINDIA
 
Hi,pease find ansers for Questions1.5 Fill in the Blanksa) The.pdf
Hi,pease find ansers for Questions1.5 Fill in the Blanksa) The.pdfHi,pease find ansers for Questions1.5 Fill in the Blanksa) The.pdf
Hi,pease find ansers for Questions1.5 Fill in the Blanksa) The.pdf
KARTIKINDIA
 

More from KARTIKINDIA (20)

We first see what is the Small Intestine – It connects the stomach a.pdf
We first see what is the Small Intestine – It connects the stomach a.pdfWe first see what is the Small Intestine – It connects the stomach a.pdf
We first see what is the Small Intestine – It connects the stomach a.pdf
 
Water needs to be present. The 2 compounds will only react after.pdf
Water needs to be present. The 2 compounds will only react after.pdfWater needs to be present. The 2 compounds will only react after.pdf
Water needs to be present. The 2 compounds will only react after.pdf
 
True.SolutionTrue..pdf
True.SolutionTrue..pdfTrue.SolutionTrue..pdf
True.SolutionTrue..pdf
 
1) option d is the answer, i.e. 11Solution1) option d is the a.pdf
1) option d is the answer, i.e. 11Solution1) option d is the a.pdf1) option d is the answer, i.e. 11Solution1) option d is the a.pdf
1) option d is the answer, i.e. 11Solution1) option d is the a.pdf
 
The same Mechanisms of genetic exchange in bacteria 1. Conjugation .pdf
The same Mechanisms of genetic exchange in bacteria 1. Conjugation .pdfThe same Mechanisms of genetic exchange in bacteria 1. Conjugation .pdf
The same Mechanisms of genetic exchange in bacteria 1. Conjugation .pdf
 
The answer is b) facilitates O2 diffusion through alveolar membrane.pdf
The answer is b) facilitates O2 diffusion through alveolar membrane.pdfThe answer is b) facilitates O2 diffusion through alveolar membrane.pdf
The answer is b) facilitates O2 diffusion through alveolar membrane.pdf
 
The cam material will be UHMW polyethylene because it had the lost c.pdf
The cam material will be UHMW polyethylene because it had the lost c.pdfThe cam material will be UHMW polyethylene because it had the lost c.pdf
The cam material will be UHMW polyethylene because it had the lost c.pdf
 
tan(x)=1x=pi4Solutiontan(x)=1x=pi4.pdf
tan(x)=1x=pi4Solutiontan(x)=1x=pi4.pdftan(x)=1x=pi4Solutiontan(x)=1x=pi4.pdf
tan(x)=1x=pi4Solutiontan(x)=1x=pi4.pdf
 
Ques-1 antinormative collective pro-social behaviorReasonOnlin.pdf
Ques-1 antinormative collective pro-social behaviorReasonOnlin.pdfQues-1 antinormative collective pro-social behaviorReasonOnlin.pdf
Ques-1 antinormative collective pro-social behaviorReasonOnlin.pdf
 
Physical properties can be observed or measured without changing the.pdf
Physical properties can be observed or measured without changing the.pdfPhysical properties can be observed or measured without changing the.pdf
Physical properties can be observed or measured without changing the.pdf
 
(E) a+ and b+ are more closely linked than a+ and c+.   If two gen.pdf
(E) a+ and b+ are more closely linked than a+ and c+.   If two gen.pdf(E) a+ and b+ are more closely linked than a+ and c+.   If two gen.pdf
(E) a+ and b+ are more closely linked than a+ and c+.   If two gen.pdf
 
Please follow the data and description 1) An association indicate.pdf
Please follow the data and description 1) An association indicate.pdfPlease follow the data and description 1) An association indicate.pdf
Please follow the data and description 1) An association indicate.pdf
 
package chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdfpackage chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdf
 
Mononucleotides are monomer of polynucleotides. Its three uses are-.pdf
Mononucleotides are monomer of polynucleotides. Its three uses are-.pdfMononucleotides are monomer of polynucleotides. Its three uses are-.pdf
Mononucleotides are monomer of polynucleotides. Its three uses are-.pdf
 
Intelligence comes from the Latin verb intellegere, which means .pdf
Intelligence comes from the Latin verb intellegere, which means .pdfIntelligence comes from the Latin verb intellegere, which means .pdf
Intelligence comes from the Latin verb intellegere, which means .pdf
 
Initial compromise is the method that is adopted by intruders to ent.pdf
Initial compromise is the method that is adopted by intruders to ent.pdfInitial compromise is the method that is adopted by intruders to ent.pdf
Initial compromise is the method that is adopted by intruders to ent.pdf
 
I agree .Ethernet nodes listen to the medium when they want to tra.pdf
I agree .Ethernet nodes listen to the medium when they want to tra.pdfI agree .Ethernet nodes listen to the medium when they want to tra.pdf
I agree .Ethernet nodes listen to the medium when they want to tra.pdf
 
A. 1.Virus modified exoxomes are specialized form of nano sized vesi.pdf
A. 1.Virus modified exoxomes are specialized form of nano sized vesi.pdfA. 1.Virus modified exoxomes are specialized form of nano sized vesi.pdf
A. 1.Virus modified exoxomes are specialized form of nano sized vesi.pdf
 
Hi,pease find ansers for Questions1.5 Fill in the Blanksa) The.pdf
Hi,pease find ansers for Questions1.5 Fill in the Blanksa) The.pdfHi,pease find ansers for Questions1.5 Fill in the Blanksa) The.pdf
Hi,pease find ansers for Questions1.5 Fill in the Blanksa) The.pdf
 
(1)White matter in the cerebellumThe arbor vitae refers to the c.pdf
(1)White matter in the cerebellumThe arbor vitae refers to the c.pdf(1)White matter in the cerebellumThe arbor vitae refers to the c.pdf
(1)White matter in the cerebellumThe arbor vitae refers to the c.pdf
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 

Recently uploaded (20)

PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 

#include iostream #include fstream #include iomanip #.pdf

  • 1. #include #include #include #include "CityList.h" using namespace std; void welcome(); void readCityData(CityList *readList); void printCityData(CityList *printList); void searchCityData(CityList *searchList); void deleteCityData(CityList *deleteList); void goodbye(); int main() { CityList list; // WELCOME FUNCTION welcome(); // A. Read data from a text file readCityData(&list); // B. Print the list printCityData(&list); // C. Seach Function searchCityData(&list); // D. Delete Function deleteCityData(&list); // EXTRA. Check the Result (Inactive) // list.displayList(); // GOODBYE FUNCTION goodbye();
  • 2. return 0; } //**************************************************************************** * // Definition of function welcome // This function displays the welcome screen //**************************************************************************** * void welcome() { cout << "Welcome to the Linked Lists Project" << endl; cout << "___________________________________" << endl << endl; } //**************************************************************************** * // Definition of function readCityData // This function save the city list from the file to the linked list //**************************************************************************** * void readCityData(CityList *readList) { cout << endl << "A. Read City Data" << endl; cout << "___________________" << endl; Data import; ifstream infile; infile.open("cities.txt"); while(!infile) { cout << "FILE OPEN ERROR" << endl; exit(111); }
  • 3. while(infile>>import.state) { //infile >> import.state; infile >> import.year; infile.ignore(); getline(infile, import.city); // DEBUG // /* cout << import.state; cout << import.year; cout << import.city; cout << endl; */ readList->insertNode(import); } infile.close(); cout << endl << "Complete to read data" << endl; cout << "___________________" << endl; } //**************************************************************************** * // Definition of function printCityData // This function displays the city list //**************************************************************************** * void printCityData(CityList * printList) { cout << endl << endl << "B. Print City Data" << endl; cout << "___________________" << endl << endl; cout << left << setw(10) << "State" << setw(10) << "Year" << setw(20) << "City" <<
  • 4. endl; cout << setw(10) << "-----" << setw(10) << "-----" << setw(20) << "----------" << endl; printList->displayList(); cout << "___________________" << endl; } //**************************************************************************** * // Definition of function searchCityData // This function search the city from the city data //**************************************************************************** * void searchCityData(CityList * searchList) { string searchCity; cout << endl << "C. Search City Data" << endl; cout << "___________________" << endl; while(searchCity!="QUIT") { cout << endl << "Enter the city for search (QUIT for stop searching) : "; getline(cin,searchCity); if(searchCity!="QUIT") { searchList->searchList(searchCity); } } cout << "___________________" << endl; } //**************************************************************************** * // Definition of function deleteCityData // This function delete the city from the city data
  • 5. //**************************************************************************** * void deleteCityData(CityList * deleteList) { string searchCity; cout << endl << endl << "D. Delete City Data" << endl; cout << "___________________" << endl; while(searchCity!="QUIT") { cout << endl << "Enter the city for delete (QUIT for stop searching) : "; getline(cin,searchCity); if(searchCity!="QUIT") { deleteList->deleteNode(searchCity); } } } //**************************************************************************** * // Definition of function goodbye // This function displays the goodbye screen //**************************************************************************** * void goodbye() { cout << endl << endl << "______________________________________________" << endl << endl; cout << "Thank you for using the Linked Lists Project" << endl; } CityList.h // Specification file for the CityList class
  • 6. #ifndef CITYLIST_H #define CITYLIST_H #include using namespace std; struct Data { string state; int year; string city; // other fields could be added here }; class CityList { private: // Declare a structure for the list struct ListNode { //double value; // The value in this node Data data; ListNode *next; // To point to the next node }; ListNode *head; // List head pointer public: // Constructor CityList() { head = NULL; } // Destructor ~CityList(); // Linked list operations void insertNode(Data); //void insertNode(double); void deleteNode(string); void searchList(string) const; void displayList() const; }; #endif
  • 7. CityList.cpp // Implementation file for the CityList class #include // For cout and NULL #include #include "CityList.h" using namespace std; //************************************************** // displayList shows the value * // stored in each node of the linked list * // pointed to by head. * //************************************************** void CityList::displayList() const { ListNode *nodePtr; // To move through the list // Position nodePtr at the head of the list. nodePtr = head; // While nodePtr points to a node, traverse // the list. while (nodePtr) { // Display the value in this node. cout << setw(10) << nodePtr->data.state; cout << setw(10) << nodePtr->data.year; cout << setw(20) << nodePtr->data.city << endl; // Move to the next node. nodePtr = nodePtr->next; } } //************************************************** // The insertNode function inserts a node with * // data copied to its data member. * //************************************************** void CityList::insertNode(Data dataIn)
  • 8. { ListNode *newNode; // A new node ListNode *nodePtr; // To traverse the list ListNode *previousNode = NULL; // The previous node // Allocate a new node and store num there. newNode = new ListNode; newNode->data.state = dataIn.state; newNode->data.year = dataIn.year; newNode->data.city = dataIn.city; // If there are no nodes in the list // make newNode the first node if (!head) { head = newNode; newNode->next = NULL; } else // Otherwise, insert newNode { // Position nodePtr at the head of list. nodePtr = head; // Initialize previousNode to NULL. previousNode = NULL; // Skip all nodes whose value is less than num. while (nodePtr != NULL && nodePtr->data.city < dataIn.city) { previousNode = nodePtr; nodePtr = nodePtr->next; } // If the new node is to be the 1st in the list, // insert it before all other nodes. if (previousNode == NULL) { head = newNode; newNode->next = nodePtr; }
  • 9. else // Otherwise insert after the previous node. { previousNode->next = newNode; newNode->next = nodePtr; } } } //************************************************** // The searchList function searches for a node * // with city as its value. The node, if found, is * // print from the list. * //************************************************** void CityList::searchList(string city) const { ListNode *nodePtr; // To move through the list // Position nodePtr at the head of the list. nodePtr = head; // While nodePtr points to a node and // whose value member is not equal to city traverse // the list. while (nodePtr != NULL && nodePtr->data.city!=city) { // Move to the next node. nodePtr = nodePtr->next; } // Display the value in this node. if(nodePtr != NULL && nodePtr->data.city==city) { cout << endl << left << setw(10) << "State" << setw(10) << "Year" << setw(20) << "City" << endl; cout << setw(10) << "-----" << setw(10) << "-----" << setw(20) << "----------" << endl; cout << setw(10) << nodePtr->data.state; cout << setw(10) << nodePtr->data.year;
  • 10. cout << setw(20) << nodePtr->data.city << endl; } // Display error if there is no result in this node else { cout << "<" << city << ">" << " was not found" << endl; } } //************************************************** // The deleteNode function searches for a node * // with city as its value. The node, if found, is * // deleted from the list and from memory. * //************************************************** void CityList::deleteNode(string city) { ListNode *nodePtr; // To traverse the list ListNode *previousNode; // To point to the previous node // If the list is empty, do nothing. if (!head) return; // Determine if the first node is the one. //if (head->value == num) if (head->data.city == city) { cout << endl << left << setw(10) << "State" << setw(10) << "Year" << setw(20) << "City" << endl; cout << setw(10) << "-----" << setw(10) << "-----" << setw(20) << "----------" << endl; cout << setw(10) << head->data.state; cout << setw(10) << head->data.year; cout << setw(20) << head->data.city << endl; cout << "** Delete the " << city << " **" << endl; nodePtr = head->next;
  • 11. delete head; head = nodePtr; } else { // Initialize nodePtr to head of list nodePtr = head; // Skip all nodes whose value member is // not equal to city. while (nodePtr != NULL && nodePtr->data.city != city) { previousNode = nodePtr; nodePtr = nodePtr->next; } // If nodePtr is not at the end of the list, // link the previous node to the node after // nodePtr, then delete nodePtr. if (nodePtr) { cout << endl << left << setw(10) << "State" << setw(10) << "Year" << setw(20) << "City" << endl; cout << setw(10) << "-----" << setw(10) << "-----" << setw(20) << "----------" << endl; cout << setw(10) << nodePtr->data.state; cout << setw(10) << nodePtr->data.year; cout << setw(20) << nodePtr->data.city << endl; cout << "** Delete the " << city << " **" << endl; previousNode->next = nodePtr->next; delete nodePtr; } // Display error if there is no result in this node else { cout << "<" << city << ">" << " was not found" << endl; }
  • 12. } } //************************************************** // Destructor * // This function deletes every node in the list. * //************************************************** CityList::~CityList() { ListNode *nodePtr; // To traverse the list ListNode *nextNode; // To point to the next node // Position nodePtr at the head of the list. nodePtr = head; // While nodePtr is not at the end of the list... while (nodePtr != NULL) { // Save a pointer to the next node. nextNode = nodePtr->next; // Delete the current node. delete nodePtr; // Position nodePtr at the next node. nodePtr = nextNode; } } cities.txt TX 1837 San Antonio CA 1850 Los Angeles TX 1856 Dallas AZ 1881 Phoenix IL 1837 Chicago PA 1701 Philadelphia OH 1834 Columbus WI 1846 Milwaukee NY 1898 New York IN 1832 Indianapolis
  • 13. MD 1797 Baltimore DC 1788 Washington FL 1822 Jacksonville TN 1826 Memphis TX 1837 Huston CA 1850 San Diego CA 1850 San Jose MI 1815 Detroit CA 1850 San Francisco MA 1822 Boston Sample output Welcome to the Linked Lists Project ___________________________________ A. Read City Data ___________________ Complete to read data ___________________ B. Print City Data ___________________ State Year City ----- ----- ---------- MD 1797 Baltimore MA 1822 Boston IL 1837 Chicago OH 1834 Columbus TX 1856 Dallas MI 1815 Detroit TX 1837 Huston IN 1832 Indianapolis
  • 14. FL 1822 Jacksonville CA 1850 Los Angeles TN 1826 Memphis WI 1846 Milwaukee NY 1898 New York PA 1701 Philadelphia AZ 1881 Phoenix TX 1837 San Antonio CA 1850 San Diego CA 1850 San Francisco CA 1850 San Jose DC 1788 Washington ___________________ C. Search City Data ___________________ Enter the city for search (QUIT for stop searching) : Baltimore State Year City ----- ----- ---------- MD 1797 Baltimore Enter the city for search (QUIT for stop searching) : Washington State Year City ----- ----- ---------- DC 1788 Washington Enter the city for search (QUIT for stop searching) : Memphis State Year City ----- ----- ---------- TN 1826 Memphis Enter the city for search (QUIT for stop searching) : Cupertino
  • 15. was not found Enter the city for search (QUIT for stop searching) : QUIT ___________________ D. Delete City Data ___________________ Enter the city for delete (QUIT for stop searching) : Baltimore State Year City ----- ----- ---------- MD 1797 Baltimore ** Delete the Baltimore** Enter the city for delete (QUIT for stop searching) : Baltimore was not found Enter the city for delete (QUIT for stop searching) : Washington State Year City ----- ----- ---------- DC 1788 Washington ** Delete the Washington** Enter the city for delete (QUIT for stop searching) : Washington was not found Enter the city for delete (QUIT for stop searching) : Cupertino was not found Enter the city for delete (QUIT for stop searching) : QUIT ______________________________________________
  • 16. Thank you for using the Linked Lists Project Solution #include #include #include #include "CityList.h" using namespace std; void welcome(); void readCityData(CityList *readList); void printCityData(CityList *printList); void searchCityData(CityList *searchList); void deleteCityData(CityList *deleteList); void goodbye(); int main() { CityList list; // WELCOME FUNCTION welcome(); // A. Read data from a text file readCityData(&list); // B. Print the list printCityData(&list); // C. Seach Function searchCityData(&list); // D. Delete Function deleteCityData(&list); // EXTRA. Check the Result (Inactive) // list.displayList();
  • 17. // GOODBYE FUNCTION goodbye(); return 0; } //**************************************************************************** * // Definition of function welcome // This function displays the welcome screen //**************************************************************************** * void welcome() { cout << "Welcome to the Linked Lists Project" << endl; cout << "___________________________________" << endl << endl; } //**************************************************************************** * // Definition of function readCityData // This function save the city list from the file to the linked list //**************************************************************************** * void readCityData(CityList *readList) { cout << endl << "A. Read City Data" << endl; cout << "___________________" << endl; Data import; ifstream infile; infile.open("cities.txt"); while(!infile) { cout << "FILE OPEN ERROR" << endl;
  • 18. exit(111); } while(infile>>import.state) { //infile >> import.state; infile >> import.year; infile.ignore(); getline(infile, import.city); // DEBUG // /* cout << import.state; cout << import.year; cout << import.city; cout << endl; */ readList->insertNode(import); } infile.close(); cout << endl << "Complete to read data" << endl; cout << "___________________" << endl; } //**************************************************************************** * // Definition of function printCityData // This function displays the city list //**************************************************************************** * void printCityData(CityList * printList) {
  • 19. cout << endl << endl << "B. Print City Data" << endl; cout << "___________________" << endl << endl; cout << left << setw(10) << "State" << setw(10) << "Year" << setw(20) << "City" << endl; cout << setw(10) << "-----" << setw(10) << "-----" << setw(20) << "----------" << endl; printList->displayList(); cout << "___________________" << endl; } //**************************************************************************** * // Definition of function searchCityData // This function search the city from the city data //**************************************************************************** * void searchCityData(CityList * searchList) { string searchCity; cout << endl << "C. Search City Data" << endl; cout << "___________________" << endl; while(searchCity!="QUIT") { cout << endl << "Enter the city for search (QUIT for stop searching) : "; getline(cin,searchCity); if(searchCity!="QUIT") { searchList->searchList(searchCity); } } cout << "___________________" << endl; }
  • 20. //**************************************************************************** * // Definition of function deleteCityData // This function delete the city from the city data //**************************************************************************** * void deleteCityData(CityList * deleteList) { string searchCity; cout << endl << endl << "D. Delete City Data" << endl; cout << "___________________" << endl; while(searchCity!="QUIT") { cout << endl << "Enter the city for delete (QUIT for stop searching) : "; getline(cin,searchCity); if(searchCity!="QUIT") { deleteList->deleteNode(searchCity); } } } //**************************************************************************** * // Definition of function goodbye // This function displays the goodbye screen //**************************************************************************** * void goodbye() { cout << endl << endl << "______________________________________________" << endl << endl;
  • 21. cout << "Thank you for using the Linked Lists Project" << endl; } CityList.h // Specification file for the CityList class #ifndef CITYLIST_H #define CITYLIST_H #include using namespace std; struct Data { string state; int year; string city; // other fields could be added here }; class CityList { private: // Declare a structure for the list struct ListNode { //double value; // The value in this node Data data; ListNode *next; // To point to the next node }; ListNode *head; // List head pointer public: // Constructor CityList() { head = NULL; } // Destructor ~CityList(); // Linked list operations void insertNode(Data); //void insertNode(double); void deleteNode(string);
  • 22. void searchList(string) const; void displayList() const; }; #endif CityList.cpp // Implementation file for the CityList class #include // For cout and NULL #include #include "CityList.h" using namespace std; //************************************************** // displayList shows the value * // stored in each node of the linked list * // pointed to by head. * //************************************************** void CityList::displayList() const { ListNode *nodePtr; // To move through the list // Position nodePtr at the head of the list. nodePtr = head; // While nodePtr points to a node, traverse // the list. while (nodePtr) { // Display the value in this node. cout << setw(10) << nodePtr->data.state; cout << setw(10) << nodePtr->data.year; cout << setw(20) << nodePtr->data.city << endl; // Move to the next node. nodePtr = nodePtr->next; } } //**************************************************
  • 23. // The insertNode function inserts a node with * // data copied to its data member. * //************************************************** void CityList::insertNode(Data dataIn) { ListNode *newNode; // A new node ListNode *nodePtr; // To traverse the list ListNode *previousNode = NULL; // The previous node // Allocate a new node and store num there. newNode = new ListNode; newNode->data.state = dataIn.state; newNode->data.year = dataIn.year; newNode->data.city = dataIn.city; // If there are no nodes in the list // make newNode the first node if (!head) { head = newNode; newNode->next = NULL; } else // Otherwise, insert newNode { // Position nodePtr at the head of list. nodePtr = head; // Initialize previousNode to NULL. previousNode = NULL; // Skip all nodes whose value is less than num. while (nodePtr != NULL && nodePtr->data.city < dataIn.city) { previousNode = nodePtr; nodePtr = nodePtr->next; } // If the new node is to be the 1st in the list, // insert it before all other nodes. if (previousNode == NULL)
  • 24. { head = newNode; newNode->next = nodePtr; } else // Otherwise insert after the previous node. { previousNode->next = newNode; newNode->next = nodePtr; } } } //************************************************** // The searchList function searches for a node * // with city as its value. The node, if found, is * // print from the list. * //************************************************** void CityList::searchList(string city) const { ListNode *nodePtr; // To move through the list // Position nodePtr at the head of the list. nodePtr = head; // While nodePtr points to a node and // whose value member is not equal to city traverse // the list. while (nodePtr != NULL && nodePtr->data.city!=city) { // Move to the next node. nodePtr = nodePtr->next; } // Display the value in this node. if(nodePtr != NULL && nodePtr->data.city==city) { cout << endl << left << setw(10) << "State" << setw(10) << "Year" << setw(20) <<
  • 25. "City" << endl; cout << setw(10) << "-----" << setw(10) << "-----" << setw(20) << "----------" << endl; cout << setw(10) << nodePtr->data.state; cout << setw(10) << nodePtr->data.year; cout << setw(20) << nodePtr->data.city << endl; } // Display error if there is no result in this node else { cout << "<" << city << ">" << " was not found" << endl; } } //************************************************** // The deleteNode function searches for a node * // with city as its value. The node, if found, is * // deleted from the list and from memory. * //************************************************** void CityList::deleteNode(string city) { ListNode *nodePtr; // To traverse the list ListNode *previousNode; // To point to the previous node // If the list is empty, do nothing. if (!head) return; // Determine if the first node is the one. //if (head->value == num) if (head->data.city == city) { cout << endl << left << setw(10) << "State" << setw(10) << "Year" << setw(20) << "City" << endl; cout << setw(10) << "-----" << setw(10) << "-----" << setw(20) << "----------" << endl; cout << setw(10) << head->data.state; cout << setw(10) << head->data.year;
  • 26. cout << setw(20) << head->data.city << endl; cout << "** Delete the " << city << " **" << endl; nodePtr = head->next; delete head; head = nodePtr; } else { // Initialize nodePtr to head of list nodePtr = head; // Skip all nodes whose value member is // not equal to city. while (nodePtr != NULL && nodePtr->data.city != city) { previousNode = nodePtr; nodePtr = nodePtr->next; } // If nodePtr is not at the end of the list, // link the previous node to the node after // nodePtr, then delete nodePtr. if (nodePtr) { cout << endl << left << setw(10) << "State" << setw(10) << "Year" << setw(20) << "City" << endl; cout << setw(10) << "-----" << setw(10) << "-----" << setw(20) << "----------" << endl; cout << setw(10) << nodePtr->data.state; cout << setw(10) << nodePtr->data.year; cout << setw(20) << nodePtr->data.city << endl; cout << "** Delete the " << city << " **" << endl; previousNode->next = nodePtr->next; delete nodePtr; } // Display error if there is no result in this node
  • 27. else { cout << "<" << city << ">" << " was not found" << endl; } } } //************************************************** // Destructor * // This function deletes every node in the list. * //************************************************** CityList::~CityList() { ListNode *nodePtr; // To traverse the list ListNode *nextNode; // To point to the next node // Position nodePtr at the head of the list. nodePtr = head; // While nodePtr is not at the end of the list... while (nodePtr != NULL) { // Save a pointer to the next node. nextNode = nodePtr->next; // Delete the current node. delete nodePtr; // Position nodePtr at the next node. nodePtr = nextNode; } } cities.txt TX 1837 San Antonio CA 1850 Los Angeles TX 1856 Dallas AZ 1881 Phoenix IL 1837 Chicago PA 1701 Philadelphia
  • 28. OH 1834 Columbus WI 1846 Milwaukee NY 1898 New York IN 1832 Indianapolis MD 1797 Baltimore DC 1788 Washington FL 1822 Jacksonville TN 1826 Memphis TX 1837 Huston CA 1850 San Diego CA 1850 San Jose MI 1815 Detroit CA 1850 San Francisco MA 1822 Boston Sample output Welcome to the Linked Lists Project ___________________________________ A. Read City Data ___________________ Complete to read data ___________________ B. Print City Data ___________________ State Year City ----- ----- ---------- MD 1797 Baltimore MA 1822 Boston IL 1837 Chicago OH 1834 Columbus
  • 29. TX 1856 Dallas MI 1815 Detroit TX 1837 Huston IN 1832 Indianapolis FL 1822 Jacksonville CA 1850 Los Angeles TN 1826 Memphis WI 1846 Milwaukee NY 1898 New York PA 1701 Philadelphia AZ 1881 Phoenix TX 1837 San Antonio CA 1850 San Diego CA 1850 San Francisco CA 1850 San Jose DC 1788 Washington ___________________ C. Search City Data ___________________ Enter the city for search (QUIT for stop searching) : Baltimore State Year City ----- ----- ---------- MD 1797 Baltimore Enter the city for search (QUIT for stop searching) : Washington State Year City ----- ----- ---------- DC 1788 Washington Enter the city for search (QUIT for stop searching) : Memphis State Year City
  • 30. ----- ----- ---------- TN 1826 Memphis Enter the city for search (QUIT for stop searching) : Cupertino was not found Enter the city for search (QUIT for stop searching) : QUIT ___________________ D. Delete City Data ___________________ Enter the city for delete (QUIT for stop searching) : Baltimore State Year City ----- ----- ---------- MD 1797 Baltimore ** Delete the Baltimore** Enter the city for delete (QUIT for stop searching) : Baltimore was not found Enter the city for delete (QUIT for stop searching) : Washington State Year City ----- ----- ---------- DC 1788 Washington ** Delete the Washington** Enter the city for delete (QUIT for stop searching) : Washington was not found Enter the city for delete (QUIT for stop searching) : Cupertino was not found
  • 31. Enter the city for delete (QUIT for stop searching) : QUIT ______________________________________________ Thank you for using the Linked Lists Project