Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Introduction to Computer Science I Project #2 -vector utilization, sorting, and algorithm development Design and implement a computer based solution (program) using vectors for
Introduction to Computer Science I Project #2 -vector utilization, sorting, and algorithm development Design and implement a computer based solution (program) using vectors for the following requirements: 1. Read in a series of sales dollar amounts and cost dollar amounts from a file that are tab separated (tab delimited), and store the amounts in two (2) vectors. 2. Sort both of the vectors from lowest to highest. The price and cost will coincide when sorted. 3. Output the sorted lists of sales and costs to the console window, in two (2) columns right aligned, and the sum for each column. Use "\t", setw(x), and include dollar signs and precision as appropriate. The totals may be computed in the output function. a. EXTRA CREDIT (15 Points): Compute the profit for each sale and output to a third column in the console window along with the sum of the profit. The profits may be computed in the output function. 4. Required functions called from main and included in a header file: (1) opening the input file with error handling (shown below), (2) reading the input and storing the values in vectors, (3) output to the console window. Sort may be called from main using the vector sort function shown below. The function definitions are to be in the header file. 5. Create the input file named "sales_and_cost_amounts.txt" and add the following values in the order that they appear in two (2) columns with a tab between them. The sale price is in the left column and cost is to the right. Use them to compute profit for extra credit. Main shall only have declarations for the variables, stream, and vectors, function calls, and file closing. Lab references: Declaring a vector - page 437 Vector push_back function - page 441 Vector size - page 443 sales_and_cost_amounts.txt - Notepad File Edit Format View Help 29.95 24.26 3.55 3.27 34.70 26.72 12.34 10.61 21.40 17.33 2.67 2.46 33.89 26.10 8.98 8.26 24.99 20.24 18.45 15.87 4.99 4.59 15.95 13.72 NOTE: vectors are passed by reference to change them The vector sort function requires #include , and has two (2) arguments: the beginning and the end as shown here. sort(vectorName.begin(), vectorName.end()); 1
Step by Step Solution
★★★★★
3.54 Rating (147 Votes )
There are 3 Steps involved in it
Step: 1
The detailed answer for the above question is provided below Solution All the functions in the given ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started