Question: I keep getting the following error and can't find what is wrong Here is the code... #include #include #include #include using namespace std; //head_to_val() method

I keep getting the following error and can't find what is wrong

I keep getting the following error and can't find what is wrong

Here is the code...

#include #include #include #include

using namespace std;

//head_to_val() method assigns an integer value to cards with different heads int head_to_val(char c) { if(c=='C') return 1; else if (c=='D') return 2; else if (c=='H') return 3; else if (c=='S') return 4; }

//tag_to_val() method assigns an integer value to card of every denomination with a head set int tag_to_val(char c) { if(c=='2') return 1; else if (c=='3') return 2; else if (c=='4') return 3; else if (c=='5') return 4; else if (c=='6') return 5; else if (c=='7') return 6; else if (c=='8') return 7; else if (c=='9') return 8; else if (c=='M') return 9; //I have used M for 10 else if (c=='J') return 10; else if (c=='Q') return 11; else if (c=='K') return 12; else if (c=='A') return 13; }

//cmp method compares between two cards bool cmp(string s1,string s2) { if(head_to_val(s1[0])==head_to_val(s2[0])) { return tag_to_val(s1[1])

class list { //listarr stores strings present in the list //dynamic array of size 20 string* listarr;

// n keeps count of total no. of elements in te listarr int n;

public: list() { n=0; // Part1 : To Create a list by dynamic allocated array and set the size to 20 listarr= new string[20];

// Initialize every string in list by a space" " for(int i=0;i

void PutItem(string s); void GetItem(string s); void DeleteItem(string s); void Display() { for(int i=0;i

continue;

}

cout

//PutItem() method insert string(card) s into sorted Poker cards list. void list::PutItem(string s) { if(listarr[0]==" ") { listarr[0]=s; } else { int i=0;

while(cmp(listarr[i],s) && listarr[i]!=" ") { i++; } if(listarr[i]==" ") { listarr[i]=s; } else { for(int j=18;j>=i;j--) listarr[j+1] = listarr[j];

listarr[i] = s; } }

n += 1; }

//DeleteItem() method deletes string(card) s into sorted Poker cards list. void list::DeleteItem(string s) { if(listarr[0]==" ") { return; } else { int i=0;

while(listarr[i]!=s && i

if(listarr[i] == s) { for(int j=i;j

n-=1; } else { cout

//GetItem() method finds string(card) s in the sorted Poker cards list.

void list::GetItem(string s) { if(listarr[0]==" ") { cout

while(listarr[i]!=s && i

if(listarr[i] == s) { cout

int main() { ifstream fobj; fobj.open("DataFile.txt"); int cnt = 0;

if(!fobj.good()) { cout

//Part2 : Read the first 20 cards in the first line of the file, the put them one by one into the list by using PutItem() int i = 0;

while( ss.good() && i

if(substr[1]=='1' && substr[2]=='0') { substr[1] = 'M'; substr[2] = '\0'; }

l.PutItem(substr); i++; }

l.Display();

//Part3 : delete the cards indicated in the second line of the file by using DeleteItem getline(fobj,str);

stringstream ss1(str);

i = 0;

while( ss1.good() && i

if(substr[1]=='1' && substr[2]=='0') { substr[1] = 'M';

substr[2] = '\0'; }

l.DeleteItem(substr); i++; }

l.Display();

//Part4 : put the items in the third line in to the list. Must use PutItem() getline(fobj,str); stringstream ss2(str);

i = 0;

while( ss2.good() && i

getline( ss2, substr, ',' );

if(substr[1]=='1' && substr[2]=='0') { substr[1] = 'M'; substr[2] = '\0'; }

l.PutItem(substr); i++;

}

l.Display(); //Part5 : Search the current list for the elements in the list getline(fobj,str);

stringstream ss3(str);

i = 0;

while( ss3.good() && i

l.GetItem(substr); i++; }

cout

return 0; }

Item D5 not present! Item HK not present! Item D2 not present! C2,C4,C8,?9 , CJ , CQ, D2,05,08,D10,DJ,00,DK , H3 , Hjhj , HK,57,SM terminate called after throwing an instance of std::logic_error what): basic_string::_M_construct null not valid This application has requested the Runtime to terminate it in an unusual way, Please contact the application's support team for more information

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!