input streams/ print specific parts of txt file

so I was given an input file where they gave me the following information
#ofentries
fruitname:color, length, width, vitamins\n.
I need to run a program that prints out the name and color of the fruit based on the vitamins the user is searching for.
for example if the user inputs vitamin K
the program has to list all the names and colors of the fruit that contain that certain vitamin they inputed.
how would I achieve that?
Show the first three entries (after #ofentries) in the file.
I'm wondering what vitamins looks like.
Is it just a string of uppercase letters representing the vitamins in the fruit?
Last edited on
Banana:Yellow, 9 ,11,K
Strawberry: Red, 2,5,A
Lemon: Yellow, 3,11,C
Can a fruit contain more than one vitamin? What does that look like in the file?

The basic way to do this program is as follows:

1. Create a class or struct to represent a single fruit. If you don't know what classes are then just define the variables that represent a single fruit.

2. Write a class method (or a function) to read a single fruit from the input.

3. Write a method or function to print out a single fruit.

4. Create a main program that reads the fruits from cin and prints them to cout. Make sure this works correctly!

5. Now the easy part, just add some code to prompt for the desired color and vitamin. After reading each fruit, only print it out if it matches the desired color & vitamin.
Topic archived. No new replies allowed.