Тема: C++ помилка в коді
Привіт. У мене помилка в стрічці 38. Якщо не складно, підкажіть що не так і допоможіть виправити. У Visual Studio пише: Variable is uninitialized.Always initilize a member variable (type6). Але в олнайн-компіляторі все працює
#include <iostream>
#include <string>
#include <fstream>
#include <conio.h>
using namespace std;
struct TarifPlan
{
private:
float zalishok;
public:
float sms;
float price1;
float price2;
void setzalishok()
{
zalishok = 15;
}
int getzalishok()
{
//cout << zalishok << endl;
return zalishok;
}
void popovnenya()
{
zalishok += 20;
}
void popovnenya(int x)
{
zalishok += x;
}
void abouttarifplan()
{
cout << " Vartist sms - " << sms << "\n Zena rozmovu v sereduni mereshi - " << price1 << "\n Zena rozmovu z nomeramu inshih operatoriv - " << price2 << "\n Zalishok = " << zalishok << endl;
}
TarifPlan() //тут помилка
{
ifstream filee;
filee.open("tarifplan.txt", fstream::in);
filee >> sms;
filee >> price1;
filee >> price2;
}
};
class Abonent
{
protected:
int nomer;
string result;
string name;
TarifPlan plan;
//------------------------------------------------------------------------------------------------------------------
public:
Abonent()
{
ifstream filee;
filee.open("abonent.txt", fstream::in);
filee >> nomer;
filee >> result;
filee >> name;
}
void aboutabonent()
{
cout << " nomer - " << nomer << "\n result - " << result << "\n name - " << name << endl;
plan.abouttarifplan();
}
void popovnenya()
{
plan.popovnenya();
}
void popovnenya(int x)
{
plan.popovnenya(x);
}
void setzalishok()
{
plan.setzalishok();
}
};
class Naslidok : public Abonent
{
public:
void zchituvanua(string imya)
{
ifstream filee;
filee.open(imya, fstream::in);
filee >> plan.sms;
filee >> plan.price1;
filee >> plan.price2;
}
void choosingtf()
{
popovnenya(-10);
}
friend void countsms(Naslidok& value);
};
int zukl(float value1, float value2)
{
int count = 0;
while (value1 != 0)
{
value1 -= value2;
if (value1 >= 0)
count++;
else
break;
}
//cout << count << endl;
return count;
}
void countsms(Naslidok& value)
{
float x = value.plan.getzalishok();
cout << " Count of sms - " << zukl(x, value.plan.sms) << endl;
cout << " Count of zena1 - " << zukl(x, value.plan.price1) << endl;
cout << " Count of zena2 - " << zukl(x, value.plan.price2) << endl;
//cout << " Count of sms - " << count<< endl;
}
Naslidok naslidok;
void menu()
{
char point;
cout << "Viberite tarifplan: 1, 2, 3, 4 or 5 : ";
cin >> point;
switch (point)
{
case '1':
naslidok.zchituvanua("tarifplan.txt");
break;
case'2':
naslidok.zchituvanua("tarifplan2.txt");
break;
case '3':
naslidok.zchituvanua("tarifplan3.txt");
break;
case '4':
naslidok.zchituvanua("tarifplan4.txt");
break;
case '5':
naslidok.zchituvanua("tarifplan5.txt");
break;
}
}
int main()
{
naslidok.setzalishok();
menu();
char znak, znak2;
do
{
cout << "Vvedite znak - " << endl;
cout << "1 - stan rahunku" << endl;
cout << "2 - popovnenya na 20" << endl;
cout << "3 - popovnenya na x" << endl;
cin >> znak;
switch (znak)
{
case '1':
naslidok.aboutabonent();
countsms(naslidok);
break;
case '2':
naslidok.popovnenya();
naslidok.aboutabonent();
break;
case '3':
int x;
cout << "Vvedite x" << endl;
cin >> x;
naslidok.popovnenya(x);
naslidok.aboutabonent();
break;
default: puts("Invalid input"); return 0;
}
cout << "Press # if you want to choose the tarifplan" << endl;
cin >> znak2;
if (znak2 == '#')
{
menu();
naslidok.choosingtf();
}
} while (getch() != 27);
system("pause");
return 0;
}