Can someone help me please? I've got 17 errors and 3 warnings. The main problem is that it keeps telling me that "Triangle" isn't a class name :confused: i'm so confused. Could you also help me with any other problems that you see? Thx in advance. (list of errors at bottom)

#include <iostream.h>

class Triangle
{
public:
	friend Triangle Copy(Triangle triangle1);
	friend bool operator ==(const Triangle& triangle1, const Triangle& triangle2);
	friend ostream& operator <<(ostream& outs, Triangle& the_triangle);

	Triangle(float side1, float side2, float side3);
	Triangle();

	void SetTriangle(float side1, float side2, float side3);

	bool IsEquilateral();
	bool IsIsosceles();
	bool IsScalene();

	bool IsRight();
	bool IsAcute();
	bool IsObtuse();	
	
	float get_side1();
	float get_side2();
	float get_side3();

private:
	void swap(float& side_1, float& side_2);
	void order();
	float side_1, side_2, side_3;
};

void main()
{
	Triangle triangle1, triangle2(6.0, 6.0, 6.0), triangle3(5.0, 4.0, 3.0), triangle4(6.0, 4.0. 4.0);
	cout << "display triangle 2: \n";

}

Triangle::Triangle(float side1, float side2, float side3)
{
	SetTriangle(side1, side2, side3);
	order();
}

Triangle::Triangle()
{
	side_1 = 0;
	side_2 = 0;
	side_3 = 0;
}

void Triangle::SetTriangle(float side1, float side2, float side3)
{
	side_1 = side1;
	side_2 = side2;
	side_3 = side3;
	order ();
}

void Triangle::swap(float& side_1, float& side_2)
{
	float temp = side_1;
	side_1 = side_2;
	side_2 = temp;
}

void Triangle::order()
{
if (side_1 > side_2)
	swap (side_1, side_2);
if (side_1 > side_3)
	swap (side_1, side_3);
if (side_2 > side_3)
	swap (side_2, side_3);
}

float Triangle::get_side1()
{
	return side_1;
}
float Triangle::get_side2()
{
	return side_2;
}
float Triangle::get_side3()
{
	return side_3;
}

Triangle
friend bool operator ==(const Triangle& Triangle1, const Triangle& Triangle2)
{
	return((Triangle1.get_side1() == Triangle2.get_side1()) && (Triangle1.get_side2() == Triangle2.get_side2()) && (Triangle1.get_side3() == Triangle2.get_side3()));
}

Triangle
friend Triangle::ostream& operator <<(ostream& outs, Triangle& the_triangle)
{
	return(outs << the_triangle.get_side1() << the_triangle.get_side2() << the_triangle.get_side3());
}

bool Triangle::IsEquilateral()
{
	return((side_1 == side_2) && (side_2 == side_3));
}

bool Triangle::IsIsosceles()
{
	if ((side_1 == side_2) && (side_2 == side_3))
		return(false);
	if((side_1 == side_2) && (side_1 != side_3) && (side_2 != side_3))
		return(true);
	if((side_2 == side_3) && (side_2 != side_1) && (side_3 != side_1))
		return(true);
	if((side_1 == side_3) && (side_1 != side_2) && (side_3 != side_2))
		return(true);
}

bool Triangle::IsScalene()
{
	return(side_1 != side_2 && side_2 != side_3 && side_1 != side_3);
}

bool Triangle::IsRight()
{
	return(side_3 * side_3 == side_1 * side_1 + side_2 * side_2);
}
bool Triangle::IsAcute()
{
	return(side_1 + side_2 < side_3);
} 
bool Triangle::IsObtuse()
{
	return (side_3 * side_3 > side_1 * side_1 + side_2 * side_2);
}

C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(36) : error C2059: syntax error : 'constant'
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(37) : error C2228: left of '.cout' must have class/struct/union type
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(37) : error C2297: '<<' : illegal, right operand has type 'char [22]'
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(41) : error C2653: 'Triangle' : is not a class or namespace name
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(45) : warning C4508: 'Triangle' : function should return a value; 'void' return type assumed
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(47) : error C2653: 'Triangle' : is not a class or namespace name
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(52) : warning C4508: 'Triangle' : function should return a value; 'void' return type assumed
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(54) : error C2653: 'Triangle' : is not a class or namespace name
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(55) : error C2373: 'SetTriangle' : redefinition; different type modifiers
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(62) : error C2653: 'Triangle' : is not a class or namespace name
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(64) : warning C4244: 'initializing' : conversion from 'int' to 'float', possible loss of data
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(69) : error C2653: 'Triangle' : is not a class or namespace name
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(70) : error C2373: 'order' : redefinition; different type modifiers
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(79) : error C2653: 'Triangle' : is not a class or namespace name
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(83) : error C2653: 'Triangle' : is not a class or namespace name
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(87) : error C2653: 'Triangle' : is not a class or namespace name
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(93) : error C2144: syntax error : missing ';' before type 'int'
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(93) : error C2501: 'Triangle' : missing storage-class or type specifiers
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(93) : error C2373: 'Triangle' : redefinition; different type modifiers
C:\Documents and Settings\owner\My Documents\C++\lab7\lab7.cpp(93) : fatal error C1004: unexpected end of file found

