Advertisement
Guest User

OOP C++ 2

a guest
Aug 20th, 2015
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. /*
  2. cities.txt ფაილში ჩაწერილია ინფორმაცია ქალაქების შესახებ
  3.  
  4. ქალაქის დასახელება, ქვეყანა , მოსახლეობა (მილიონებში)
  5.  
  6. ფაილის დასაწყისში წერია ჩანაწერების რაოდენობა.
  7.  
  8. შექმენით შესაბამისი ვექტორი და ფაილიდან წაკითხული ქალაქები
  9. ჩაწერეთ მასში. ინფორმაცია იმ ქალაქების შესახებ, რომლებშიც
  10. 5 მილიონზე მეტი მოსახლეობაა ჩაწერეთ large.txt ფაილში,
  11. ხოლო იმ ქალაქების შესახებ ინფორმაცია რომელშიც 5მილიონი
  12. ან ნაკლები მოსახლეა ჩაწერეთ small.txt ფაილში
  13.  
  14. */
  15.  
  16. #include <iostream>
  17. #include <fstream>
  18. #include <vector>
  19. #include <string>
  20.  
  21. using namespace std;
  22.  
  23. class City{
  24. public :
  25.     string name;
  26.     string country;
  27.     double population;
  28.  
  29.     City(ifstream &ifs);
  30.  
  31.     void printInfo(ofstream &ofs);
  32. };
  33.  
  34. City::City(ifstream &ifs){
  35.     ifs >> name >> country >> population;
  36. }
  37.  
  38. void City::printInfo(ofstream &ofs){
  39.     ofs << "Name : " << name << ",\tCountry : " <<
  40.         country << ",\tPopulation : " << population << endl;
  41. }
  42.  
  43. int main(){
  44.  
  45.     vector<City> cities;
  46.  
  47.     ifstream ifs("cities.txt");
  48.     ofstream ofsLarge("large.txt");
  49.     ofstream ofsSmall("small.txt");
  50.  
  51.     int count(0);
  52.  
  53.     ifs >> count;
  54.  
  55.     for (int i = 0; i < count; i++){
  56.         City city(ifs);
  57.         cities.push_back(city);
  58.     }
  59.  
  60.     for (int i = 0; i < cities.size(); i++){
  61.         if (cities[i].population <= 5){
  62.             cities[i].printInfo(ofsSmall);
  63.         }
  64.         else{
  65.             cities[i].printInfo(ofsLarge);
  66.         }
  67.     }
  68.  
  69.     return 0;
  70. }
  71.  
  72. /*
  73. ფაილი
  74.  
  75. 6
  76. Tbilisi Georgia 3
  77. Gori Georgia 0.3
  78. Baku Azerbajan 5.5
  79. Nicosia Cyprus 1.7
  80. Berlin Germany 7.95
  81. Paris France 6.66
  82.  
  83. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement