Write a program that defines an array of 25 right Triang pointers, and then use Malloc to allocate 25 rightTriangle objects who pointters are then assigned to each of the 25 array elements. NOw, make each triangle a mulitple of a 3-4-5 triangle. The first triangle should have l=3, w=4, h=5. Each succeeding triangle should have dimensions a factor of two bigger than the last one.. Set the colors all the same. Now write a loop that will print each Triangle's description to the screen.
ok that is the problem i'm having. This is what i've came up with.. I'm having the most trouble with Malloc.
Header file is this.
and my main.cpp fileCode:#include <iostream> using namespace std; typedef struct { int l, w, h; char color[10]; } rightTriangle;
Please help meCode:#include "prob2.h" void main() { int i; rightTriangle triangle[25]; triangle[0].l = 3; triangle[0].w = 4; triangle[0].h = 5; for (i=1; i<25; i++) { triangle[i].l = triangle[i - 1].l * 2; triangle[i].w = triangle[i - 1].w * 2; triangle[i].h = triangle[i - 1].h * 2; } for (i=0; i<25; i++) { cout << i << " l: " << triangle[i].l << " w: " << triangle[i].w << " h: " << triangle[i].h << endl; } }



LinkBack URL
About LinkBacks


