// A function returning a vector
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

struct fruit {
  string origin;
  double weight;
  int price;
};

vector<fruit> getList(vector<fruit>, string);

int main() {
  int n;
  cout << "How many fruits? ";
  cin >> n;

  // Define a vector whose elemements have type "fruit"
  vector<fruit> f(n);

  for(unsigned int i=0; i<f.size(); i++){
    cout << "Origin of fruit " << i+1 << "? "; cin >> f[i].origin;
    cout << "Price  of fruit " << i+1 << "? "; cin >> f[i].price;
    cout << "Weight of fruit " << i+1 << "? "; cin >> f[i].weight;
    cout << endl;
  }

  // Assign list of fruits from "Asia" to fa
  vector<fruit> fa = getList(f, "Asia");

  cout << "Fruits from Asia:\n";
  for(unsigned int i=0; i<fa.size(); i++){
    cout << fa[i].origin << "\t"
         << fa[i].weight << "\t" << fa[i].price << endl;
  }
}

// Returns a vector of fruits of given origin (source)
vector<fruit> getList(vector<fruit> f, string source){
  fruit x;
  vector<fruit> fr;

  for(unsigned int i=0; i<f.size(); i++){
    if(f[i].origin == source) {
        x.origin = f[i].origin;
        x.weight = f[i].weight;
        x.price  = f[i].weight;
        fr.push_back(x);
    }
  }
  return fr;
}

