Hi there,
I am doing an exercise from a c++ book, but I get few errors that I can't seem to be able to fix, and I am not quite sure why.
The exercise goes:" In a right triangle with dimensions side1, side2 and hypotenuse, find all Pythagorean triples for side1, side2 and hypotenuse no larger than 500...".
Now these are the errors I am getting in Visual C++:
Compiling...
triangle.cpp
c:\program files\microsoft visual studio 8\vc\include\sal.h(226) : error C2143: syntax error : missing ';' before 'string'
c:\program files\microsoft visual studio 8\vc\include\sal.h(226) : error C2059: syntax error : 'string'
c:\program files\microsoft visual studio 8\vc\include\sal.h(226) : error C2143: syntax error : missing ';' before '{'
c:\program files\microsoft visual studio 8\vc\include\sal.h(226) : error C2447: '{' : missing function header (old-style formal list?)
triangle_main.cpp
z:\in common folder 24_09\programming\exercises deitel and deitel\ex 5.20 p242\triangle_main.cpp(7) : error C2628: 'Triangle' followed by 'int' is illegal (did you forget a ';'?)
z:\in common folder 24_09\programming\exercises deitel and deitel\ex 5.20 p242\triangle_main.cpp(9) : error C3874: return type of 'main' should be 'int' instead of 'Triangle'
z:\in common folder 24_09\programming\exercises deitel and deitel\ex 5.20 p242\triangle_main.cpp(14) : error C2664: 'Triangle::Triangle(const Triangle &)' : cannot convert parameter 1 from 'int' to 'const Triangle &'
Reason: cannot convert from 'int' to 'const Triangle'
No constructor could take the source type, or constructor overload resolution was ambiguous
Generating Code...
Build log was saved at "file://z:\In common folder 24_09\programming\deitel and deitel programs compiled\ex_5_20\ex_5_20\Debug\BuildLog.htm"
ex_5_20 - 7 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
here are the files:
triangle.h
//exercise 5.20 Deitel and deitel pag 242
//file triangle.h
//class definition
class Triangle
{
public:
Triangle( double, double, double ) ; //constructor initializing the 3 triangle dimensions
void calculateDimensions( double, double, double ) ; //assigns dimensions
//int getTriangle( ) ; //get the value of the dimensions
void printDimensions( double, double, double ) ; //print dimensions
private:
double side1 ;
double side2 ;
double hypotenuse ;
}
triangle.cpp:
//exercise 5.20 Deitel and deitel pag 242
//file: triangle.cpp
//member function definition
#include "triangle.h"
#include <iostream>
using namespace std ;
#include <cmath> //for the power function
// constants in the program
const int EXPONENT = 2 ;
const char N = '\n' ;
/*the constructors initialize the values of the sides to 1 and pass them to the
calculateDimensions functions */
Triangle::Triangle( double Side1, double Side2, double Hypot )
{
calculateDimensions( Side1, Side2, Hypot ) ;
}
//set the 3 dimensions and calculates the Pythagorean triple
void Triangle::calculateDimensions( double Side1, double Side2, double Hypot )
{
side1 = Side1 ;
side2 = Side2 ;
hypotenuse = Hypot ;
//int i = 0 ; //for the iteration in the for loop
for ( int i = 1 ; i <= 500 ; i++ )
{
side1 = i ;
for ( int j = 1 ; j <= 500 ; j++ )
{
side2 = j ;
for ( int k = 1 ; k <= 500 ; k++ )
{
hypotenuse = k ;
if( ( pow( side1 , EXPONENT ) ) + ( pow( side2 , EXPONENT ) ) == ( pow ( hypotenuse , EXPONENT ) ) )
{
printDimensions( side1, side2, hypotenuse ) ;
}
}
}
}
}
void Triangle::printDimensions( double side1, double side2, double hypotenuse )
{
cout << "( " << side1 << " , " << side2 << " , " << hypotenuse << " ) " << endl ;
}
and triangle_main.cpp
//exercise 5.20 Deitel and deitel pag 242
//file: triangle_main.cpp
//file containing main function
#include "triangle.h" //include definition of class triangle
int main( )
{
Triangle rightTriangle( 1.0 , 1.0 , 1.0 ) ; //create Triangle object
return 0 ;
}
Any suggestion?
thanks