Member Avatar for Siersan

Compare this with what you have:

#include <iostream>

using namespace std;

class Triangle
{
public:
  friend Triangle Copy(Triangle triangle1);
  friend bool operator ==(const Triangle& triangle1, const Triangle& triangle2);
  friend ostream& operator <<(ostream& outs, Triangle& the_triangle);

  Triangle(float side1, float side2, float side3);
  Triangle();

  void SetTriangle(float side1, float side2, float side3);

  bool IsEquilateral();
  bool IsIsosceles();
  bool IsScalene();

  bool IsRight();
  bool IsAcute();
  bool IsObtuse();	

  float get_side1() const;
  float get_side2() const;
  float get_side3() const;

private:
  void swap(float& side_1, float& side_2);
  void order();
  float side_1, side_2, side_3;
};

int main()
{
  Triangle triangle1, triangle2(6.0, 6.0, 6.0), triangle3(5.0, 4.0, 3.0), triangle4(6.0, 4.0, 4.0);
  cout << "display triangle 2: \n";

}

Triangle::Triangle(float side1, float side2, float side3)
{
  SetTriangle(side1, side2, side3);
  order();
}

Triangle::Triangle()
{
  side_1 = 0;
  side_2 = 0;
  side_3 = 0;
}

void Triangle::SetTriangle(float side1, float side2, float side3)
{
  side_1 = side1;
  side_2 = side2;
  side_3 = side3;
  order ();
}

void Triangle::swap(float& side_1, float& side_2)
{
  float temp = side_1;
  side_1 = side_2;
  side_2 = temp;
}

void Triangle::order()
{
  if (side_1 > side_2)
    swap (side_1, side_2);
  if (side_1 > side_3)
    swap (side_1, side_3);
  if (side_2 > side_3)
    swap (side_2, side_3);
}

float Triangle::get_side1() const
{
  return side_1;
}
float Triangle::get_side2() const
{
  return side_2;
}
float Triangle::get_side3() const
{
  return side_3;
}

bool operator ==(const Triangle& Triangle1, const Triangle& Triangle2)
{
  return((Triangle1.get_side1() == Triangle2.get_side1()) && (Triangle1.get_side2() == Triangle2.get_side2()) && (Triangle1.get_side3() == Triangle2.get_side3()));
}

ostream& operator <<(ostream& outs, Triangle& the_triangle)
{
  return(outs << the_triangle.get_side1() << the_triangle.get_side2() << the_triangle.get_side3());
}

bool Triangle::IsEquilateral()
{
  return((side_1 == side_2) && (side_2 == side_3));
}

bool Triangle::IsIsosceles()
{
  if ((side_1 == side_2) && (side_2 == side_3))
    return(false);
  if((side_1 == side_2) && (side_1 != side_3) && (side_2 != side_3))
    return(true);
  if((side_2 == side_3) && (side_2 != side_1) && (side_3 != side_1))
    return(true);
  if((side_1 == side_3) && (side_1 != side_2) && (side_3 != side_2))
    return(true);
  return false;
}

bool Triangle::IsScalene()
{
  return(side_1 != side_2 && side_2 != side_3 && side_1 != side_3);
}

bool Triangle::IsRight()
{
  return(side_3 * side_3 == side_1 * side_1 + side_2 * side_2);
}
bool Triangle::IsAcute()
{
  return(side_1 + side_2 < side_3);
} 
bool Triangle::IsObtuse()
{
  return (side_3 * side_3 > side_1 * side_1 + side_2 * side_2);
}

But be sure to check all of the line numbers that your compiler is giving you errors on and try to guess what I changed to fix it. :)

i see that you made the get_side functions constant, which helps with one of the problems, but what does the error mean when it says "error C2653: 'Triangle' : is not a class or namespace name"?

Member Avatar for Siersan

Compare the operator== and operator<< functions between your version and mine. Therein lies the problem. Both Triange and friend should be removed from the front of the function tags, and Triangle is not the namespace that ostream is declared in.

okay, yea i see that. but im still getting 14 errors :( *i feel so stupid right now* im so lost... :confused: i even tried your version of it ..

Member Avatar for Siersan

Post the errors. Most likely we're using incompatible compilers where stuff like new headers and namespaces work for me but not for you.

OMG! thank you so much! it worked. i just re-compiled it again and it was fine. i dont know why it was showing errors a few minutes ago :/ (now i just have to finish writing the code in main) could i pm you later if i have another question/problem come up?

Member Avatar for Siersan

Sure, but be warned that I'm very busy during work hours, so I may not get to your question until tomorrow evening if I miss it tonight.

thats fine. i dont think i will work on it more until tomorrow anyways. thanks again for all of your help :)

i've gotten rid of all of the errors and completed everything in my program except now i cant figure out how to get my "friend Triangle Copy(Triangle triangle1);" function to work correctly. It is supposed to copy one object into another. Could someone please help me?

thx in advance
heres the code i have now:

#include <iostream.h>
#include<stdlib.h>

class Triangle
{
public:
  Triangle(float side1, float side2, float side3);
  Triangle();

  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:
  void swap(float& side_1, float& side_2);
  void order();
  float side_1, side_2, side_3;
};

void main()
{
	//test1 
	Triangle triangle1, triangle2(6.0, 6.0, 6.0), triangle3(5.0, 4.0, 3.0), triangle4(6.0, 4.0, 4.0);
	cout << "display triangle 2:\n" << triangle2 << "display triangle 3:\n" << triangle3 << "display triangle 4:\n" << triangle4;
	
	//test2(copy test)
	Triangle Copy(Triangle triangle1);
	cout << "\n\ndisplay triangle 1:\n" << triangle1 << "display triangle 4:\n" << triangle4;
	if(triangle1 == triangle4)
		cout << "are equal\n\n";
	else
		cout << "are not equal\n\n";
	
	//test3(== test)
	cout << "\ndisplay triangle 2:\n" << triangle2 << "display triangle 3:\n" << triangle3;
	if (triangle2 == triangle3)
		cout << "are equal\n\n";
	else
		cout << "are not equal\n\n";
	
	//test4(set triangle test) 
	triangle3.SetTriangle(5,4,3);
	cout << "\ndisplay triangle 3: \n" << triangle3;

}

Triangle::Triangle(float side1, float side2, float side3)
{
  SetTriangle(side1, side2, side3);
  order();
}

Triangle::Triangle()
{
  side_1 = 0;
  side_2 = 0;
  side_3 = 0;
}

void Triangle::SetTriangle(float side1, float side2, float side3)
{
  side_1 = side1;
  side_2 = side2;
  side_3 = side3;
  order ();
}

bool Triangle::IsEquilateral()
{
  return((side_1 == side_2) && (side_2 == side_3));
}

bool Triangle::IsIsosceles()
{
  if ((side_1 == side_2) && (side_2 == side_3))
    return(false);
  if((side_1 == side_2) && (side_1 != side_3) && (side_2 != side_3))
    return(true);
  if((side_2 == side_3) && (side_2 != side_1) && (side_3 != side_1))
    return(true);
  if((side_1 == side_3) && (side_1 != side_2) && (side_3 != side_2))
    return(true);
	return(false);
}

bool Triangle::IsScalene()
{
  return(side_1 != side_2 && side_2 != side_3 && side_1 != side_3);
}

bool Triangle::IsRight()
{
	
	return(side_3 * side_3 == side_1 * side_1 + side_2 * side_2);
	
}
bool Triangle::IsAcute()
{
	
	return(side_3 * side_3 < side_1 * side_1 + side_2 * side_2);
	  
} 
bool Triangle::IsObtuse()
{
	
	return(side_3 * side_3 > side_1 * side_1 + side_2 * side_2);
	
}

/*Triangle Copy(Triangle triangle1)
{
	Triangle  triangle4(6.0, 4.0, 4.0);
	triangle1 = triangle4;
	return(triangle1);	
}*/

bool operator ==(const Triangle& Triangle1, const Triangle& Triangle2)
{
  return((Triangle1.side_1 == Triangle2.side_1) && (Triangle1.side_2 == Triangle2.side_2) && (Triangle1.side_3 == Triangle2.side_3));
}

ostream& operator <<(ostream& outs, Triangle& the_triangle)
{
	outs << "Side1 = " << the_triangle.side_1 << "\nSide2= " << the_triangle.side_2 << "\nSide3 = " << the_triangle.side_3;
	if(the_triangle.IsEquilateral())
		 outs << "\nIs Equilateral\n";
	else if(the_triangle.IsIsosceles())
		 outs << "\nIs Isosceles\n";
	else if(the_triangle.IsScalene())
		 outs << "\nIs Scalene\n";
	
	if(the_triangle.IsRight())
		outs << "Is Right\n";
	else if(the_triangle.IsAcute())
		outs << "Is Acute\n";
	else if(the_triangle.IsObtuse())
		outs << "Is Obtuse\n";
	return(outs << "------------------\n");
	
}

void Triangle::swap(float& side_1, float& side_2)
{
  float temp = side_1;
  side_1 = side_2;
  side_2 = temp;
}

void Triangle::order()
{
  if (side_1 > side_2)
    swap (side_1, side_2);
  if (side_1 > side_3)
    swap (side_1, side_3);
  if (side_2 > side_3)
    swap (side_2, side_3);
}
Member Avatar for Siersan

Try:

Triangle Copy(Triangle t)
{
  return Triangle(t.side_1, t.side_2, t.side_3);
}

thx for all your help :) i finally figured it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.