Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1....
- #include <iostream>
- #include <math.h>
- using namespace std;
- class odcinek{
- public:
- double x1,x2,y1,y2;
- void show(){
- cout << "wczytaj x1" <<endl;
- cin >> x1;
- cout<<"wczytaj y1"<<endl;
- cin >> y1;
- cout << "wczytaj x2" <<endl;
- cin >> x2;
- cout<<"wczytaj y2"<<endl;
- cin >> y2;
- cout<<"x1 wynosi: "<<x1<<endl;
- cout<<"y1 wynosi: "<<y1<<endl;
- cout<<"x2 wynosi: "<<x2<<endl;
- cout<<"y2 wynosi: "<<y2<<endl;
- };
- double odleglosc(){
- double odleglosc;
- odleglosc=(sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
- return odleglosc;
- };
- };
- /*class punkt{
- public:
- double x,y;
- void show(){
- cout << "wczytaj x" <<endl;
- cin >> x;
- cout<<"wczytaj y"<<endl;
- cin >> y;
- cout<<"x wynosi: "<<x<<endl;
- cout<<"y wynosi: "<<y<<endl;
- };
- void odleglosc(){
- cout<<"odleglosc miedzy punktami p1 i p2 wynosci"<<endl;
- ((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
- }
- };*/
- int main() {
- odcinek p1;
- p1.show();
- cout<<"odleglosc odcinka"<< p1.odleglosc()<<endl;
- return 0;
- }
- 2...
- #include <iostream>
- #include <math.h>
- using namespace std;
- class trojkat{
- public:
- double x1,x2,x3,y1,y2,y3;
- void wczytaj(){
- cout<< "podaj x,y pierwszego punktu"<<endl;
- cin >>x1>>y1;
- cout<< "podaj x,y drugiego punktu"<<endl;
- cin >>x2>>y2;
- cout<< "podaj x,y trzeciego punktu"<<endl;
- cin >>x3>>y3;
- cout<<"pierwszy punkt ma wspolrzedne "<< x1<<","<<y1<<endl;
- cout<<"drugi punkt ma wspolrzedne "<< x2<<","<<y2<<endl;
- cout<<"trzeci punkt ma wspolrzedne "<< x3<<","<<y3<<endl;
- }
- double obwod(){
- double a,b,c,obwod;
- a=(sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
- b=(sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1)));
- c=(sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2)));
- obwod=a+b+c;
- return obwod;
- }
- double pole(){
- double a,b,c,pole,p;
- a=(sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
- b=(sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1)));
- c=(sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2)));
- p=(a+b+c)/2.0;
- pole=sqrt((p*(p-a)*(p-b)*(p-c)));
- return pole;
- }
- };
- int main() {
- trojkat t1;
- t1.wczytaj();
- cout<<"obwod trojkata wynosi "<<t1.obwod()<<endl;
- cout<<"pole trojkata wynosi "<<t1.pole()<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement