5.Write a program that calculates area of a triangle if coordinates of points are given. Below shown an example (values inputted by a user highlighted as bold).
Calculating area of a triangle:
Input the coordinates of angles (leave a space between points):
x1,y1 → -2 5
x2,y2 → 1 7
x3,y3 → 5 -3
Area of the triangle: 19 cm^2
Другие языки программирования и технологии
C++ write a program (дайте пожалуйста код)
#include <iostream>
#include <string>
using namespace std;
struct coord {
coord() : x(0), y (0) { }
coord(double _x, double _y) : x(_x), y (_y) { }
double x;
double y;
};
class triangle {
public:
triangle() : a(coord()), b(coord()), c(coord()) { }
triangle(coord _a, coord _b, coord _c) : a(_a), b(_b), c(_c) { }
double get_area()const { return abs((a.x - c.x) * (b.y - c.y) - (b.x - c.x) * (a.y - c.y)) / 2; }
private:
coord a, b, c;
};
void input_double(double &, string);
void create_triangle(triangle &);
int main() {
triangle tr;
create_triangle(tr);
cout << " Area = " << tr.get_area() << endl;
cin.get(); cin.get();
return 0;
}
void create_triangle(triangle & _tr) {
string coords_str[] = { "x1", "y1", "x2", "y2", "x3", "y3" };
coord coords[3];
for (int n = 0; n < 6; n++) {
string msg = " Input coord " + coords_str[n] + ": ";
if (~n & 1) input_double(coords[n >> 1].x, msg);
else input_double(coords[n >> 1].y, msg);
}
triangle temp(coords[0], coords[1], coords[2]);
_tr = temp;
}
void input_double(double & _dbl_t, string _msg) {
do {
cout << _msg;
cin >> _dbl_t;
if (cin.good()) break;
else {
cin.clear();
cin.ignore(80,'\n');
cout << "\a Error!\n";
}
} while (true);
}
#include <string>
using namespace std;
struct coord {
coord() : x(0), y (0) { }
coord(double _x, double _y) : x(_x), y (_y) { }
double x;
double y;
};
class triangle {
public:
triangle() : a(coord()), b(coord()), c(coord()) { }
triangle(coord _a, coord _b, coord _c) : a(_a), b(_b), c(_c) { }
double get_area()const { return abs((a.x - c.x) * (b.y - c.y) - (b.x - c.x) * (a.y - c.y)) / 2; }
private:
coord a, b, c;
};
void input_double(double &, string);
void create_triangle(triangle &);
int main() {
triangle tr;
create_triangle(tr);
cout << " Area = " << tr.get_area() << endl;
cin.get(); cin.get();
return 0;
}
void create_triangle(triangle & _tr) {
string coords_str[] = { "x1", "y1", "x2", "y2", "x3", "y3" };
coord coords[3];
for (int n = 0; n < 6; n++) {
string msg = " Input coord " + coords_str[n] + ": ";
if (~n & 1) input_double(coords[n >> 1].x, msg);
else input_double(coords[n >> 1].y, msg);
}
triangle temp(coords[0], coords[1], coords[2]);
_tr = temp;
}
void input_double(double & _dbl_t, string _msg) {
do {
cout << _msg;
cin >> _dbl_t;
if (cin.good()) break;
else {
cin.clear();
cin.ignore(80,'\n');
cout << "\a Error!\n";
}
} while (true);
}
#include <iostream>
using namespace std;
int main()
{
double x1,x2,x3,y1,y2,y3=0;
double S=0;
cout<<"Enter x1"<<endl;>>x1;
cout<<"Enter y1"<<endl;>>y1;
cout<<"Enter x2"<<endl;>>x2;
cout<<"Enter y2"<<endl;>>y2;
cout<<"Enter x3"<<endl;>>x3;
cout<<"Enter y3"<<endl;>>y3;
S=(0.5)*abs(((x1-x3)*(y2-y3))-((x2-x3)*(y1-y3)));
cout<<"Area of the triangle "<
using namespace std;
int main()
{
double x1,x2,x3,y1,y2,y3=0;
double S=0;
cout<<"Enter x1"<<endl;>>x1;
cout<<"Enter y1"<<endl;>>y1;
cout<<"Enter x2"<<endl;>>x2;
cout<<"Enter y2"<<endl;>>y2;
cout<<"Enter x3"<<endl;>>x3;
cout<<"Enter y3"<<endl;>>y3;
S=(0.5)*abs(((x1-x3)*(y2-y3))-((x2-x3)*(y1-y3)));
cout<<"Area of the triangle "<
Похожие вопросы
- помогите пожалуйста кто смыслит в C# или в C++, очень нужна ваша помощь, нужен код программы, точнее двух
- Найти трехзначные числа a, b, c, все цифры которых различны и удовлетворяют уравнению a^2 – b^2 – c^2 = a – b – c.
- Напишите пожалуйста код на C#
- c++ напишите решение задачи, пожалуйста (код)
- Помогите решить задачу на языке c++. Не понимаю условия в конце кода.
- C++ не работает программа посмотрите пожалуйста))
- ПОДСКАЖИТЕ ПОЖАЛУЙСТА код разблокировки баннера билайн
- Выручайте. Составьте пожалуйста код на С++. Задание по практике.
- Посмотрите пожалуйста код.
- дайте плиз код для изменения цвета текст в HTML есле можно то и с таблицей цветов :)