4)
triangle.h
#include<math.h>
class Triangle{
private:
float x1,y1; //A
float x2,y2; //B
float x3,y3; //C
public:
//Default constructor
Triangle(){
}
//-----------------------
//Parameterized constructor
Triangle(float x1,float y1,float x2,float y2,float x3,float
y3){
this->x1=x1;
this->y1=y1;
this->x2=x2;
this->y2=y2;
this->x3=x3;
this->y3=y3;
}
//-----------------------
//initialize the coordinates
void setValue(float x1,float y1,float x2,float y2,float x3,float
y3){
this->x1=x1;
this->y1=y1;
this->x2=x2;
this->y2=y2;
this->x3=x3;
this->y3=y3;
}
//----------------------------
//destructor
~Triangle(){
delete(this); //delete the object
}
//-----------------------
//finds the perimeter of the triangle
float perimeter(){
float AB;
float AC;
float BC;
float P;
//length of each three sides of the triangle
AB=sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
AC=sqrt((x3-x1)*(x3-x1) + (y3-y1)*(y3-y1));
BC=sqrt((x3-x2)*(x3-x2) + (y3-y2)*(y3-y2));
P=AB+AC+BC;
return P;
}
//------------------------------------
//find the area of the circle
float area(){
float AB;
float AC;
float BC;
float S;
float A;
//length of each three sides of the triangle
AB=sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
AC=sqrt((x3-x1)*(x3-x1) + (y3-y1)*(y3-y1));
BC=sqrt((x3-x2)*(x3-x2) + (y3-y2)*(y3-y2));
//Heron's formula to find the area of the triangle
S=(AB+AC+BC)/2;
A=sqrt(S*(S-AB)*(S-AC)*(S-BC));
return A;
}
};
//---------------------------------------------
triangle.cpp
#include<iostream>
#include "triangle.h"
using namespace std;
int main(){
Triangle *T=new Triangle(3,5,12,30,50,67);
cout<<"\nArea of the triangle= "<<T->area()<<"
unit square"<<endl;
cout<<"Perimeter of the triangle=
"<<T->perimeter()<<"
unit"<<endl<<endl;
return 0;
}
//-----------------------------
OUTOUT:

number 4 in c++ please square method not mentioned no sauare method was given. can thus...
C++ please
27. How do you differentiate a destructor from the rest? 28. Can a static function call an instance one? 29. Can an instance function call a static one? 30. How many objects are created? class Account { public: string firstName; string lastName; double balance; Account* p; 31. Discuss the differences among the following access modifiers, public, private, and protected. 32. When do you use the following notation? . (dot notation) :: (scope resolution operator) -> (arrow notation) 33....
Design a general class GeometricObject can be used to model all geometric objects. This class contains the properties color and filled and their appropriate get and set methods. Assume that this class also contains toString() methods. The toString() method returns a string representation of the object. Define the Triangle, Circle, and Rectangle classes that extend the GeometricObject class. The Triangle class inherits all accessible data fields and methods from the GeometricObject class.In addition, it has three double data fields named...
C++
Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the class point that should have the following Private data members x and y (of type int), with default values of 0 A constant ID of type int A private static integer data member named numOfPoints This data member should be o Incremented whenever a new point object is created. o Decremented whenever a point object is destructed. A default constructor An...
This exercise guides you through the process of converting an Area and Perimeter application from a procedural application to an object-oriented application. Create and use an object 1. Open the project named ch04_ex2_Area and Perimeter that’s stored in the ex_starts folder. Then, review the code for the Main class. 2. Create a class named Rectangle and store it in the murach.rectangle package. 3. In the Rectangle class, add instance variables for length and width. The, code the get and set...
please write the code in
C++
2 Base class File 3 Derived class PDF 3.1 Class declaration • The class PDF inherits from File and is a non-abstract class 1. Hence objects of the class PDF can be instantiated. 2. To do so, we must override the pure virtual function clone) in the base class • The class declaration is given below. • The complete class declaration is given below, copy and paste it into your file. . It is...
Q2) Interface Create a program that calculates the perimeter and the area of any given 2D shape. The program should dynamically assign the appropriate calculation for the given shape. The type of shapes are the following: • Quadrilateral 0 Square . Perimeter: 4xL • Area:LXL O Rectangle • Perimeter: 2(L+W) • Area:LxW Circle Circumference: I x Diameter (TT = 3.14) Area: (TT xD')/4 Triangle (assume right triangle) o Perimeter: a+b+c O Area: 0.5 x base x height (hint: the base...
Create a C++ console program that defines a class named EvenNumber that represents an even number. Create the class inside a separate header file (.h) and then include this header in your main source code file. The class should have one private integer data field to store the even number. The default constructor should initialize the data field to 0. Also define a 1-arg constructor that initializes the object with the specified value. Define a public getter method named getValue...
Write a C++ console program that defines a class named Course that utilizes a dynamically allocated array. Do not use the vector class for this assignment. The Course class should define private data members for the name of the course, the number of students in the course, an array of student names (string*), and the capacity of the course (the array may not be full of students). Use pointer notation when dealing with the array. A 2-arg constructor should initialize...
Please help with a source code for C++ and also need screenshot of output: Step 1: Create a Glasses class using a separate header file and implementation file. Add the following attributes. Color (string data type) Prescription (float data type) Create a default constructor that sets default attributes. Color should be set to unknown because it is not given. Prescription should be set to 0.0 because it is not given. Create a parameterized constructor that sets the attributes to the...