kestutis

2 lygis | 1 pamoka| Trikampio plotas

Nov 26th, 2013
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <fstream>
  2. #include <iomanip>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. const char duom[] = "Duomenys.txt";
  7. const char rez[] = "Rezultatai.txt";
  8.  
  9. double krastines_ilgis(int x1, int y1, int x2, int y2) {
  10.     return sqrt( pow(x1-x2, 2) + pow(y1-y2, 2) );
  11. }
  12.  
  13. //Herono formulė
  14. double plotas(int x1, int y1, int x2, int y2, int x3, int y3) {
  15.     double a = krastines_ilgis(x1, y1, x2, y2);
  16.     double b = krastines_ilgis(x1, y1, x3, y3);
  17.     double c = krastines_ilgis(x2, y2, x3, y3);
  18.     double p = (a+b+c)*0.5;// Pusperimetris
  19.     return sqrt(p*(p-a)*(p-b)*(p-c));
  20. }
  21.  
  22. int main() {
  23.     int x1, y1, x2, y2, x3, y3;
  24.     ifstream in(duom);
  25.     ofstream out(rez);
  26.     while( in >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 )
  27.         out << fixed << setprecision(2) << plotas(x1, y1, x2, y2, x3, y3) << endl;  
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment