Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Zad1
- #include<iostream>
- #include<fstream>
- using namespace std;
- struct Student
- {
- string imie;
- string nazwisko;
- unsigned numer;
- };
- struct Studenci
- {
- unsigned ile;
- Student * studenci;
- };
- Student wczytaj(istream& in)
- {
- Student student;
- in>>student.imie;
- in>>student.nazwisko;
- in>>student.numer;
- return student;
- }
- void wczytajs(Studenci& lista,istream& in)
- {
- in>>lista.ile;
- lista.studenci = new Student[lista.ile];
- for(unsigned i=0;i<lista.ile;i++)
- lista.studenci[i] = wczytaj(in);
- }
- void wypisz(Studenci lista,ostream& out = cout)
- {
- out<<lista.ile<<"\n";
- for(unsigned i=0;i<lista.ile;i++)
- {
- out<<lista.studenci[i].imie<<" ";
- out<<lista.studenci[i].nazwisko<<" ";
- out<<lista.studenci[i].numer<<"\n";
- }
- }
- void wypisz(Studenci lista,unsigned ktory, ostream& out = cout)
- {
- out<<lista.studenci[ktory-1].imie<<" ";
- out<<lista.studenci[ktory-1].nazwisko<<" ";
- out<<lista.studenci[ktory-1].numer<<"\n";
- }
- void edytuj(Studenci lista,unsigned ktory)
- {
- cout<<"Imie: ";
- cin>>lista.studenci[ktory-1].imie;
- cout<<"Nazwisko: ";
- cin>>lista.studenci[ktory-1].nazwisko;
- cout<<"Indeks: ";
- cin>>lista.studenci[ktory-1].numer;
- }
- int main(int ile, char*dane[])
- {
- ifstream txtin("in1.txt");
- ofstream txtout("out1.txt");
- Studenci listaS;
- wczytajs(listaS,txtin);
- unsigned n=1,t=0;
- while(n!=0)
- {
- cout<<"[1] Wyswietl wszystkie\n";
- cout<<"[2] Wyswietl konkretne\n";
- cout<<"[3] Edytuj konkretne\n";
- cout<<"[4] Zapisz\n";
- cout<<"[0] Zamknij\n";
- cout<<"Podaj nr: ";
- cin>>n;
- switch(n)
- {
- case 1:
- wypisz(listaS);
- break;
- case 2:
- cout<<"Podaj nr studenta: ";
- cin>>t;
- if(t>=listaS.ile)
- {
- cout<<"Bledny nr studenta\n";
- break;
- }
- wypisz(listaS,t);
- break;
- case 3:
- cout<<"Podaj nr studenta: ";
- cin>>t;
- if(t>=listaS.ile)
- {
- cout<<"Bledny nr studenta\n";
- break;
- }
- edytuj(listaS,t);
- break;
- case 4:
- wypisz(listaS,txtout);
- break;
- case 0:
- n=0;
- break;
- default:
- cout<<"Bledny numer\n";
- }
- cout<<endl;
- }
- delete [] listaS.studenci;
- txtout.close();
- txtin.close();
- return 0;
- }
- Zad2
- #include<iostream>
- using namespace std;
- class punkt
- {
- private:
- float _x,_y,_z;
- public:
- float& x()
- {
- return _x;
- }
- float& y()
- {
- return _y;
- }
- float& z()
- {
- return _z;
- }
- const float& x() const
- {
- return _x;
- }
- const float& y() const
- {
- return _y;
- }
- const float& z() const
- {
- return _z;
- }
- punkt()
- {
- _x=0;
- _y=0;
- _z=0;
- }
- punkt(float a, float b, float c)
- {
- _x=a;
- _y=b;
- _z=c;
- }
- };
- /*
- class prostokat
- {
- private:
- float _a,_b;
- punkt _p;
- public:
- prostokat()
- {
- _a=0;
- _b=0;
- _p.x() = 0;
- }
- };*/
- int main(int ile,char*dane[])
- {
- //...
- punkt p1, p2(1,2,3);
- const punkt p3(1.1,2.2,3.3);
- cout << p3.x() << '\t' << p3.y() << '\t' << p3.z() << endl;
- p1.x()=1; p1.y()=10; p1.x()=100;
- cout << p1.x() << '\t' << p1.y() << '\t' << p1.z() << endl;
- //...
- return 0;
- }
- Zad3
- #include<iostream>
- #include<cmath>
- using namespace std;
- class punkt
- {
- private:
- float _x,_y;
- public:
- punkt()
- {
- _x=0;
- _y=0;
- }
- punkt(float a, float b)
- {
- _x=a;
- _y=b;
- }
- float& x()
- {
- return _x;
- }
- float& y()
- {
- return _y;
- }
- float odleglosc(punkt p)
- {
- return sqrt(pow(_x-p.x(),2)+pow(_y-p.y(),2));
- }
- };
- class wielobok
- {
- private:
- punkt *tab;
- int n;
- public:
- wielobok(punkt * p,punkt * k)
- {
- n = k - p;
- tab = new punkt[n];
- int i = 0;
- while(p!=k)
- {
- tab[i] = *p;
- i++;
- p++;
- }
- }
- wielobok()
- {
- n = 0;
- tab = NULL;
- }
- punkt &punkte(int nr)
- {
- return tab[nr];
- }
- float obwod()
- {
- float obw=0;
- for(int i=0;i<n-1;i++)
- {
- obw+=tab[i].odleglosc(tab[i+1]);
- }
- obw+=tab[n].odleglosc(tab[0]);
- return obw;
- }
- void punkty(punkt * p,punkt * k)
- {
- n = k - p;
- tab = new punkt[n];
- int i = 0;
- while(p!=k)
- {
- tab[i] = *p;
- i++;
- p++;
- }
- }
- int ilosc()
- {
- return n;
- }
- };
- int main(int ile,char* dane[])
- {
- punkt p(2, 3);
- cout << p.x() << ' ' << p.y() << '\n';
- p.x() = 1;
- p.y() = 1;
- cout << p.x() << ' ' << p.y() << '\n';
- cout << p.odleglosc(punkt()) << '\n';
- punkt t[] = { punkt(0, 1), punkt(0, 0), punkt(1, 0), punkt(1, 1) };
- wielobok w1(t, t+4);
- cout << w1.obwod() << '\n';
- w1.punkte(1) = punkt(0.5, 0.5);
- cout << w1.obwod() << '\n';
- wielobok w2;
- w2.punkty(t, t+3);
- cout << w2.obwod() << '\n';
- for (int i = 0; i < w2.ilosc(); ++i)
- cout << w2.punkte(i).x() << ' ' << w2.punkte(i).y() << '\n';
- return 0;
- }
- Zad4
- #include<iostream>
- using namespace std;
- class adres
- {
- private:
- string _miasto, _ulica, _kod;
- unsigned int _nr;
- public:
- adres()
- {
- }
- adres(string miasto, string kod, string ulica, unsigned nr)
- {
- _miasto = miasto;
- _ulica = ulica;
- _nr = nr;
- _kod = kod;
- }
- //ostream& operator <<()
- //{
- // out<<_mieszkanie;
- // return out;
- // }
- };
- // Jesli jeden obiekt jest dynamiczny w klasie to musimy utworzyc:
- // 1. Konstruktor kopjujacy (domyslny kopjuje adres wskaznika, a nie dane)
- // osoba o2(o); ==to samo== osoba o2=o;
- // 2. Deztruktor
- // 3. Operator kopjujacy
- class osoba
- {
- private:
- string _imie, _nazwisko;
- unsigned int _wiek;
- adres * _adres;
- public:
- osoba()
- {
- _adres = 0;
- }
- osoba(const osoba &o) // Konstruktor kopjujacy
- {
- _imie = o._imie;
- _nazwisko = o._nazwisko;
- _wiek = o._wiek;
- _adres = new adres;
- *_adres = *o._adres;
- }
- osoba& operator =(const osoba &o) // Operator kopjujacy
- {
- if(&o != this) // Zbezpiczenie przed o2 = o2;
- {
- _imie = o._imie;
- _nazwisko = o._nazwisko;
- _wiek = o._wiek;
- if (_adres != 0) delete _adres;
- _adres = new adres;
- *_adres = *o._adres;
- }
- return *this;
- }
- osoba(string imie, string nazwisko, unsigned wiek,adres Adres)
- {
- _imie = imie;
- _nazwisko = nazwisko;
- _wiek = wiek;
- _adres = new adres;
- *_adres = Adres;
- }
- ~osoba() // Deztruktor
- {
- if (_adres != 0)
- {
- delete _adres;
- }
- }
- };
- int main(int ile,char* dane[])
- {
- adres* wsk = new adres("Czestochowa", "42-200", "Dabrowskiego", 73);
- //cout << *wsk << '\n';
- adres a1(*wsk);
- delete wsk;
- const adres* wsk1 = new adres("Warszawa", "00-950", "Mysliwiecka", 357);
- //cout << a1 << '\n';
- //cout << *wsk1 << '\n';
- adres a2;
- //cout << a2 << '\n';
- a2 = a1;
- //cout << a2 << '\n';
- osoba o("Jan", "Kos", 25, *wsk1);
- //cout << o << '\n';
- osoba o1(o);
- //cout << o1 << '\n';
- osoba o2;
- //cout << o2 << '\n';
- o2 = o1;
- //cout << o2 << '\n';
- delete wsk1;
- return 0;
- }
- Zad5
- #include<iostream>
- using namespace std;
- class punkt
- {
- private:
- double wsp[3];
- public:
- punkt()
- {
- for(int i=0;i<3;i++)
- wsp[i]=0;
- }
- punkt(double p[])
- {
- for(int i=0;i<3;i++)
- wsp[i]=p[i];
- }
- punkt(const double a, const double b, const double c)
- {
- wsp[0]=a;
- wsp[1]=b;
- wsp[2]=c;
- }
- //operator przeciazony w klasie
- //zwraca operator'symbol'(argumenty)
- double& operator[](int i)
- {
- return wsp[i];
- }
- //operator dwuargumentowy w klasie
- punkt operator+(punkt p2)
- {
- punkt p3;
- for(int i=0;i<3;i++)
- p3[i]=wsp[i]+p2[i];
- return p3;
- }
- friend ostream& operator<<(ostream& out,const punkt& p)
- {
- out<<'('<<p[0]<<','<<p[1]<<','<<p[2]<<')';
- return out;
- }
- ostream& operator<<(ostream& out, punkt p)
- {
- out<<'('<<p[0]<<','<<p[1]<<','<<p[2]<<')';
- return out;
- }
- };
- //operator dwuargumentowy poza klasa
- punkt operator+(punkt p1,punkt p2)
- {
- punkt p3;
- for(int i=0;i<3;i++)
- p3[i]=p1[i]+p2[i];
- return p3;
- }
- punkt operator+(punkt p,double v)
- {
- punkt p3;
- for(int i=0;i<3;i++)
- p3[i]=p[i]+v;
- return p3;
- }
- punkt operator+(double v,punkt p)
- {
- return p+v;
- }
- int main(int ile,char* dane[])
- {
- double x[2][3] = {{1.0, 1.0, 1.0},
- {1.0, 2.0, 3.0}};
- punkt p1(x[0]), p2(x[1]);
- const punkt p3(0.4, 0.2, 0.1);
- cout << p1 << ", " << p2 << "\n";
- cout << p3[0] << ' ' << p3[1] << ' ' << p3[2] << '\n';
- //cout << p1.distance(point()) << ", "<< p3.distance(p1) << '\n';
- //cout << p1 + p2 << ", " << p1 - p3 << '\n';
- //cout << 3.14 * p2 << ", " << p2 * 3.14 << '\n';
- //cout << (p1 < p3) << ", " << (p1 == punkt(1.0, 1.0, 1.0)) << '\n';
- //cin >> p1;
- //cout << p1 << '\n';
- return 0;
- }
- Zad6
- #include<iostream>
- #include<fstream>
- using namespace std;
- class punkt
- {
- private:
- double wsp[2];
- public:
- punkt()
- {
- for(int i=0;i<2;i++)
- wsp[i]=0;
- }
- punkt(double p[])
- {
- for(int i=0;i<2;i++)
- wsp[i]=p[i];
- }
- punkt(const double a,const double b)
- {
- wsp[0]=a;
- wsp[1]=b;
- }
- double& operator[](int i)
- {
- return wsp[i];
- }
- };
- int main(int ile,char* dane[])
- {
- ifstream plik("z6.txt");
- if(!plik)
- {
- return 1;
- }
- char tmp[255];
- int i=0;
- int non;
- int * poly;
- punkt * punkty;
- int n;
- double x,y;
- while(i==0)
- {
- plik.getline(tmp,255);
- if(tmp[0] =='[')
- if(tmp[1] =='N')
- if(tmp[2] =='U')
- if(tmp[3] =='M')
- if(tmp[4] =='B')
- if(tmp[5] =='E')
- if(tmp[6] =='R')
- {
- cout<<tmp<<endl;
- plik>>non;
- cout<<non<<endl;
- punkty = new punkt[non];
- poly = new int[non];
- continue;
- }
- if(tmp[0] =='[')
- if(tmp[1] =='N')
- if(tmp[2] =='O')
- if(tmp[3] =='D')
- if(tmp[4] =='E')
- if(tmp[5] =='S')
- if(tmp[6] ==']')
- {
- cout<<tmp<<endl;
- for(int i=0;i<non;++i)
- {
- plik>>n>>x>>y;
- //punkty[n-1].x() = x;
- punkty[n-1][0] = x;
- punkty[n-1][1] = y;
- cout<<n<<' '<<punkty[n-1][0]<<' '<<punkty[n-1][1]<<endl;
- }
- continue;
- }
- if(tmp[0] =='[')
- if(tmp[1] =='P')
- if(tmp[2] =='O')
- if(tmp[3] =='L')
- if(tmp[4] =='Y')
- if(tmp[5] =='G')
- if(tmp[6] =='O')
- if(tmp[7] =='N')
- if(tmp[8] ==']')
- {
- cout<<tmp<<endl;
- for(int i=0;i<non;++i)
- {
- plik>>poly[i];
- cout<<poly[i]<<' ';
- }
- cout<<endl;
- break;
- }
- }
- //Pole
- double pole=0;
- for(int q=0;q<non-1;q++)
- pole+=punkty[poly[q]-1][0]*punkty[poly[q]][1]-punkty[poly[q]][0]*punkty[poly[q]-1][1];
- pole/=2;
- cout<<"Pole: "<<pole<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement