Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is my code contian 3 files and they are : triangle.h: triangle.cpp, and main.cpp I need to draw the triangle, I did make points

Here is my code contian 3 files and they are : triangle.h: triangle.cpp, and main.cpp

I need to draw the triangle, I did make points like (1,5)(5,10) , but I could not make the shape of tringle. please I need help in that

#ifndef Triangle_h // prevents multible inclusion of the header file

#define Triangle_h

#include "iostream"

#include "string"

using namespace std;

// create a triangle class

class Triangle

{

//create the priavte variables

private:

int x1;

int x2;

int y1;

int y2;

string TrigName;

public:

Triangle();// constructor

void setx1(int xa);

int getx1();

void setx2(int xb);

int getx2();

void sety1(int ya);

int gety1();

void sety2(int yb);

int gety2();

void setTrigName(string trigName);

string getTrigName();

void printTrigName();

double peramter();

double printarea();

void variable();

void draw();

};

#endif

------------------------------------------------------------------------

#include"triangle.h"

#include"iomanip"

Triangle::Triangle()

{

x1 = 0;

x2 = 0;

y1 = 0;

y2 = 0;

TrigName;

}

void Triangle::setx1(int xa)

{

x1 = xa;

}

int Triangle::getx1()

{

return x1;

}

void Triangle::setx2(int xb)

{

x2 = xb;

}

int Triangle::getx2()

{

return x2;

}

void Triangle::sety1(int ya)

{

y1 = ya;

}

int Triangle::gety1()

{

return y1;

}

void Triangle::sety2(int yb)

{

y2 = yb;

}

int Triangle::gety2()

{

return y2;

}

void Triangle::setTrigName(string trigName)

{

TrigName = trigName;

}

string Triangle::getTrigName()

{

return TrigName;

}

void Triangle::printTrigName()

{

cout << " Name of tringle name is:" << " " << TrigName << endl;

}

double Triangle::peramter()

{

double y = sqrt(pow(getx2() - getx1(), 2) + pow(gety2() - gety1(), 2)) + ((getx2() - getx1()) + (gety2() - gety1()));

cout << " The perimeter is:" << "[ " << y << " ]" << endl;

return y;

}

double Triangle::printarea()

{

double x = (((getx2() - getx1()) * (gety2() - gety1())))*0.5;

cout << " The area of trig is: " << "[" << x << " ]" << endl;

return x;

}

void Triangle::variable()

{

cout << " The varibale that you used for trig: " << "x1= " << x1 << " , " << "x2= " << x2 << " , " << "y1= " << y1 << " , " << "y2= " << y2 << " . " << endl;

}

void Triangle::draw()

{

int count =20;

for (size_t row = count; row > 0; row--) {

cout << row << setw(3);

for (size_t col = 1; col < count; col++) {

if ((col >= x1 && col <= x2 && row >= y1 && row <= y2))

{

cout << " *" << setw(3);

}

else

{

cout << "-" << setw(3);

}

}

cout << ' ';

}

for (size_t i = 0; i < count; i++) {

cout << i << setw(3);

}

}

---------------------------------------------------------------------------------

// main function main.cpp

#include"triangle.h"

#include "Date.h"

#include"ctime"

#include"iomanip"

int main();

int menu();

int main()

{

int xa, xb, ya, yb; int choice;

int month, day, year;

string trigName;

Triangle trigObj;

Date dateObj;

choice = menu();

// create a while loop between 1 and 6

while ((choice >= 1) && (choice <= 8))

{

// if the user entered 1 it will ask to enter the coordante

if (choice == 1)

{

cout << " Enter the coordante:";

cin >> xa >> xb >> ya >> yb;

// if the first variable bigger than the second variable for x's, it will show a message

if (xb

{

cout << " Wrong!!!... The first coordante should be less than the second coordante for x's " << endl;

}

// if the first variable bigger than the second variable for y's, it will show a message

if (yb

{

cout << " Wrong!!!... The first coordante should be less than the second coordante for y's " << endl;

}

// if the first variable less than second variable, it will show a message that tringle accepted

else if ((xb > xa) && (yb > ya))

{

cout << " Triangle accepted" << endl;

}

trigObj.setx1(xa);

trigObj.setx2(xb);

trigObj.sety1(ya);

trigObj.sety2(yb);

//dateObj.setMonth(month);

//dateObj.setDay(day);

//dateObj.setYear(year);

}

//if the user choice 2 it will ask the user to enter the name of the trig

else if (choice == 2)

{

cout << " The tringle name is: ";

cin >> trigName;

trigObj.setTrigName(trigName);

}

// if the user enter 3 it will show the peramter

else if (choice == 3)

{

trigObj.peramter();

}

// if the user entred 4 it will show the area of the trig

else if (choice == 4)

{

trigObj.printarea();

}

// if the user choice 5 it will show the trig info

else if (choice == 5)

{

trigObj.variable();

trigObj.printTrigName();

trigObj.peramter();

trigObj.printarea();

cout << " The date is: " << dateObj.getMonth() << " / " << dateObj.getDay() << " / " << dateObj.getYear() << endl;

}

else if (choice == 6)

{

cout << " Enter the month : " << endl;

cin >> month;

dateObj.setMonth(month);

cout << " Enter the Day: " << endl;

cin >> day;

dateObj.setDay(day);

cout << " Enter the Year: " << endl;

cin >> year;

dateObj.setYear(year);

}

else if (choice == 7)

{

trigObj.draw();

}

// if the user choice 6 it will exite the program

else if (choice == 8)

{

exit(1);

}

choice = menu();

}

}

// create the menu function

int menu()

{

// declare the choice1

int choice1;

// write the menu

cout << " 1. Enter the cordinates for the triangle. " << endl;

cout << " 2. Enter the name of the Tringle: " << endl;

cout << " 3. Enter the peramter of the Tringle: " << endl;

cout << " 4. Enter the area of the Tringle: " << endl;

cout << " 5. Print the info for the trig " << endl;

cout << " 6. Enter the date:" << endl;

cout << " 7. Disply the graph of the trig: " << endl;

cout << " 8. Exit......" << endl;

cout << " What would you like to choice: ";

cin >> choice1;

return choice1;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

Students also viewed these Databases questions

Question

=+Who should be recruited?

Answered: 1 week ago

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago