1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
// Aqeel Abbas LW1 week5.cpp : Defines the entry point for the console application.
//
#include <cstdlib>
#include <iostream>
#include <conio.h>
using namespace std;
struct rectinfo
{
int height,width,area,perimeter;
}R1,*R2;
void dynamic (rectinfo* );
void genData (rectinfo*,int );
void calAreaPer (rectinfo* ,int );
void display (rectinfo* ,int );
int main()
{
R2=&R1;
dynamic(R2);
getch();
return 0;
}
void dynamic(rectinfo* R)
{
int n;
cout<<"how many structures of type rectinfo you want to declare ?? "<<endl;
cin>>n;
rectinfo* shape=new rectinfo[n];// this defines an array of shape[n] of rectinfo data type.
genData (shape,n);
calAreaPer (shape,n);
display (shape,n);
}
void genData (rectinfo* R,int n)
{
int a;
for(int i=0; i<n; i++)
{
(R->height[i]=(rand()%21));
(R->width[i]=(rand()%21));
}
}
void calAreaPer (rectinfo* A,int n)
{
for(int i=0; i<n; i++)
{
A->area[i]= (A->height*A->width);
A->perimeter[i]=2*(A->height + A->width);
}
}
void display (rectinfo* B,int n)
{
for(int i=0; i<n; i++)
{
cout<<"Randomnly generated value of height is "<<B->height[i]<<endl;
cout<<"Randomnly generated value of width is "<<B->width[i]<<endl;
cout<<"Area of rectangle is :"<<B->area[i]<<endl;
cout<<"Perimeter of rectangle is :"<<B->perimeter[i]<<endl;
}
}
|