/*******************************************************************************************
07.cpp
    read data into an array of objects, then display them
*******************************************************************************************/
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

class item
    {
    public:
        int part;
        string desc;
        float price;
    };

//prototypes
void readFrom(string file, item list[], const int size, int& count);
void showList(item [], const int count);

void main()
    {
    const int MaxSize = 25;
    item goods[MaxSize];
    int count = 0;

    string filename;
    cout << "What is the file to read: ";
    cin >> filename;

    readFrom(filename, goods, MaxSize, count);

    showList(goods, count);

    return;
    }

void readFrom(string file, item list[], const int size, int& count)
    {
    ifstream fin(file.c_str());

    for (int i = 0; i < size; i++)
        {
        if(fin >> list[i].part >> list[i].desc >> list[i].price)
            count++;
        else
            break;
        }

    return;
    }

void showList(item list[], const int count)
    {
    for (int i = 0; i < count; i++)
        {
        cout << list[i].desc << " (" << list[i].part << ") $" << list[i].price << endl;
        }

    cout << endl;
    return;
    }