trojanxem

Untitled

Jun 17th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3. #include <string.h>
  4. #include <map>
  5. #include <vector>
  6. #include <algorithm>
  7.  
  8.  
  9. using namespace std;
  10.  
  11.  
  12.  template <typename T>
  13.  class Punkt
  14.  {
  15.     public:
  16.        Punkt( T argX, T argY, T argZ )
  17.        : x(argX), y(argY), z(argZ)
  18.        { }
  19.  
  20.        T x, y, z;
  21.  };
  22.  
  23. template <class parametr1, class parametr2>
  24. parametr1 sumuj (parametr1 argument1, parametr2 argument2)
  25. {
  26.     if( argument1 + argument2 > 10)
  27.     {
  28.         return (argument1 + argument2);
  29.     }
  30.     else
  31.     {
  32.         return 666;
  33.     }
  34.     if( argument1 + argument2 == 0)
  35.     {
  36.         return 0;
  37.     }
  38.     else
  39.     {
  40.  
  41.         return 987654321;
  42.     }
  43.  
  44. }
  45.  
  46.  
  47.  typedef Punkt<int> PunktInt;
  48.  typedef Punkt<unsigned> PunktUInt;
  49.  typedef Punkt<float> PunktFloat;
  50.  
  51.  int main(void)
  52.  {
  53.     PunktInt A(0,-10,0);
  54.     PunktUInt B(0,10,5);
  55. /*Pierwsze*/
  56. cout<<"Zadanie pierwsze "<<endl;
  57.    cout << "A(" << A.x << "," << A.y << "," << A.z << ")" << endl;            // Efekt wywolania metody 1
  58.    cout << "B(" << B.x << "," << B.y << "," << B.z << ")" << endl;
  59.     cout <<endl;
  60.      cout <<endl;
  61.      /*Drugie*/
  62.      cout<<"Zadanie drugie "<<endl;
  63.    cout << sumuj(5,  10) <<endl;
  64.     cout <<endl;
  65.      cout <<endl;
  66.    /* Zadanie trzecie i osme */
  67.    cout<<"Zadanie trzecie "<<endl;
  68.    list<int> L;
  69.    L.push_back(0);              // Na koncu listy element
  70.    L.push_front(0);             // -||- na koncu
  71.    L.insert(++L.begin(),2);     // Wlóz dwa przed pierwsz¹ pozycjê
  72.    L.push_back(5);
  73.    L.push_back(6);
  74.    list<int>::iterator i;
  75.    cout << "Polecenie trzecie" << endl;
  76.    for(i=L.begin(); i != L.end(); ++i)
  77.    {
  78.        cout << *i << " ";
  79.    }
  80.    L.sort();
  81.    cout << "Po sortowaniu zadanie 8 polowa" <<endl;
  82.     for(i=L.begin(); i != L.end(); ++i)
  83.    {
  84.        cout << *i << " ";
  85.    }
  86.    cout <<endl;
  87.    cout <<endl;
  88.     cout << "Po sortowaniu zadanie 8 druga polowa" <<endl;
  89.    cout << "Maximum ze stla: " <<endl;
  90.    cout << "max(3.14,2.73)==" << max(3.14,2.73) << '\n';
  91.  
  92.    cout <<endl;
  93.     cout <<endl;
  94.  
  95.  
  96.  
  97.     /* Zadanie czwarte */
  98.     map<int, string> Film;
  99.     cout << "Zadanie czwarte" <<endl;
  100.    Film[4] = "Oszukac przeznaczenie";
  101.    Film[6] = "24 hours";
  102.    Film[8] = "300";
  103.    Film[9] = "Lord of the rings";
  104.    Film[7] = "King Kong";
  105.       cout << "Map size: " << Film.size() << endl;
  106.    for( map<int,string>::iterator ii=Film.begin(); ii!=Film.end(); ++ii)
  107.    {
  108.        cout << (*ii).first << ": " << (*ii).second << endl;
  109.    }
  110.     cout <<endl;
  111.      cout <<endl;
  112.  
  113.    /*Zadanie pi¹te */
  114.    vector<string> wektor;
  115.    cout << "Zadanie piate" <<endl;
  116. wektor.push_back("The number is 10");
  117. wektor.push_back("The number is 20");
  118. wektor.push_back("The number is 30");
  119. cout << "Petla po indeksie <Vektor>:" << endl;
  120. int ii;
  121. for(ii=0; ii < wektor.size(); ii++)
  122. {
  123. cout << wektor[ii] << endl;
  124. }
  125. cout << endl << "Staly iterator:" << endl;
  126. vector<string>::const_iterator cii;
  127. for(cii=wektor.begin(); cii!=wektor.end(); cii++)
  128.  {
  129.   cout << *cii << endl;
  130.   }
  131.    cout <<endl;
  132.     cout <<endl;
  133.  
  134.  
  135.  
  136.  
  137.    return 0;
  138.  
  139.  
  140.  
  141.  }
Advertisement
Add Comment
Please, Sign In to add comment