# Thread: CS201: Introduction to Programming Assignment 6 Deadline 30 July 2010

1. ## CS201: Introduction to Programming Assignment 6 Deadline 30 July 2010

Problem Statement: Calculate Area of Triangle of two objects of same class using setfill(), setw() and setprecision() manipulators.
• You are required to write a class. Class should have area, base and height private data members (real numbers).
Class should have
• A default constructor which will initialize all data members with values 2.5 and 2.5 for base and height.
• Getter and setter functions
You are required to create two objects of the same class.
You must assign values of first object through setter functions.
You should have a CalaulateArea method, which will calculate area of
the triangle for both objects.
The formula of Area of triangle = base x height / 2
 You should have a Display (public) method for displaying area after
calculation. Display method should also show input values at screen.
 You should use setfill() and setw() manipulators for both objects. You can use it in Display method. You should use * as parameter in setfill().

For 2nd object;
 User will input for 2nd object and input values should be set for this object.
 Setprecision will be used for 2nd object and parameter will be 1.

-------------------------------------------------------------------------
Sample output:

Area of Triangle
----------------
Object1
Input:******************base = 2.5 , Height = 2.5
Area of Object 1:*******3.125

Object2
Input:******************base = 2.5 , Height = 2.5
Area of Object 2:*******3.1

2. yar ap yah solution last date sa pahla nah da sakta last date ko hi kiun data han pahla post karna ka faida phir

3. Solution to hai mere pass per us mein thori gar bar hai

4. ## cs201 sloution required

cs201 6th assignment solution required

5. Originally Posted by wahabawq
Solution to hai mere pass per us mein thori gar bar hai
you post it here. I will remove bugs.

6. Originally Posted by Xpert
you post it here. I will remove bugs.
me too here to remove the bugs INSHALLAH

7. ## Idea Solution

Code:
```#include <iostream>
using namespace std;
#include <conio.h>
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(){this->height=this->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(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();
coutsetw(40)"Area of Triangle"endlsetw(40)setfill(-);
cout"object1\n";
object1.areafinder();
object1.display(1);
cout"object2\n";
object2.areafinder();
object2.display(2);
coutendl;
system("Pause");
return 0;
}```

8. Ok done! but kindly change it before submitting.

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;
}```
I will fix it for you. Anyone can send me code for fixation but it should contain some serious effort.