Question

In: Computer Science

I know this qu is posted but I have not got the answer BY unsorted list...

I know this qu is posted but I have not got the answer BY unsorted list using STLl!!

1.(70) An organization that your little cousin belongs to is selling low-fat cookies. If your cousin's class sells more cookies than any other class, the teacher has promised to take the whole class on a picnic. Of course, your cousin volunteered you to keep track of all the sales and determine the winner. Each class has an identification number. Each sales slip has the class identification number and the number of boxes sold.

Input (Note: if you use keyboard for the input, it is ok for this assignment) Here is a sample of the data. (The classes are numbered from 1 through 10.)

Id. Number Boxes Sold

3 23

4 1

2 13

2 7

4 5

1 6

10 16  


Output The following information written on file "boxes", all properly labeled. The total number of boxes sold by each class. The identification number of the winning class. If there is a tie, list all winners.

Data Structures: using class UnsortedType defined in the textbook (chapter 3). The interface is provided as follows or you can include from the STL library. You can use either array or LinkedList as the fundamental data structure. (you need to justify your decision.)

Deliverables

Part I - Your design (objected-oriented design). (use diagrams, or pseudo-code, or CRC card to show your logical level design) 

Part II - A listing of your program (implementation of the program in C++) - A listing of your test plan as input to the program - A listing of the output file

Interface of UnsortedType class:

bool IsFull() const; // Function: Determines whether list is full. // Pre: List has been initialized.
// Post: Function value = (list is full)

int LengthIs() const; // Function: Determines the number of elements in list. // Pre: List has been initialized. // Post: Function value = number of elements in list

void RetrieveItem(ItemType& item, bool& found); // Function: Retrieves list element whose key matches item's // key (if present). // Pre: List has been initialized. // Key member of item is initialized. // Post: If there is an element someItem whose key matches // item's key, then found = true and item is a copy of // someItem; otherwise found = false and item is unchanged. // List is unchanged.

void InsertItem(ItemType item); // Function: Adds item to list. // Pre: List has been initialized. // List is not full. // item is not in list. // Post: item is in list.

void DeleteItem(ItemType item); // Function: Deletes the element whose key matches item's key. // Pre: List has been initialized. // Key member of item is initialized. // One and only one element in list has a key matching // item's key. // Post: No element in list has a key matching item's key.

void ResetList(); // Function: Initializes current position for an iteration // through the list. // Pre: List has been initialized. // Post: Current position is prior to list.

void GetNextItem(ItemType& item); // Function: Gets the next element in list. // Pre: List has been initialized and has not been changed since // last call. // Current position is defined. // Element at current position is not last in list. // Post: Current position is updated to next position. // item is a copy of element at current position.

Solutions

Expert Solution

I will use Array as my data structure as number of classes is fix that is 10 so need to use Linked List.

I am typing the code as well attaching the screenshots. Please refer to the comments to understand the code.

Code:

#include <bits/stdc++.h>
using namespace std;

int main()
{
cout << "Enter id and boxes:" << endl;
int id;
int boxes;
int classes[10] = {0}; // 10 classes initially all have sold 0 boxes;
// take id and number of boxes sold as input
// Type any alphabet or character other than integer to stop taking input
// count boxes sold by each class and store in the array
while (cin >> id)
{
if(id <= 10){
cin >> boxes;
classes[id-1] += boxes; // id -1 as index starts from 0 while class id starts from 1
}else{
cout << "Invalid" << endl; // if id > 10
}
}
// print class id and total boxes sold by them
cout << "id boxes"<< endl;
for(int i = 0; i < 10; i++){
cout << i+1 << " ";
cout << classes[i]<<endl;
}
// finding the maximum boxes sold by any class
int max = 0;
for(int i = 0; i < 10; i++){
if(classes[i] > max){
max = classes[i];
}
}
// printing the name of winners
cout << "winners:" << endl;
for(int i = 0; i < 10; i++){
if(classes[i] == max){
cout << i+1 << endl;
}
}
return 0;
}

Input:

3 23
4 1
2 13
2 7
4 5
1 6
10 16
STOP

Output:

Enter id and boxes:
id boxes
1 6
2 20
3 23
4 6
5 0
6 0
7 0
8 0
9 0
10 16
winners
3

Related Solutions

I posted a question yesteraday and got an answer. There is a second part to the...
I posted a question yesteraday and got an answer. There is a second part to the question Problem 6-4AA Periodic: Alternative cost flows P3 Refer to the information in Problem 6-3A and assume the periodic inventory system is used. Required Compute cost of goods available for sale and the number of units available for sale. Compute the number of units in ending inventory. Compute the cost assigned to ending inventory using (a) FIFO, (b) LIFO, (c) weighted average, and (d)...
I HAVE POSTED THIS TWICE ALREADY AND GOT WRONG ANSWERS. PLS ANSWER ONLY IF SURE IN...
I HAVE POSTED THIS TWICE ALREADY AND GOT WRONG ANSWERS. PLS ANSWER ONLY IF SURE IN AN ELABORATE FORM. Proposition: "Entrepreneurship" is a meaningless phrase of no importance for economics. Support or attack this proposition
PLEASE DO NOT ANSWER THIS IF YOU DO NOT KNOW IT. Last time I posted, someone...
PLEASE DO NOT ANSWER THIS IF YOU DO NOT KNOW IT. Last time I posted, someone literally copied and pasted from an article and it was very difficult to understand. 1) What is meant by Factoring of Accounts Receivables? 2) List 3 advantages of Factoring 3) List 3 disadvantages of Factoring 4) List 3 Factors in the USA. 5) If you are a company that factors your receivables, would you prefer "recourse" or "non-recourse" factoring? Explain your choice.
(I have posted this question three times without any answer! please answer it. I really need...
(I have posted this question three times without any answer! please answer it. I really need the answer) Using openERP open-source (Odoo 10) systems, you will have to build HR & Finance business processes into the system. You will have to build ( a University or any company of your choosing) HR business processes using one of the tool you found interesting. You will have to find out improvements of the process Add the business rules to the processes You...
I have a problem, and I have the answer but I don't know where the solution...
I have a problem, and I have the answer but I don't know where the solution comes from. ( I have to be able to solve these myself so please help me by answering the questions about the problem.) Here is the answer given to me by the professor: What is the density of SF4 vapor at 650 torr and 100 C? 650 torr (1atm/760 Torr)=0.855atm 100C=373K PV=nRT n/v=P/RT= 0.855atm/0.8206l-atm/molek) (373)=0.0279 mole/l M.W. of SF4=108.1 gm/mole Density=mass/volume 0.0279 mole/l(108.1gm/mole) Answer...
I posted this question looking for a new paper not an answer that's already posted on...
I posted this question looking for a new paper not an answer that's already posted on chegg since if someone already turned in that paper it will show as a copied paper... the question is.. write a paper of 300-600 words presenting your analysis of the following topic- Discuss shortages and surpluses and how they re-direct resources
Please answer if you have the correct knowledge becuase this is the second times i posted...
Please answer if you have the correct knowledge becuase this is the second times i posted this question. i was not happy with the last answer. For example , Question d), the answer so short and general, and not answer the qestion properly. Thank you so much. Balance Sheet For Magnificent Homeware Ltd As At 31 March 2018 2018 2017 2016 $(000) $(000) $(000) Current assets Bank - - 1,804 Accounts receivable 5,200 3,250 1,620 Allowance for bad debts (210)...
. The attached file contains the six variables. I have already attempted this answer and got...
. The attached file contains the six variables. I have already attempted this answer and got it wrong. Please ignore the checkmarks. Question Using the information below select all of the variables that are dichotomous (i.e., two categories). QN88 QN33 _SMOKER3 _SLEPTIM1 QN44 _RFBING5 Behavioral Risk Factor Surveillance System (BRFSS 2016) Calculated Variables https://www.cdc.gov/brfss/annual_data/2016/pdf/2016_calculated_variables_version4.pdf Youth Risk Behavior Surveillance System (YRBSS 2015) YRBS Data User's Guide https://www.cdc.gov/healthyyouth/data/yrbs/pdf/2015/2015_yrbs-data-users_guide_smy_combined.pdf
I posted this already and got a terrible response. Direct Method, Reciprocal Method, Overhead Rates Macalister...
I posted this already and got a terrible response. Direct Method, Reciprocal Method, Overhead Rates Macalister Corporation is developing departmental overhead rates based on direct labor hours for its two production departments—Molding and Assembly. The Molding Department employs 24 people, and the Assembly Department employs 84 people. Each person in these two departments works 2,070 hours per year. The production-related overhead costs for the Molding Department are budgeted at $203,000, and the Assembly Department costs are budgeted at $98,000. Two...
i posted this question before , but the answer was totally wrong . i am developing...
i posted this question before , but the answer was totally wrong . i am developing e-commerce website for my project in my school . this testing is not required to testing by code . and i need to fail the table , and example should be related to e-commere website . hi everyone i need your help , actually i trying to develop e commerce website and i have to document the testing for my system in my project...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT