V
V
Valeria Tkacheva2019-12-06 23:39:28
C++ / C#
Valeria Tkacheva, 2019-12-06 23:39:28

Gives an error that the constructor must have a class type. How to fix it?

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
class CONTRY
{
  char* name;
  double temp_summer, temp_autumn, temp_winter, temp_spring;
public:
  CONTRY() { name = NULL; };
  CONTRY(char*, double, double, double, double);
  ~CONTRY() { delete[]name; }
  void print();
  char* getname() { return name; }
  double gettemp_winter() { return temp_winter; }
  double gettemp_spring() { return temp_spring; }
  double gettemp_summer() { return temp_summer; }
  double gettemp_autumn() { return temp_autumn; }
};
CONTRY::CONTRY(char* aname, double atemp_winter, double atemp_spring, double atemp_summer, double atemp_autumn)
{
  int n;
  n = strlen(aname);
  name = new char[n + 1];
  strcpy(name, aname);
  temp_winter = atemp_winter;
  temp_spring = atemp_spring;
  temp_summer = atemp_summer;
  temp_autumn = atemp_autumn;
}
void CONTRY::print()
{
  cout << setw(16) << name << '|';
  cout << setw(20) << temp_winter << '|';
  cout << setw(17) << temp_spring << '|';
  cout << setw(15) << temp_summer << '|';
  cout << setw(15) << temp_autumn << '|';
  cout << '\n';
}
int main()
{
  setlocale(LC_ALL, "Russian");
  CONTRY *a[100];
  double temp_summer, temp_autumn, temp_winter, temp_spring;
  int n, i;
  char name[30];
  cout << "Введите кол-во городов: ";
  cin >> n;
  for (i = 0; i < n; i++)
  {
    cout << "\n";
    cout << "Название города: ";
    cin >> name;
    cout << "ТЕМПЕРАТУРА ЗИМОЙ: ";
    cin >> temp_winter;
    cout << "ТЕМПЕРАТУРА ВЕСНОЙ: ";
    cin >> temp_spring;
    cout << "ТЕМПЕРАТУРА ЛЕТОМ: ";
    cin >> temp_summer;
    cout << "ТЕМПЕРАТУРА ОСЕНЬЮ: ";
    cin >> temp_autumn;

    a[i] = new CONTRY(name, temp_winter, temp_spring, temp_summer, temp_autumn);
  }
  cout << "Название города | температура зимой | температура весной | температура летом | температура осенью |\n";
  for (i = 0; i < n; i++)
    a[i]->print();
  int winter = a[0]->gettemp_winter();
  int summer = a[0]->gettemp_summer();
  for (i = 0; i < n; i++)
  {
    if (winter < a[i]->gettemp_winter())
      winter = a[i]->gettemp_winter();
    if (summer > a[i]->gettemp_summer())
      summer = a[i]->gettemp_summer();

  }
  for (i = 0; i < n; i++)
  {
    if (a[i]->gettemp_winter() == winter)

      cout << "СТРАНА С САМОЙ ТЕПЛОЙ ЗИМОЙ \n" << a[i].getname << "ТЕМПЕРАТУРА ЗИМОЙ = " << winter << endl;
    if (a[i]->gettemp_summer() == summer)
      cout << "СТРАНА С САМЫМ ХОЛОДНЫМ ЛЕТОМ \n " << a[i].getname << "ЛЕТНЯЯ ТЕМПЕРАТУРА = " << summer << endl;
  }


  system("pause");
}

As a result, the countries with the coldest summers and the warmest winters should emerge.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tsarevfs, 2019-12-06
@valerikk

It helped me to
replace with
https://ideone.com/LqYxAG

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question