Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- #include <windows.h>
- #include <fstream>
- using namespace std;
- class celestialBody {
- protected:
- string name; //Название
- float maxtemp, age;//Максимальная температура и возраст
- public:
- celestialBody(); // конструктор без параметров
- celestialBody(string _name, float _maxtemp, float _age);// конструктор инициализации
- virtual void print();
- string getName();
- float getMaxTemp();
- float getAge();
- virtual ~celestialBody(); // деструктор
- virtual string get_t(){
- return "0";
- }
- };
- celestialBody::celestialBody()
- {
- name = "";
- maxtemp =0;
- age = 0;
- }
- celestialBody::celestialBody(string _name, float _maxtemp, float _age) : name(_name), maxtemp(_maxtemp), age(_age)
- {}
- void celestialBody::print()
- {
- //cout<<left<<setw(20) << "Название " <<setw(12)<< "Температура" <<setw(7) << "Возраст"<< endl;
- cout<<left<<fixed<<setw(20)<<name<<setw(12)<<setprecision(2)<<maxtemp << setw(7) <<setprecision(2)<<age;
- }
- string celestialBody::getName()
- {
- return name;
- }
- float celestialBody::getMaxTemp()
- {
- return maxtemp;
- }
- float celestialBody::getAge()
- {
- return age;
- }
- celestialBody::~celestialBody()
- {
- cout << "Объект удален из памяти!" << endl;
- }
- class cometa : public celestialBody{
- string type;
- float dia, period, ecc;
- public:
- cometa(): type(""), dia(0), period(0), ecc(0){}
- cometa(string _name, float _maxtemp, float _age, string _type, float _dia, float _period, float _ecc): celestialBody(_name, _maxtemp, _age) {
- dia = _dia;
- period = _period;
- ecc = _ecc;
- }
- void print(){
- celestialBody::print();
- cout << "WITH: " << dia << " " << period << " " << ecc << "\n";
- }
- string get_t(){
- return type;
- }
- float get_p(){
- return period;
- }
- ~cometa(){
- cout << "object destroyed \n";
- }
- };
- class Container {
- celestialBody** arr;
- int n;
- public:
- Container() :arr(nullptr), n(0) {}
- Container(string filename) {
- /*freopen(filename.c_str(), "r", stdin);
- ofstream cout(filename.c_str(), std::ios::out);*/
- ifstream in(filename.c_str(), ios::in);
- in >> this->n;
- arr = new celestialBody * [this->n];
- cout << "n " << n << endl;
- for (int i = 0; i < this->n; i++) {
- string s;
- in >> s;
- if (s == "тело") {
- string name;
- float a, b;
- in >> name >> a >> b;
- arr[i] = new celestialBody(name, a, b);
- }
- else if (s == "комета") {
- string name, tp;
- float a, b, c, d, e;
- //int d;
- in >> name >> a >> b >> c >> d >> e;
- arr[i] = new cometa(name, a, b, tp, c, d, e);
- }
- }
- }
- ~Container() {
- for (int i = 0; i < this->n; i++) {
- delete arr[i];
- }
- delete[]arr;
- }
- //2
- void printData() {
- for (int i = 0; i < this->n; i++) {
- arr[i]->print();
- }
- }
- //3
- double f3(char startW) {
- float mnt = -10000;
- for (int i = 0; i < this->n; i++) {
- if (arr[i]->getName()[0] == startW) {
- mnt = min(arr[i]->getMaxTemp(), mnt);
- }
- }
- return mnt ;
- }
- //4 // most fr type cometa
- string f4() {
- float a[3];
- a[0] = 0;
- a[1] = 0;
- a[2] = 0;
- for(int i = 0; i < n; i++){
- if(arr[i]->get_t() == "0"){
- continue;
- }
- if(arr[i]->get_t() == "короткопериодическая"){
- a[0] +=1;
- }
- if(arr[i]->get_t() == "долгопериодическая"){
- a[1] +=1;
- }
- if(arr[i]->get_t() == "межзвездная"){
- a[2] +=1;
- }
- }
- float mx = max(a[0], max(a[1], a[2]));
- if(a[0] == mx){
- cout << "короткопериодическая\n";
- return "короткопериодическая";
- }
- if(a[1] == mx){
- cout << "долгопериодическая\n";
- return "долгопериодическая";
- }
- if(a[2] == mx){
- cout << "долгопериодическая\n";
- return "долгопериодическая";
- }
- }
- };
- int main() {
- setlocale(LC_ALL, "rus");
- //SetConsoleCP(1251);
- string fn = "variant7.txt";
- Container c(fn);
- c.printData();
- char st;
- cin >> st;
- cout << "f3: " << c.f3(st) << "\n";
- c.f4();
- return 0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment