Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <c++/map>
- #include <c++/fstream>
- using namespace std;
- template <typename T>
- void swap2(T &t1, T &t2)
- {
- T tmp = t1;
- t1 = t2;
- t2 = tmp;
- }
- class Bryla{
- public:
- Bryla(){ };
- virtual double obj() = 0;
- };
- class Szescian : public Bryla{
- private:
- double a;
- public:
- Szescian(double a) : a(a){ };
- double obj() override
- {
- return a*a*a;
- }
- };
- class Kula : public Bryla{
- private:
- double r;
- public:
- Kula(double r) : r(r) {};
- double obj() override
- {
- double PI = 3.14;
- return 4/3*PI*r*r*r;
- }
- };
- class ReadFile{
- private:
- string fName;
- fstream plik;
- map<string, int> wyrazy;
- public:
- ReadFile(const string & f) : fName(f){};
- void readWords()
- {
- plik.open(fName,ios::in);
- if(!plik.good())
- throw runtime_error("Nie mozna odczytac pliku");
- else
- {
- string tmp;
- while(!plik.eof())
- {
- plik >> tmp;
- auto it = wyrazy.find(tmp);
- if(it == wyrazy.end())
- {
- wyrazy.insert(make_pair(tmp,1));
- }
- else
- {
- it->second++;
- }
- }
- }
- }
- };
- int main()
- {
- int a, b;
- a = 5;
- b = 3;
- cout << a << " " << b << endl;
- swap2(a,b);
- cout << a << " " << b << endl;
- vector<Bryla*> bryly(2);
- bryly[0] = new Kula(5);
- bryly[1] = new Szescian(10);
- double objsum = 0;
- for(const auto& b : bryly)
- {
- objsum += b->obj();
- }
- double objAvg = objsum / bryly.size();
- cout << objAvg << endl;
- ReadFile rf("test.txt");
- rf.readWords();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement