Zdravím potreboval bych jen jesli by jste kdyztak poradili jestli by se tam dalo neco ulehcit nebo pozmenit. Program sam o sobe dela presne to co ma ale asi to mam moc slozite nejak nevim jak to zlepsi… Hlavne tohle je pro tri argumenty a mam jich mit pro 20 a uz ted je to nehorazne dlouhe… Diky moc
Jo a nikdy jsem nedelal s argumenty takze nevim jestli je to dobre, ale zatim to funguje.
#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, char *argv[])
{
int x1, x2, x3;
int y1, y2, y3;
int AB, BC;
float delka;
int SV = 0; //Kvadranty jsou urceny podle zemepisneho smeru
int JV = 0;
int JZ = 0;
int SZ = 0;
int uzavreni;
if(argc < 2)
{
cout << "Program akceptuje jeden parametr 2-20!";
cin.get();
}
else if(argc == 2) //Pro 2 body
{
cout << "Zadejte souradnice 1. bodu" << endl;
cout << "x = ";
cin >> x1;
cout << "y = ";
cin >> y1;
cout << "Zadejte souradnice 2. bodu" << endl;
cout << "x = ";
cin >> x2;
cout << "y = ";
cin >> y2;
AB = ((x2 - x1)*(x2 - x1)+(y2 - y1)*(y2 - y1));
delka = sqrt(AB);
if((x1 > 0)&&(y1 > 0))
SV++;
else if((x1 > 0)&&(y1 < 0))
JV++;
else if((x1 < 0)&&(y1 < 0))
JZ++;
else if((x1 < 0)&&(y1 > 0))
SZ++;
if((x2 > 0)&&(y2 > 0))
SV++;
else if((x2 > 0)&&(y2 < 0))
JV++;
else if((x2 < 0)&&(y2 < 0))
JZ++;
else if((x2 < 0)&&(y2 > 0))
SZ++;
if((x1 == x2)&&(y1 == y2))
uzavreni = 1;
else
uzavreni = 0;
cout << "*Delka lomene cary dane body je " << delka << endl;
cout << "*Pocet bodu v kvadrantech (++, +-, --, -+)";
cout << " " << SV;
cout << " " << JV;
cout << " " << JZ;
cout << " " << SZ << endl;
if(uzavreni == 1)
{
cout << "*Lomena cara je uzavrena" << endl;
cin.get();
cin.get();
}
else if(uzavreni == 0)
{
cout << "*Lomena cara neni uzavrena" << endl;
cin.get();
cin.get();
}
}
else if(argc == 3) // Pro 3 body
{
cout << "Zadejte souradnice 1. bodu" << endl;
cout << "x = ";
cin >> x1;
cout << "y = ";
cin >> y1;
cout << "Zadejte souradnice 2. bodu" << endl;
cout << "x = ";
cin >> x2;
cout << "y = ";
cin >> y2;
cout << "Zadejte souradnice 3. bodu" << endl;
cout << "x = ";
cin >> x3;
cout << "y = ";
cin >> y3;
AB = ((x2 - x1)*(x2 - x1)+(y2 - y1)*(y2 - y1));
BC = ((x3 - x2)*(x3 - x2)+(y3 - y2)*(y3 - y2));
delka = sqrt(AB) + sqrt(BC);
if((x1 > 0)&&(y1 > 0))
SV++;
else if((x1 > 0)&&(y1 < 0))
JV++;
else if((x1 < 0)&&(y1 < 0))
JZ++;
else if((x1 < 0)&&(y1 > 0))
SZ++;
if((x2 > 0)&&(y2 > 0))
SV++;
else if((x2 > 0)&&(y2 < 0))
JV++;
else if((x2 < 0)&&(y2 < 0))
JZ++;
else if((x2 < 0)&&(y2 > 0))
SZ++;
if((x3 > 0)&&(y3 > 0))
SV++;
else if((x3 > 0)&&(y3 < 0))
JV++;
else if((x3 < 0)&&(y3 < 0))
JZ++;
else if((x3 < 0)&&(y3 > 0))
SZ++;
if((x1 == x3)&&(y1 == y3))
uzavreni = 1;
else
uzavreni = 0;
cout << "*Delka lomene cary dane body je " << delka << endl;
cout << "*Pocet bodu v kvadrantech (++, +-, --, -+)";
cout << " " << SV;
cout << " " << JV;
cout << " " << JZ;
cout << " " << SZ << endl;
if(uzavreni == 1)
{
cout << "*Lomena cara je uzavrena" << endl;
cin.get();
cin.get();
}
else if(uzavreni == 0)
{
cout << "*Lomena cara neni uzavrena" << endl;
cin.get();
cin.get();
}
}
}