83.6k views
2 votes
Your Community Supported Agriculture (CSA) farm delivers a box of fresh fruits and vegetables to your house once a week. For this Programming Project, define the class Box Of Produce that contains exactly three bundles of fruits or vegetables. You can represent the fruits or vegetables as an array of type string. Add accessor and mutator functions to get or set the fruits or vegetables stored in the array. Also write an output function that displays the complete contents of the box on the console.

Next, write a main function that creates a Box Of Produce with three items randomly selected from this list:
Broccoli Tomato Kiwi Kale Tomatillo.
This list should be stored in a text file that is read in by your program. For now you can assume that the list contains exactly five types of fruits or vegetables. Do not worry if your program randomly selects duplicate produce for the three items.
Next, the main function should display the contents of the box and allow the user to substitute any one of the five possible fruits or vegetables for any of the fruits or vegetables selected for the box.
After the user is done with substitutions output the final contents of the box to be delivered.

User Rozana
by
4.2k points

1 Answer

2 votes

Answer:

C++.

Step-by-step explanation:

class BoxOfProduce {

private:

string fruit_bundles[3][5];

////////////////////////////////////////////////////////////////////////

public:

// Methods 1, 2 and 3

void setFruit(string fruit, int bundle, location) {

self.fruit_bundles[bundle][location] = fruit;

}

string getFruit(int bundle, int location) {

return self.fruit_bundles[bundle][location];

}

void printBundle(int bundle) {

cout<<"Bundle "<<i<<endl;

for (int j = 0; j < 5; j++) {

cout<<fruit_bundles[bundle][j]<<", ";

}

cout<<endl;

}

};

////////////////////////////////////////////////////////////////////////

// Main

int main() {

BoxofProduce box_of_produce1;

// Get fruit names from file and add to box_of_produce1

ifstream myfile("fruitList.text");

int line_number = rand() % 5 + 1;

string fruit;

if (myfile.is_open()) {

for (int i = 1; i <= line_number; i++) {

getline(myfile, fruit);

}

}

box_of_produce1.setFruit(fruit, 1);

// Print contents of bundle 1

box_of_produce.printBundle1(1);

// Left one - Allow the user to substitute any one of the five possible fruits or vegetables for any of the fruits or vegetables selected for the box.

return 0;

}

User Omar Juvera
by
3.9k points