Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please i need help!!! I need a DeleteStae function added to the following code,

ID: 3823517 • Letter: P

Question

please i need help!!! I need a DeleteStae function added to the following code, If you could please Bold print the Added code so i know what to add.

#include<iostream>
#include<string>
#include<fstream>
#include <iomanip>
#include <cassert>
using namespace std;
class StateData
{
private:
string myStateName;
string myStateCap;
int myStateUNum;
int myStateJYear;
int myStateAra;
public:
StateData(string myName1 = " ", string capN1 = " ", int uNum1 = 0, int yrN1 = 0, int areaN1 = 0)
{
myStateName = myName1;
myStateCap = capN1;
myStateUNum = uNum1;
myStateJYear = yrN1;
myStateAra = areaN1;
}
string getMyStateName()
{
return myStateName;
}
void setMyStateName(string n)
{
myStateName = n;
}
string getMyStateCap()
{
return myStateCap;
}
void setMyStateCap(string c)
{
myStateCap = c;
}
int getMyStateUNum()
{
return myStateUNum;
}
void setMyStateUNum(int n)
{
myStateUNum = n;
}
int getMyStateJYear()
{
return myStateJYear;
}
void setMyStateJYear(int y)
{
myStateJYear = y;
}
int getMyStateArea()
{
return myStateAra;
}
void setArea(int aa)
{
myStateAra = aa;
}
friend ostream& operator<<(ostream& myOut, StateData& myStateInfo)
{
if (myStateInfo.getMyStateArea() > 0)
{
myOut << myStateInfo.getMyStateName() << " , ";
myOut << myStateInfo.getMyStateCap() << " , ";
myOut << myStateInfo.getMyStateJYear() << ", ";
myOut << myStateInfo.getMyStateUNum() << " , ";
myOut << myStateInfo.getMyStateArea();
}
return myOut;
}
friend istream& operator>>(istream& myIn, StateData& myStateInfo)
{
getline(myIn, myStateInfo.myStateName);
getline(myIn, myStateInfo.myStateCap);
myIn >> myStateInfo.myStateAra >> myStateInfo.myStateJYear >> myStateInfo.myStateUNum;
char myChh;
myIn.get(myChh);
return myIn;
}

StateData& operator=(const StateData& otherStateInfo)
{
myStateName = otherStateInfo.myStateName;
myStateCap = otherStateInfo.myStateCap;
myStateUNum = otherStateInfo.myStateUNum;
myStateJYear = otherStateInfo.myStateJYear;
myStateAra = otherStateInfo.myStateAra;
return *this;
}
//operators overloading
bool operator!=(const StateData& otherStateInfo) const
{
return myStateName != otherStateInfo.myStateName;
}
bool operator==(const StateData& otherStateInfo) const
{
return myStateName == otherStateInfo.myStateName;
}
bool operator>(const StateData& otherStateInfo) const
{
return myStateName > otherStateInfo.myStateName;
}
bool operator>=(const StateData& otherStateInfo) const
{
return myStateName >= otherStateInfo.myStateName;
}
bool operator<(const StateData& otherStateInfo) const
{
return myStateName < otherStateInfo.myStateName;
}
bool operator<=(const StateData& otherStateInfo) const
{
return myStateName <= otherStateInfo.myStateName;
}

};
template <class infoType>
class STATEHASHTABLE
{
private:
infoType *MYHASHTABLE;
int *itemStatus;
int myHashLen;
int myTableSize;
public:
STATEHASHTABLE(int myHashSze= 101)
{
MYHASHTABLE = new infoType[myHashSze];
itemStatus = new int[myHashSze];
for (int kk = 0; kk < myHashSze; kk++) {
itemStatus[kk] = 0;
myTableSize = myHashSze;
myHashLen = 0;
}
}
~STATEHASHTABLE()
{
delete[] MYHASHTABLE;
delete[] itemStatus;
}
int hashFunc(string myStateName);
void displayMystateHashTable() const;
void InsertMyState(int myHashIndx, const infoType& myStateRec);
void getMyState(int myHashIndx, infoType& myStateRec) const;
void searchState(int& myHashIndx, string stateName, bool& myItemFound) const;
bool checkStates(int myHashIndx, const infoType& myStateRec) const;
void clearMyStateInfo(int myHashIndx, const infoType& myStateRec);
};
template <class infoType>
int STATEHASHTABLE<infoType>::hashFunc(string myStateName)
{
int aa, myHSum;
int len;
aa = 0;
myHSum = 0;
len = myStateName.length();
for (int k = 0; k < 15 - len; k++)
myStateName = myStateName + ' ';
for (int k = 0; k < 5; k++)
{
myHSum = myHSum + static_cast<int>(myStateName[aa]) * 128 * 128 + static_cast<int>(myStateName[aa + 1]) * 128 + static_cast<int>(myStateName[aa + 2]);
aa = aa + 3;
}
return myHSum % myTableSize;
}
template <class infoType>
void STATEHASHTABLE<infoType>::InsertMyState(int myHashIndx, const infoType& myStateRec)
{
int incCntt=1;
int myInc=1;
while(itemStatus[myHashIndx] == 1 && incCntt < myTableSize / 2)
{
myHashIndx = (myHashIndx + myInc ) % myTableSize;
myInc = myInc + 2;
incCntt++;
}
if(itemStatus[myHashIndx] != 1)
{
MYHASHTABLE[myHashIndx] = myStateRec;
itemStatus[myHashIndx] = 1;
myHashLen++;
}
else
{
if(MYHASHTABLE[myHashIndx] == myStateRec)
cout<<"Already present"<<endl;
else
cout<<"HASH TABLE FULL"<<endl;
}
}
template <class infoType>
void STATEHASHTABLE<infoType>::searchState(int& myHashIndx, string stateName, bool& myItemFound) const
{
int incCntt=1;
int myInc=1;
while (itemStatus[myHashIndx] != 0 && incCntt < myTableSize / 2)
{
if (MYHASHTABLE[myHashIndx].getMyStateName().compare(stateName) == 0 && itemStatus[myHashIndx] == 1) {
cout<<MYHASHTABLE[myHashIndx]<<endl;
myItemFound = true;
break;
}
myHashIndx = (myHashIndx + myInc) % myTableSize;
incCntt++;
myInc = myInc + 2;
}
}
template <class infoType>
bool STATEHASHTABLE<infoType>::checkStates(int myHashIndx, const infoType& myStateRec) const
{
if (itemStatus[myHashIndx] != 1) {
cout << "EMPTY!" << endl;
return false;
}
return MYHASHTABLE[myHashIndx] == myStateRec;
}
template <class infoType>
void STATEHASHTABLE<infoType>::getMyState(int myHashIndx, infoType& myStateRec) const
{
if (itemStatus[myHashIndx] != 1) {
cout << "EMPTY!" << endl;
}
else
myStateRec = MYHASHTABLE[myHashIndx];
}
template <class infoType>
void STATEHASHTABLE<infoType>::clearMyStateInfo(int myHashIndx, const infoType& myStateRec)
{
bool myItemFound;
searchState(myHashIndx, myStateRec, myItemFound);
if (myItemFound) {
itemStatus[myHashIndx] = -1;
myHashLen--;
}
else
cout << "EMPTY." << endl;
}
template <class infoType>
void STATEHASHTABLE<infoType>::displayMystateHashTable() const
{
for (int kk = 0; kk < myTableSize-1; kk++) {
if (itemStatus[kk] == 1) {
cout << MYHASHTABLE[kk] << endl;
}
}
}
int main()
{
STATEHASHTABLE<StateData> myHashTable(100);
ifstream fID1("Kyles_State_Data.txt");
if(fID1.is_open())
{
StateData myState;
while(fID1)
{
fID1>>myState;
int myIndx=myHashTable.hashFunc(myState.getMyStateName());
myHashTable.InsertMyState(myIndx, myState);
}

string stateName;
cout<<"Enter myStateName to look into the hash table"<< endl;
cout<<"(Please use Capital letter for first letter of the state)"<< endl;
cout<<"State Name = ";
cin>>stateName;
int myIndx=myHashTable.hashFunc(stateName);
bool myItemFound=false;
cout<<"StateName--Capital--JoinYear--StateNum--Area"<< endl<< endl;
myHashTable.searchState(myIndx, stateName, myItemFound) ;
if(!myItemFound)
cout<<"Item not Found."<<endl;

}
//system("pause");
return 0;
}

Explanation / Answer


template <class infoType>
void STATEHASHTABLE<infoType>::DeleteMyState(int& myHashIndx, const string stateName)
{
   int myHashIndx = hashFunc(stateName);
   int incCntt=1;
   int myInc=1;
   while(itemStatus[myHashIndx] != 0 && incCntt < myTableSize / 2)
   {
       if(MYHASHTABLE[myHashIndx].getMyStateName().compare(stateName) == 0 && itemStatus[myHashIndx] == 1) {
           itemStatus[myHashIndx] = 0;
           return;
       }
       myHashIndx = (myHashIndx + myInc) % myTableSize;
       myInc = myInc + 2;
       incCntt++;
   }
}