Question: I need help to write a C++ code. Please provide the full code. Thank you! Learning objectives Reviewing Structures Classes Requirements Store and print a
I need help to write a C++ code. Please provide the full code.
Thank you!
Learning objectives Reviewing Structures Classes Requirements Store and print a list of bottles that is part of someones collection. You will get the list of bottles from a text file. (test.txt, big.txt) There is a maximum of 30 records in the file. Make and use a constant for this. You may use the string class for any text variables. Use functions and methods in a logical way. Dont have big functions or methods. Your classes and structures must: Each has their own .h and .cpp. Only methods that are 1 line may be inline (in the .h) Your .h must either use #ifndef or #pragma once. You will have at least 1 class to store the information about a single bottle. The color One word to describe the color. The type One word to describe the type of bottle: i.e. flask, syrup. The age an integer to indicate how old the bottle is. The value a double to indicate how much the bottle is worth. A print method that prints a single bottle. A default constructor that blanks or zeros all the data. A constructor that takes all 4 pieces of data (color, type, age, value) and calls the initialization function below. You will need setters for all your data or a method to initialize a whole bottle. here is the signature:
void init (const string & color, const string & cat, int age, double value);
You will have another class or structure to represent the collection of bottles. You will fill the collection as you read the file and add bottles. It has the following member data. An array for your bottles. It is at most 30 bottles An integer to indicate how many bottles you have at this moment. (So, for example the test.txt file has 7 as the size. A method to provide the total value of the collection. This will simply loop through the array of bottles and sum the values. A method to print the collection. It will also print the count of bottles and the total value.
output example:

text files:

-----------------------------------------------------------------------

copyable txt:
(big)
aqua flask 105 205.50 amber bitters 95 15.00 clear syrup 55 8.80 olive medicine 78 4.25 bisque ink 120 960.50 teal flask 220 2.60 cobalt bitters 60 1.15 aqua flask 105 205.50 amber bitters 95 15.00 clear syrup 55 8.80 olive medicine 78 4.25 bisque ink 120 60.50 teal flask 220 992.60 cobalt bitters 60 1.15 aqua flask 103 205.50 amber bitters 95 15.00 clear syrup 55 8.80 olive medicine 78 4.25 bisque ink 120 60.50 teal flask 220 2.60 cobalt bitters 60 1.15 green flask 107 1000 amber bitters 95 15.00 clear syrup 55 8.80 olive medicine 78 4.25 bisque ink 120 60.50 teal flask 220 2.60 cobalt bitters 60 1.15 cobalt flask 115 215.50 amber bitters 95 915.00
(test)
aqua flask 105 205.50 amber bitters 95 15.00 clear syrup 55 8.80 olive medicine 78 4.25 black ink 120 60.50 teal flask 220 2.60 cobalt bitters 60 1.15
Microsoft Visual Studio Debug Console Please enter the input file name including extension : test.txt COLOR CATEGORY AGE VALUE aqua 105 95 amber ilear olive black teal cobalt flask bitters syrup medicine ink flask bitters 55 78 120 220 205.50 15.00 8.80 4.25 60.50 2.60 1.15 60 There are: 7 bottles. Your collection is worth: 297.80 test - Notepad File Edit Format View Help aqua flask 105 205.50 amber bitters 95 15.00 clear syrup 55 8.80 olive medicine 78 4.25 black ink 120 60.50 teal flask 220 2.60 cobalt bitters 60 1.15 big - Notepad File Edit Format View Help Jaqua flask 105 205.50 amber bitters 95 15.00 clear syrup 55 8.80 olive medicine 78 4.25 bisque ink 120 960.50 teal flask 220 2.60 cobalt bitters 60 1.15 aqua flask 105 205.50 amber bitters 95 15.00 clear syrup 55 8.80 olive medicine 78 4.25 bisque ink 120 60.50 teal flask 220 992.60 cobalt bitters 60 1.15 aqua flask 103 205.50 amber bitters 95 15.00 clear syrup 55 8.80 olive medicine 78 4.25 bisque ink 120 60.50 teal flask 220 2.60 cobalt bitters 60 1.15 green flask 107 1000 amber bitters 95 15.00 clear syrup 55 8.80 olive medicine 78 4.25 bisque ink 120 60.50 teal flask 220 2.60 cobalt bitters 60 1.15 cobalt flask 115 215.50 amber bitters 95 915.00
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
