I made a class called triangle for my programming hw!
In the header file that contains this class and some fuctions, there is a function called vector<triangle> findRightTriangle that gets two int as parameters! This function has to return a vector containing three int!
what i want to know is since the return value of this function is vector<triangle>, is the vector have to contain the member variables of triangle class??
vector<triangle> findRightTriangles(unsignedlong l, unsignedlong h)
there is a function like this!!
It has to return a vector that has three integers!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
class triangle {
public:
// member functions:
// constructor:
triangle(unsignedlong a=3, unsignedlong b=4, unsignedlong c=5):
s1(a),s2(b),s3(c) {}
unsignedlong perimeter();
unsignedlong area();
void print(); // prints to standard output
// member variables:
// integers for the 3 sides:
unsignedlong s1;
unsignedlong s2;
unsignedlong s3;
};
vector<triangle> findRightTriangles(unsignedlong l, unsignedlong h);
bool congruent(triangle t1, triangle t2);
bool similar(triangle t1, triangle t2);
this is the class in the header file!!
so I am trying to make function in other cpp file!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
vector<triangle> findRightTriangles(unsignedlong l, unsignedlong h) {
triangle t1;
t1.s1=l;
t1.s3=h;
t1.s2;
for (unsignedlong p = 0; p < t1.s3; p++) {
t1.s2=p;
if ( p >= t1.s1 && p <= t1.s3 && (((t1.s1*t1.s1)+(p*p)) == (t1.s3*t1.s3))){
retval.push_back(t1.s1);
retval.push_back(t1.s2);
retval.push_back(t1.s3);
break;
}
}
return retval;
}
so in this function I made an triangle object t1.
and assign the values l and h into s1 and s3 which are the member variables in triangle class!!
In the for loop, find the appropriate value for s2 and push_back these three values and break the loop!!
and return the vector!!
there is an error!! T.,T