Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function correctly tells if object is a circle, triangle, or rect.

Status
Not open for further replies.

hunternjb

Programmer
Mar 21, 2001
7
0
0
US
I am learning C++ from a book called Teach Yourself C++ and I want to write a function which takes a file as
input, assumes that the file has only one of the below
objects drawn into it, and correctly tells whether the object is a rectangle, circle or triangle, filled or hollow. I am having trouble on where to start. If someone could help me with this I would gratly appreciate it. Here are some examples of objects that would be in the file.


* * * * *
* * * *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* * * *
* * * * *

*
**
* *
* *
* *
* *
* *
********
 
Read the first line of the file (I suppose they explain that in your book), if there is a W in your first line,
its a rectangle,if there is only one * its a triangle,and
it there are more ,it must be a circle.

Then to see if it is filled or hollow,you must read the
second line and check if there are spaces in there,if yes it is hollow and if not its filled.

Is this what you mean ?
Greetz,

The Muppeteer.

themuppeteer@hotmail.com

Don't eat yellow snow...
 
Muppeteer,

Considering the square, circle, or rectangle can be made with any char value, how do I build the function. So lets say the objects looked like this:

* * * * *
* * * *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* * * *
* * * * *
*****
*****
*****
*****
*****

*
**
* *
* *
* *
* *
* *
********

 
Ok,so lets not look at the char value then,
triangles can be easy checked if there is only on char on the first line,is that ok?
So you only have to find if it is a rectangle or a cicle.
For a rectangle,all the lines are equal.
You do it like this:

Are all the lines equal?
yes->it is a rectangle
no ->is there one char on the first line ?
yes->it is a triangle
no ->it is a circle

Better ? X-)
Greetz,

The Muppeteer.

themuppeteer@hotmail.com

Don't eat yellow snow...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top