Другие языки программирования и технологии

C++ структуры и функции

Есть один треугольник заданный координатами вершин
задача: с клавы вводится точка, проверить треугольник на наличие в нем этой точки.

мой вариант в консоли

// lab.2 N2.cpp : main project file.

#include "stdafx.h"
#include "stdio.h"
#include "conio.h"
#include "math.h"
using namespace System;

int main(float Ax, float Ay, float Bx, float By, float Cx, float Cy)
{
struct vector{float x,y;}KA,KB,KC,AB,AC;
float Kx,Ky;
float Stringle(vector a,vector b);
{
float s;
s=((sqrt((a.x*b.y-b.x*a.y)(a.x*b.y-b.x*a.y)))/2);
return s;
}
printf("Введите X:");scanf("%f",&Kx);
printf("\nВведите y:");scanf("%f",&Ky);
KA.x=Ax-Kx;
KA.y=Ay-Ky;
KB.x=Bx-Kx;
KB.y=By-Ky;
KC.x=Cx-Kx;
KC.y=Cy-Ky;
AB.x=Bx-Ax;
AB.y=By-Ay;
AC.x=Cx-Ax;
AC.y=Cy-Ay;
if (Stringle(AB,AC)==Stringle(KA,KB)+Stringle(KB,KC)+Stringle(KC,KA)) printf("Входит");
else printf("Не входит");
getch();
}

Внимание вопрос:
1> lab.2 N2.cpp
1>lab.2 N2.cpp(17): error C2065: 'a' : undeclared identifier
1>lab.2 N2.cpp(17): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>lab.2 N2.cpp(17): error C2065: 'b' : undeclared identifier
1>lab.2 N2.cpp(17): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>lab.2 N2.cpp(17): error C2065: 'b' : undeclared identifier
1>lab.2 N2.cpp(17): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>lab.2 N2.cpp(17): error C2065: 'a' : undeclared identifier
1>lab.2 N2.cpp(17): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>lab.2 N2.cpp(17): error C2065: 'a' : undeclared identifier
1>lab.2 N2.cpp(17): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>lab.2 N2.cpp(17): error C2065: 'b' : undeclared identifier
1>lab.2 N2.cpp(17): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>lab.2 N2.cpp(17): error C2065: 'b' : undeclared identifier
1>lab.2 N2.cpp(17): error C2228: left of '.x' must have class/struct/union
1> type is ''unknown-type''
1>lab.2 N2.cpp(17): error C2065: 'a' : undeclared identifier
1>lab.2 N2.cpp(17): error C2228: left of '.y' must have class/struct/union
1> type is ''unknown-type''
1>lab.2 N2.cpp(18): warning C4244: 'return' : conversion from 'float' to 'int', possible loss of data
1>
1>Build FAILED.

ЧЯДНТ?
Алёшка Love Mi
Алёшка Love Mi
161
#include <iostream>
using namespace std;
struct Triangle {
double x1; double y1;
double x2; double y2;
double x3; double y3;
double areaTriangle();
};
double party(double, double, double, double);
double area(double, double, double);
void accessory(double[], double);
int main() {
Triangle copy;
locale::global(locale(""));
cout << endl << " Координаты вершин треугольника: " << endl << endl;
cout << " Введите x1: "; cin >> copy.x1;
cout << " Введите y1: "; cin >> copy.y1;
cout << " Введите x2: "; cin >> copy.x2;
cout << " Введите y2: "; cin >> copy.y2;
cout << " Введите x3: "; cin >> copy.x3;
cout << " Введите y3: "; cin >> copy.y3;
cout << endl << " Координаты точки: " << endl << endl;
double s = copy.areaTriangle();
double eps = 1e-12;
if (s < eps) cout << endl << "\a Треугольник не существует! ";
else {
double x, y;
cout << " Введите x: "; cin >> x;
cout << " Введите y: "; cin >> y;
double arr[] = { copy.x1, copy.y1, copy.x2, copy.y2, copy.x3, copy.y3, x, y };
accessory(arr, s);
}
cin.get(); cin.get();
return 0;
}
void accessory(double _arr[8], double _s) {
double a = party(_arr[0], _arr[1], _arr[2], _arr[3]);
double b = party(_arr[2], _arr[3], _arr[4], _arr[5]);
double c = party(_arr[0], _arr[1], _arr[4], _arr[5]);
double da = party(_arr[0], _arr[1], _arr[6], _arr[7]);
double db = party(_arr[2], _arr[3], _arr[6], _arr[7]);
double dc = party(_arr[4], _arr[5], _arr[6], _arr[7]);
double summa = area(a, da, db) + area(b, db, dc) + area(c, da, dc);
if (summa - _s < 1e-12) cout << endl << " Точка лежит внутри треугольника. ";
else cout << endl << " Точка лежит вне треугольника. ";
}
double Triangle::areaTriangle() {
double a = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
double b = sqrt(pow(x3 - x2, 2) + pow(y3 - y2, 2));
double c = sqrt(pow(x1 - x3, 2) + pow(y1 - y3, 2));
double p = (a + b + c) / 2;
return sqrt(p * (p - a) * (p - b) * (p - c));
}
double party(double _x1, double _y1, double _x2, double _y2) {
return sqrt(pow(_x2 - _x1, 2) + pow(_y2 - _y1, 2));
}
double area(double _a, double _b, double _c) {
double _p = (_a + _b + _c) / 2;
return sqrt(_p * (_p - _a) * (_p - _b) * (_p - _c));
}
Влад Фролов
Влад Фролов
81 336
Лучший ответ
Простите, но - это пиздеееееец!
Bahytzhan Amandykov
Bahytzhan Amandykov
11 082
))))))))))))))))
1) Выучи синтаксис C++
2) float Stringle(vector a,vector b); как минимум проблема в точке с запятой. Скобки за "функцией" принадлежат уже main, и в этой области видимости нет таких переменных
я тупая и не увидела, что ты не так делаешь. . пойду поем