• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can't find my error  RSS feed

 
Ryan Mat
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry if this is a bad question for posting.. but I'm confused as to where I'm going wrong. The assignment is to read in different shapes from a text file and put them in a linked list.

I put here the two classes in the program that I think are relevant. The issue I'm having is that the program seems to be reading each shape in twice, so for example when I print the list I am somehow adding two of each shape rather than one. I have figured out that I can add an extra line of code somewhere, for example in the getShape() method in the Input class I can add another call of readInput(); and it will only add one of each shape to the linked list. Similarly in the ShapeDriver constructor while loop I can say i.getShape(); and it will also add each shape only once. I feel like these aren't really solutions to my error, though, just coverups.

I'm just not seeing why it seems to be reading and adding each shape twice.

In case it helps the input text file looks something like this

Circle
4.0
Square
2.2
2.2
2.2
2.2
Rectangle
3.0
2.0
3.0
2.0




 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here are a few hints...

What happens when readInput() encounters an error condition? Does it report anything? Or does it ignore it?

What happens to getShape() when readInout() returns? Does it return the actual value from readInput? Even when readInput() encounters an error?

Henry

 
Ryan Mat
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response.

As far as readInput() encountering errors, it's been stated in the assignment requirements that that won't happen. I.E. there will always be the correct number of sides for each shape. In the event that a side has length zero or less than zero, that error is handled in the individual shape's class.

getShape() just calls readInput(), and readInput() simply stores the new shape it creates in the protected _shape object. That _shape object is then returned when getShape() is called.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!