Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help writing a C++ code. The instruction as follows: Thank you! Store and print a list of bottles that is part of someone's

I need help writing a C++ code. The instruction as follows:

image text in transcribed

image text in transcribed

image text in transcribed

Thank you!

Store and print a list of bottles that is part of someone's collection. You will get the list of bottles from a text file. I've provided a couple text files for you. We will grade with big.txt. Your text file reading doesn't need to be fancy. The data is space delimited. 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. Don't have big functions or methods. Your classes and structures must: Each have their own.h and.cpp. Only methods that are 1 line may be inline in the.h) Be const correct. Don't underestimate the work of this the first-time round. (It will be easier if you make it a habit and just start const correct.) Your.h must either use #ifndef or #pragma once. If you use #pragma once you must provide a comment that describe how it works and demonstrates that you understand it. Note: Since you are adding.h and.cpp for your classes you will be pushing new files to github. You can do it! You will have at least 1 class to store the information about a single bottle. The information we care about is: 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. To stay const correct you will need getter functions for all the data. Thes functions can be defined in the.h since they will only be a line long. 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. As a hint here is the signature from mine: 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 (see note above about file size.) 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. Note that I said you can do this as a structure. You can also do it as a class with private member data. If you do this, you can get some extra credit because this will be harder. I strongly suggest that you get it to work as a structure before adding the private member data. (Also, I'd suggest moving one piece of data to private at a time to limit your exposure to errors.) Please do this incrementally. In the program, I added comments with most of the steps that I did. My steps are only a suggestion. Your steps will likely be smaller as this is your first time at classes. Just do a small bit and compile and test. Output Here is an example of the output from my program for test.txt. You don't have to copy it exactly. Just be self-documenting and not ugly. Microsoft Visual Studio Debug Console Please enter the input file name including extension : test.txt COLOR CATEGORY AGE VALUE === ===== aqua 105 95 55 amber clear blive black teal cobalt flask bitters syrup medicine ink flask bitters 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Build It For The Real World A Database Workbook

Authors: Wilson, Susan, Hoferek, Mary J.

1st Edition

0073197599, 9780073197593

More Books

Students also viewed these Databases questions