In: Computer Science
In c++, Can anyone make these code int user input as user have to put all the amount.
int main()
{
Polygon p1(3,4,4.5,5.5);
Polygon p2(4,4,5.5,6.5);
Polygon p3(5,4,6.5,7.5);
cout<<"Area of
Polygon#1:"<<p1.getArea()<<endl;
cout<<"Perimeter of
Polygon#1:"<<p1.getPerimeter()<<endl;
cout<<"\nArea of
Polygon#2:"<<p2.getArea()<<endl;
cout<<"Perimeter of
Polygon#2:"<<p2.getPerimeter()<<endl;
cout<<"\nArea of
Polygon#3:"<<p3.getArea()<<endl;
cout<<"Perimeter of
Polygon#3:"<<p3.getPerimeter()<<endl;
return 0;
}
Dear student, I have modified the code according to
your requirements.
Please upvote if you are satisfied with the answer.
Please do comment below if you have any doubts
thanks.
int main()
{
float a,b,c,d,e,f,g,h,i,j,k,l;
cout<<"Enter the values for Plogon 1: ";
cin>>a>>b>>c>>d;
cout<<"Enter the values for Plogon 2: ";
cin>>e>>f>>g>>h;
cout<<"Enter the values for Plogon 3: ";
cin>>i>>j>>k>>l;
Polygon p1(a,b,c,d);
Polygon p2(e,f,g,h);
Polygon p3(i,j,k,l);
cout<<"Area of
Polygon#1:"<<p1.getArea()<<endl;
cout<<"Perimeter of
Polygon#1:"<<p1.getPerimeter()<<endl;
cout<<"\nArea of
Polygon#2:"<<p2.getArea()<<endl;
cout<<"Perimeter of
Polygon#2:"<<p2.getPerimeter()<<endl;
cout<<"\nArea of
Polygon#3:"<<p3.getArea()<<endl;
cout<<"Perimeter of
Polygon#3:"<<p3.getPerimeter()<<endl;
return 0;
}