1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
if (ffile.is_open())
{
ffile.close();
}
cout << "Please enter the name of a file to be read" << endl;
getline (cin, filename);
ffile.open (filename);
if (ffile.is_open())
{
while(!ffile.eof())
{
ffile >> type;
if (type == "Residential")
{
ffile >> rent_or_own >> price >> occupation;
getline (ffile, address);
if(ffile.fail()||price < 0)
{
cout << "Error, ignoring bad input " << endl;
ffile.clear();
ffile.ignore(1000, '\n');
}
else
{
Residential* r = new Residential(rent_or_own, price, occupation, address);
properties.push_back(r);
}
}
else if (type == "Commercial")
{
ffile >> rent_or_own >> price >> tax_eligibility >> tax_discount;
getline (ffile, address);
if(ffile.fail()||price < 0)
{
cout << "Error, ignoring bad input " << endl;
ffile.clear();
ffile.ignore(1000, '\n');
}
else
{
Commercial* c = new Commercial(rent_or_own, price, tax_discount, tax_eligibility, address);
properties.push_back(c);
}
}
}
}
else
{
cout << "Error, bad file name" << endl;
}
|