vakho

კოლოქვიუმისთვის – ამოცანა 7

May 4th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class Island
  8. {
  9. private:
  10.     string Name, Location;
  11.     double Area;
  12. public:
  13.     Island()
  14.     {
  15.         Name = "Noname";
  16.         Location = "Unknown";
  17.         Area = 0.;
  18.     };
  19.     friend istream& operator>>(istream &cin, Island &isl)
  20.     {
  21.         cin >> isl.Name >> isl.Location >> isl.Area;
  22.         return cin;
  23.     };
  24.     friend ostream& operator<<(ostream &cout, Island &isl)
  25.     {
  26.         cout << isl.Name << endl << isl.Location << endl;
  27.         return cout;
  28.     };
  29.     friend Island maxArea(Island *a, int size)
  30.     {
  31.         Island &max = a[0];
  32.         for (int i = 0; i < size; i++)
  33.             if (a[i].Area > max.Area)
  34.                 max = a[i];
  35.         return max;
  36.     };
  37.     Island(string N, string L, double A):Name(N), Location(L), Area(A){};
  38.     ~Island(){};
  39. };
  40.  
  41. int main()
  42. {
  43.     const int N = 29;
  44.     Island *ptr = new Island[N];
  45.     ifstream ifs("Islands.txt");
  46.     Island isl;
  47.     for (int i = 0; i < N; i++)
  48.     {
  49.         ifs >> isl;
  50.         ptr[i] = isl;
  51.     }
  52.     ifs.close();
  53.     cout << maxArea(ptr, N);
  54.     delete [] ptr;
  55.     ptr = NULL;
  56.     system("PAUSE");
  57.     return (0);
  58. };
Advertisement
Add Comment
Please, Sign In to add comment