07-31-2010, 08:29 AM
Ok done! but kindly change it before submitting.
I will fix it for you. Anyone can send me code for fixation but it should contain some serious effort.
Code:
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <iomanip.h>
using namespace std;
int a=1;
class Triangle
{
private:
float area, height, base;
public:
Triangle();
void setF();
void areafinder(){
this->area=(this->base*this->height/2);
}
void display(int);
};
Triangle::Triangle()
{
height=2.5;
base=2.5;
}
void Triangle::setF()
{
cout << "Please enter the value of the Base: ";
cin>>base;
cout << "Please enter the value of the Height: ";
cin>>height;
}
void Triangle::display(int a)
{
if(a==1)
{
cout << "input : " << setfill('*') << setw(20) << " base : " << base << " , " << " Height : " << height;
cout << "Area of Object 1:" << setfill('*') << setw(11) << area;
}
else{
cout << "input:" << setfill('*') << setw(20) << " base : " << base << " , "" Height : " << height;
cout << "Area of Object 2:" << setfill('*') << setw(11) << setprecision(1) << area;
}
}
main(){
Triangle object1, object2;
object2.setF();
cout << setw(40) << "Area of Triangle" << endl << setw(40) << setfill('-');
cout << "object1\n";
object1.areafinder();
object1.display(1);
cout << endl;
cout << "object2\n";
object2.areafinder();
object2.display(2);
cout << endl;
system("Pause");
return 0;
}
