Please help me with this problem using c++. Also how could you create the program without having to use header files? input.txt file values: =============== DVD 10.99 DVD 20.21 TV 800.79 DVD 9.98 TV 999.99 MUSIC 3.48 MUSIC 2.29 TV 1029.99 DVD 22.95 MUSIC 3.22 DVD 5.99 input1.txt file values: (used for the example output) =============== DVD 10.99 DVD 20.21 TV 4.0 DVD 9.98 TV 2.0 TV 5.0 TV 22.2 DVD 22.95 DVD 5.99 output.txt (for input1 example) ==================== DVD 70.12 10.99 14.024 TV 33.2 4.5 8.3 MUSIC 0 nan nan You are given an input file called input.txt. Each line has a category; DVD, MUSIC, or TV and an amount for the item. First you will want to read through the file and place the amounts in a vector for each. Choose the appropriate datatype. You will want to calculate a total, mean and median for all categories. The functions should be in a separate CPP called Lab08Utility.cpp file that has a header. Make sure you include the header in the main program. Note: You should include and use standard namespace in the .h and .cpp file. The median function will need to sort the vector. You may include any sorting algorithm you’ve had this semester. The median value is the middle value from a sorted collection. If there are an odd number of values, then the median value is the value in the middle. If there are 5 items, then the median value is at index 2 of the sorted If the count is even, then there are 2 indexes that straddle the middle. Take the average of those 2 for the median. If there are no items in the vector the function should throw an error that will be caught in your main program. If an error is thrown then the median value is “nan” The sort algorithm you use should be turned into an independent function If there are no items in the vector for the mean then it should throw an error Once you’ve calculated the result, write them out separated by tabs to the file output.txt Each category will be on a separate line. This is example output from input1.txt DVD 70.12 10.99 14.024 TV 33.2 4.5 8.3 MUSIC 0 nan nan Remember to close the output file when you are don
Please help me with this problem using c++.
Also how could you create the program without having to use header files?
input.txt file values:
===============
DVD 10.99
DVD 20.21
TV 800.79
DVD 9.98
TV 999.99
MUSIC 3.48
MUSIC 2.29
TV 1029.99
DVD 22.95
MUSIC 3.22
DVD 5.99
input1.txt file values: (used for the example output)
===============
DVD 10.99
DVD 20.21
TV 4.0
DVD 9.98
TV 2.0
TV 5.0
TV 22.2
DVD 22.95
DVD 5.99
output.txt (for input1 example)
====================
DVD 70.12 10.99 14.024
TV 33.2 4.5 8.3
MUSIC 0 nan nan
- You are given an input file called input.txt. Each line has a category; DVD, MUSIC, or TV and an amount for the item. First you will want to read through the file and place the amounts in a
vector for each. Choose the appropriate datatype. - You will want to calculate a total, mean and median for all categories.
- The functions should be in a separate CPP called Lab08Utility.cpp file that has a header. Make sure you include the header in the main program.
Note: You should include <vector> and use standard namespace in the .h and .cpp file.
- The median function will need to sort the vector. You may include any sorting
algorithm you’ve had this semester. The median value is the middle value from a sorted collection. If there are an odd number of values, then the median value is the value in the middle. If there are 5 items, then the median value is at index 2 of the sorted If the count is even, then there are 2 indexes that straddle the middle. Take the average of those 2 for the median.
If there are no items in the vector the function should throw an error that will be caught in your main program. If an error is thrown then the median value is “nan”
- The sort algorithm you use should be turned into an independent function
- If there are no items in the vector for the mean then it should throw an error
- Once you’ve calculated the result, write them out separated by tabs to the file output.txt Each category will be on a separate line.
This is example output from input1.txt
DVD 70.12 10.99 14.024
TV 33.2 4.5 8.3
MUSIC 0 nan nan
- Remember to close the output file when you are done.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 9 images