|
-
April 18th, 2010, 10:55 PM
#6
Re: Seg Fault When Debugging
Ok, I will try to answer your statements:
1) Well we just went over inheritance, so it is a new concept. I thought that since I am using static memory, I wouldn't need to deal with destructors in this case. Does the compiler not generate one?
2) Back to point 1, new concept, didn't realize it needed to be virtual in the base clase.
3) rewardsPoints is to hold the values of 0, 500, and 1000. That's why I declared it in the derived class. Actually, I just realized what I could do, It's been changed. It no longer is declared in the derived class. I just set the value accordingly in the constructors for the derived class.
4) And, for the stack and queue, it might be the problem, but I am used to doing it like that. I've double checked everything with code from the book. Quite frankly, I wish I could use vectors, but, they don't allow that. And based off of the directions, it seems they want us to write our own stack and queue.
Edit: I am having difficulty getting the following to work:
Code:
int main()
{
ifstream infile;
infile.open("in.txt");
CheckIn Hotel;
if (infile.fail())
{
cout << "Cannot open file, program terminated." << endl;
exit(1);
}
string lineread; //holds a line from the input file
while(getline(infile, lineread))
{
string sub; //holds the individual words within lineread
stringstream ss(lineread);
while (ss >> sub)
{
//Trying to read ahead, if there is an add after done, then don't process done
if (sub == "done")
{
infile >> sub;
if (sub == "add")
{
cout << "Done error: cannot process done command." << endl;
getline(infile, lineread);
}
else
Hotel.done();
ss.str("");
ss << lineread; //line read at this point should have a customer's info
}
if (sub == "add")
{
Customer person;
string tempfirst, templast, temptype;
int tempnights;
ss >> tempfirst >> templast >> temptype >> tempnights;
Hotel.add(tempfirst, templast, temptype, tempnights);
}
}
}
return 0;
}
I want to read in the file. If I get to a done command, I want to check if there is an add command ahead of it. If so, I output an error message and ignore the done command.
Last edited by Alterah; April 19th, 2010 at 12:17 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|