2

I am trying to read a text file in virtual void BillRecord::ReadCustDetails(ifstream &fin)that contains customer details. Codes works fine but I dont know how to read even the whole address and negative values and store them to private members. I have tried the following code but the output is wrong.

text file:

Phone
Origin
George Carter
24 Dingo St Exeter SA
-0.018
28

Gas
EA
Paul Scott
21 Beach Rd Barham NSW
15.48786
356567

Elect
...

my output:

Origin                         
George
Carter
0
24

Required output:

Origin
George Carter
24 Dingo St Exeter SA
-0.018
28

My program:

  public:
    BillRecord();
    virtual void ReadCustDetails(ifstream &fin);
  private:
    BillType BType;
    string Supplier; // Supplier's name
    string Name, Address; // Customer's name and address
    double BillAmount;// Amount in dollars and cents of this bill            
    int DaysSinceLastReading; // Days since last reading

};

 virtual void BillRecord::ReadCustDetails(ifstream &fin)
 {
        fin >> Supplier;
        getline(fin,Name);
        getline(fin,Address);
        fin >>AccountBalance;
        fin >>BillAmount;
        fin >>DaysSinceLastReading;
        fin >>i;
        DaysSinceLastReading=i;

    //put the code here for reading the customer details part of the file 
record only into the private data members

cout << Supplier<< endl;
cout << Name  << endl;
cout << Address << endl;
cout << BillAmount << endl;
cout << AccountBalance << endl;
}
muzzi
  • 372
  • 2
  • 13

1 Answers1

0

Your code has just minor issues. try to be more specific. what is the real problem other than this code? you must have some issue in other functions. Try to post them in here. I have tried to fix up as much as I could.

void BillRecord::ReadCustDetails(ifstream &fin)
{

fin >> Supplier;
fin.ignore();
getline(fin,Name);
getline(fin,Address);
fin >> BillAmount;
fin >> AccountBalance;
fin >> DaysSinceLastReading;
cout << DaysSinceLastReading;

cout << Supplier << setw(16);
cout << Name     << setw(27);
cout << Address  << setw(15);
cout << BillAmount << setw(14);
cout << AccountBalance     << setw(8);
cout << DaysSinceLastReading  << setw(6);
}
Martin G
  • 17,357
  • 9
  • 82
  • 98
muzzi
  • 382
  • 3
  • 10