Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 1.
- დაწერეთ პროგრამის ფრაგმენტი, რომელიც numbers.txt ფაილში ჩაწერილ 1205 მთელ რიცხვს განათავსებს
- დინამიკურ მეხსიერებაში (გამოიყენეთ new ოპერატორი), შემდეგ ფაილის ბოლოსწინა რიცხვზე 3 –ჯერ მეტ
- რიცხვებს დაბეჭდავს 10 სვეტად. ჩათვალეთ, რომ ასეთი რიცხვები ფაილში არის. (3 ქულა)
- */
- #include <iostream>
- #include <fstream>
- using namespace std;
- #define size 1205
- int main()
- {
- system("COLOR F0");
- int *ptr = new int[size];
- ifstream ifs("numbers.txt");
- for (int i = 0; i < size; i++)
- ifs >> ptr[i];
- ifs.close();
- for (int i = 0, int count = 0; i < size; i++)
- {
- if ( (ptr[size - 1] * 3) < ptr[i] )
- {
- cout << setw(5) << left << ptr[i];
- count++;
- };
- if (count % 10 == 0)
- cout << endl;
- };
- delete [] ptr;
- ptr = NULL;
- system("PAUSE");
- return (0);
- };
- /*
- 2.
- cities.txt ფაილში ჩაწერილია სხვადასხვა ქალაქების მონაცემები – თითოეულის სახელი, დაკავებული
- ტერიტორიის ფართობი (კვ.კმ), მოსახლეობის რაოდენობა (მლნ.), ქუჩების რაოდენობა. ქალაქების
- რაოდენობა არ აღემატება 900–ს. დაწერეთ პროგრამა, რომელიც density.out ფაილში ჩაწერს ყველა
- იმ ქალაქის მონაცემებს, რომელთა მოსახლეობის სიმჭიდროვე არ აღემატება 1000 ად/კმ^2 –ზე.
- ამოცანის ამოსახსნელად შექმენით კლასი City, რომელშიც გაითვალისწირეთ თქვენი აზრით საჭირო
- კლასის ფუნქციები. კლასის ობიექტისთვის გადათვირთეთ >> და << ოპერატორები. მონაცემების
- ფაილიდან წასაკითხად და ფაილში ჩასაწერად შექმენით გლობალური ფუნქციები. მოთხოვნილი
- თვისების მქონე ქალაქის დასადგენად ასევე შექმენით ფუნქცია. ინფორმაცია cities.txt ფაილიდან
- განათავსეთ დინამიკურ მეხსიერებაში. (6 ქულა)
- */
- #include <iostream>
- #include <fstream>
- #include <string>
- #define size 900
- using namespace std;
- class City
- {
- private:
- string name;
- int area, population, streets;
- public:
- City(){};
- ~City(){};
- friend ostream& operator << (ostream &cout, City &a)
- {
- cout << a.name << a.area << a.population << a.streets;
- return cout;
- };
- friend istream& operator >> (istream &cin, City &a)
- {
- cin >> a.name >> a.area >> a.population >> a.streets;
- return cin;
- };
- friend bool Dencity(City &a)
- {
- return (( a.population / a.area ) <= 1000);
- };
- };
- void WriteInFile(City *A, ofstream &ofs)
- {
- for (int i = 0; i < size; i++)
- if ( Dencity(A[i]) )
- ofs << A[i];
- };
- int main()
- {
- system("COLOR F0");
- City *ptr = new City[size];
- ifstream ifs("cities.txt");
- for (int i = 0; i < size; i++)
- ifs >> ptr[i];
- ifs.close();
- ofstream ofs("density.out");
- WriteInFile(ptr, ofs);
- ofs.close();
- delete [] ptr;
- ptr = NULL;
- system("PAUSE");
- return (0);
- };
- /*
- 3.
- შემქენით კლასი book მონაცემებით – წიგნის დასახელება, ავტორის გვარი, წიგნის ღირებულება,
- წიგნის გამოცემის წელი. კლასში შემოიღეთ ფუნქციები – პარამეტრებიანი კონსტრუქტორი, დესტრუქტორი
- და საჭიროების მიხედვით კლასის სხვა ფუნქციები. book კლასის საფუძველზე შექმენით კლასი library_card
- საკუთარი მონაცემებით – კატალოგის ნომერი (მაგალითად 192039) და წიგნის გაცემის რაოდენობა.
- library_card კლასში იქონიეთ ფუნქციები – პარამეტრებიანი კონსტრუქტორი, დესტრუქტორი და საჭიროების
- მიხედვით კლასის სხვა ფუნქციები.
- main -ში გააკეთეთ განაცხადი ორივე კლასის თითო–თითო ობიექტზე. დაბეჭდეთ წიგნის მონაცემები და
- ბიბლიოთეკის ბარათის ინფორმაცია. შემდეგ შეცვალეთ წიგნის ღირებულება და კვლავ დაბეჭდეთ
- ბიბლიოთეკის ბარათის ინფორმაცია. (6 ქულა)
- */
- #include <iostream>
- #include <iomanip>
- #include <string>
- using namespace std;
- class book
- {
- protected:
- string name, author_surname;
- double price;
- int release_year;
- public:
- book(string n = "noname", string as = "unknown", double p = 0.0, int ry = 0)
- :name(n), author_surname(as), price(p), release_year(ry){};
- ~book(){};
- void SetPrice(double pr = 0.0)
- {
- price = pr;
- };
- void printInfo()
- {
- cout << setw(5) << left << this->name << "\t" << this->author_surname << "\t" << this->price << "\t" << this->release_year << endl;
- };
- };
- class library_card : public book
- {
- private:
- int catalogue_number, give_aways;
- public:
- library_card(string n = "noname", string as = "unknown", double p = 0.0, int ry = 0, int cn = 0, int ga = 0)
- :book(n, as, p, ry), catalogue_number(cn), give_aways(ga){};
- ~library_card(){};
- void printInfo()
- {
- cout << setw(5) << left << this->name << "\t" << this->author_surname << "\t" << this->price << "\t" << this->release_year << "\t" << this->catalogue_number << "\t" << this->give_aways << endl;
- };
- };
- int main()
- {
- system("COLOR F0");
- book BK("CPP", "Straustrup", 100.99, 2012);
- library_card LC("CPP", "Straustrup", 100.99, 2012, 123456, 12);
- BK.printInfo();
- LC.printInfo();
- LC.SetPrice(17.5);
- LC.printInfo();
- system("PAUSE");
- return (0);
- };
Advertisement
Add Comment
Please, Sign In to add comment