Click here to Skip to main content
15,898,990 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: template question Pin
Joaquín M López Muñoz9-Oct-03 21:08
Joaquín M López Muñoz9-Oct-03 21:08 
GeneralRe: template question Pin
Steve Messer9-Oct-03 21:11
Steve Messer9-Oct-03 21:11 
GeneralRe: template question Pin
Joaquín M López Muñoz9-Oct-03 21:23
Joaquín M López Muñoz9-Oct-03 21:23 
GeneralRe: template question Pin
Steve Messer9-Oct-03 21:30
Steve Messer9-Oct-03 21:30 
GeneralRe: template question Pin
Steve Messer9-Oct-03 21:08
Steve Messer9-Oct-03 21:08 
GeneralStrange things with parameters. Pin
esepich9-Oct-03 19:10
esepich9-Oct-03 19:10 
GeneralRe: Strange things with parameters. Pin
Anand Paranjpe9-Oct-03 19:52
Anand Paranjpe9-Oct-03 19:52 
GeneralDefine triangle class Pin
Anonymous9-Oct-03 18:40
Anonymous9-Oct-03 18:40 
Well, I am comming along more and more with this program, but I could still obviously use some help. I am going to put the specifications in full out here.

Define a class for triagnles. A triangle is defined by three sides. Class should have following capabilities:

A constructor that will allow definining a triangle. (float side1, float side2, float side3). The constructor is to call Order to place the sides in order from smallest to largest.

A constructo with no arguments: initialize the three sides to zero.

Public member functions needed.

void SetTriangle(float side1, float side2, float side3);
bool IsEquilateral();
bool IsIsosceles();
bool IsScalene();
bool IsRight();
bool IsAcute();
bool IsObtuse();
friend Triangle Copy(Triangle triangle1);
friend bool operator ==(const Triangle& triangle1, const Triangle& triangle2);
friend ostream& operator <<(ostream& outs, Triangle& the_triangle);

Private member functions needed.

void Order;
void Swap;

I need to write a program that will define triangle1, triangle2, triangle3, triangle4

am to define a class for triangles, and once I have defined it I need to do tese procedurse:

The constructor (with sides) is to call order to order the sides from smallest to largest.
and
The SetTriangle function is to call order to order the sides from smallest to largest

and then display the sides and the type it is... scalene and right, isosceles and acute, ....

I think I may need to give more detail. Triangle1 will not have any values defined. Triangle2 has sides 6.0, 6.0, 6.0. Triangle3: 5.0, 4.0, 3.0. Triangle4: 6.0, 4.0, 4.0

And then for Triangles 2, 4, and 4... I

1) Use friend operator function << to display the three sides of each

2) Test to see if the triangle is Equilateral, Isosceles, or Scalene. When one of the functions returns true, display message. Message should not be displayed within function.

3) Test to see if Right, Acute, Obtuse

For the copy test

1) Use the friend copy function to copy triangle 4 to triangle 1

2) Use friend operator function << to display the three sides of triangle 4 and triangle 1.

3)Use friend operator function == to see if triangle 1 is equal to triangle 4. If the two are, display " are equal", otherwise " are not equal.

For another == test, do the following

1)Use friend operator function << to display three sides of triangle2 and triangle3.

2)Use friend operator function ++ to see if triangle2 is equal to triangle3 and display appropriate message

For the SetTriangle test, do the following:

1)set Triangle3's sides to (5, 4, 3 (in that order))

2)use friend operator function << to disply the three sides of triangle3.

There are all the specifications and what not. It has been like a week... and I have only gotten as far as this Could I please get some help all around on this one. I would so much appreciate it. Please, could I get some help. I have done this much on my own, and now I have just gotten stuck and don't really have a clue as what to do.

My code is
#include <iostream.h><br />
#include <stdlib.h><br />
<br />
class Triangle<br />
{<br />
public:<br />
	friend Triangle Copy(Triangle triangle1);<br />
	friend bool operator ==(const Triangle& triangle1, const Triangle& triangle2);<br />
	friend ostream& operator <<(ostream& outs, Triangle& the_triangle);<br />
<br />
	Triangle(float side1, float side2, float side3);<br />
	Triangle();<br />
<br />
	void SetTriangle(float side1, float side2, float side3);<br />
<br />
	bool IsEquilateral();<br />
	bool IsIsosceles();<br />
	bool IsObtuse();<br />
<br />
	float get_side1();<br />
	float get_side2();<br />
	float get_side3();<br />
<br />
private:<br />
    void order(float side_1, float side_2, float side_3);<br />
	void swap(float side_1, float side_2);<br />
<br />
	float side_1, side_2, side_3;<br />
};<br />
<br />
void main()<br />
{<br />
	Triangle triangle1, triangle2(5.0, 4.0, 3.0), triangle3(6.0, 4.0, 4.0);<br />
	cout << "Display triangle 1:\n";<br />
	cout << "Side 1 = " << triangle1.get_side1() << endl;<br />
	cout << "Side 2 = " << triangle1.get_side2() << endl;<br />
	cout << "Side 3 = " << triangle1.get_side3() << endl;<br />
<br />
	cout << "Display triangle 2:\n";<br />
	cout << "Side 1 = " << triangle2.get_side1() << endl;<br />
	cout << "Side 2 = " << triangle2.get_side2() << endl;<br />
	cout << "Side 3 = " << triangle2.get_side3() << endl;<br />
<br />
	cout << "Display triangle 3:\n";<br />
	cout << "Side 1 = " << triangle3.get_side1() << endl;<br />
	cout << "Side 2 = " << triangle3.get_side2() << endl;<br />
	cout << "Side 3 = " << triangle3.get_side3() << endl;<br />
<br />
}<br />
<br />
<br />
Triangle Copy(Triangle triangle1)<br />
{<br />
	Triangle copy;<br />
<br />
	copy.order = triangle1;<br />
	return copy;<br />
}<br />
Triangle::Triangle(float side1, float side2, float side3)<br />
{<br />
	side_1 = side1;<br />
	side_2 = side2;<br />
	side_3 = side3;<br />
}    <br />
<br />
void swap(float side_1, float side_2)<br />
{<br />
	float temp;<br />
	temp = side_1;<br />
	side_1 = side_2;<br />
	side_2 = temp;<br />
}<br />
<br />
void order(float side_1, float side_2, float side_3)<br />
{<br />
	if (side_1 > side_2)<br />
		swap (side_1, side_2);<br />
	if (side_1 > side_3)<br />
		swap (side_1, side_3);<br />
	if (side_2 > side_3)<br />
		swap (side_2, side_3);<br />
}<br />
<br />
<br />
<br />
Triangle::Triangle() : side_1(0), side_2(0), side_3(0)<br />
{<br />
	//empty<br />
}<br />
float Triangle::get_side1()<br />
{<br />
	return side_1;<br />
}<br />
float Triangle::get_side2()<br />
{<br />
	return side_2;<br />
}<br />
float Triangle::get_side3()<br />
{<br />
	return side_3;<br />
}

GeneralRe: Define triangle class Pin
W. Hammer -sledge-11-Oct-03 9:29
W. Hammer -sledge-11-Oct-03 9:29 
GeneralHello &#213;&#226;&#202;&#199;&#202;&#178;&#195;&#180;&#209;&#189;&#163;&#191; Pin
hy_huangh9-Oct-03 18:36
hy_huangh9-Oct-03 18:36 
GeneralRe: Hello ÕâÊÇʲôѽ£¿ Pin
David Stone9-Oct-03 18:56
sitebuilderDavid Stone9-Oct-03 18:56 
GeneralFloating point calculation Pin
act_x9-Oct-03 18:20
act_x9-Oct-03 18:20 
GeneralRe: Floating point calculation Pin
Anand Paranjpe9-Oct-03 20:05
Anand Paranjpe9-Oct-03 20:05 
GeneralRe: Floating point calculation Pin
Anthony_Yio10-Oct-03 1:09
Anthony_Yio10-Oct-03 1:09 
GeneralRe: Floating point calculation Pin
JWood10-Oct-03 9:59
JWood10-Oct-03 9:59 
QuestionXML parsing with DOM?? Pin
xxhimanshu9-Oct-03 17:45
xxhimanshu9-Oct-03 17:45 
AnswerRe: XML parsing with DOM?? Pin
act_x9-Oct-03 18:28
act_x9-Oct-03 18:28 
AnswerRe: XML parsing with DOM?? Pin
Anand Paranjpe9-Oct-03 20:09
Anand Paranjpe9-Oct-03 20:09 
AnswerRe: XML parsing with DOM?? Pin
Ravi Bhavnani10-Oct-03 3:25
professionalRavi Bhavnani10-Oct-03 3:25 
Questionwhat does this mean? Pin
FlyingDancer9-Oct-03 17:34
FlyingDancer9-Oct-03 17:34 
AnswerRe: what does this mean? Pin
Anand Paranjpe9-Oct-03 20:15
Anand Paranjpe9-Oct-03 20:15 
GeneralRe: what does this mean? Pin
FlyingDancer9-Oct-03 21:26
FlyingDancer9-Oct-03 21:26 
GeneralRe: what does this mean? Pin
David Crow10-Oct-03 6:02
David Crow10-Oct-03 6:02 
GeneralRe: what does this mean? Pin
FlyingDancer12-Oct-03 3:31
FlyingDancer12-Oct-03 3:31 
GeneralMutex Objects, Semaphore Objects and Critical Section Objects Pin
FlyingDancer9-Oct-03 17:23
FlyingDancer9-Oct-03 17:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.