Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- cities.txt ფაილში ჩაწერილია ინფორმაცია ქალაქების შესახებ
- ქალაქის დასახელება, ქვეყანა , მოსახლეობა (მილიონებში)
- ფაილის დასაწყისში წერია ჩანაწერების რაოდენობა.
- შექმენით შესაბამისი ვექტორი და ფაილიდან წაკითხული ქალაქები
- ჩაწერეთ მასში. ინფორმაცია იმ ქალაქების შესახებ, რომლებშიც
- 5 მილიონზე მეტი მოსახლეობაა ჩაწერეთ large.txt ფაილში,
- ხოლო იმ ქალაქების შესახებ ინფორმაცია რომელშიც 5მილიონი
- ან ნაკლები მოსახლეა ჩაწერეთ small.txt ფაილში
- */
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- using namespace std;
- class City{
- public :
- string name;
- string country;
- double population;
- City(ifstream &ifs);
- void printInfo(ofstream &ofs);
- };
- City::City(ifstream &ifs){
- ifs >> name >> country >> population;
- }
- void City::printInfo(ofstream &ofs){
- ofs << "Name : " << name << ",\tCountry : " <<
- country << ",\tPopulation : " << population << endl;
- }
- int main(){
- vector<City> cities;
- ifstream ifs("cities.txt");
- ofstream ofsLarge("large.txt");
- ofstream ofsSmall("small.txt");
- int count(0);
- ifs >> count;
- for (int i = 0; i < count; i++){
- City city(ifs);
- cities.push_back(city);
- }
- for (int i = 0; i < cities.size(); i++){
- if (cities[i].population <= 5){
- cities[i].printInfo(ofsSmall);
- }
- else{
- cities[i].printInfo(ofsLarge);
- }
- }
- return 0;
- }
- /*
- ფაილი
- 6
- Tbilisi Georgia 3
- Gori Georgia 0.3
- Baku Azerbajan 5.5
- Nicosia Cyprus 1.7
- Berlin Germany 7.95
- Paris France 6.66
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement