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

struct rectInfo
{
int hight;
int width;
int area;
int parimeter;
void print()
{


cout<<hight<<"		"<<width<<"		"<<area<<"		"<<parimeter<<endl;
}

};

void calArea(rectInfo *p,int n){
for(int i=0;i<n;i++){
	 p[i].area=p[i].hight*p[i].width;
	 p[i].parimeter=2*(p[i].hight +p[i].width);

}
}
void genData(rectInfo *p,int n)
{for(int i=0;i<n;i++){
int a=rand()%10;
int b=rand()%10;
p[i].hight=a;
p[i].width=b;
}

}
int main()
{int *y;
y=new int(2);
int n=20;
rectInfo *shape=new rectInfo[n];
genData(shape,n );
calArea(shape,n );
//shape[0].print();
cout<<"Hight"<<" 		Width"<<"		Area"<<"		Parimeter"<<endl;
for(int i=0;i<n;i++){
shape[i].print();
}
return 0;

}

Edited 5 Years Ago by Ezzaral: Fixed code tags

struct rectInfo
{
int hight;
int width;
int area;
int parimeter;
};
void print(rectInfo r)
{
cout<<r.hight<<"	 "<<r.width<<"	 "<<r.area<<"	 "<<r.parimeter<<endl;
}

Structure doesn't have functions

This question has already been answered. Start a new discussion instead.