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
Suppose I have a list of 128 unsorted numbers. If I use the binary search to...
Suppose I have a list of 128 unsorted numbers. If I use the binary search to search it, how many comparisons will I have to do in the worst case, assuming I use a quadratic algorithm to sort the list first.
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...
In Python please! Given an unsorted list (ls) of values (you do not know the datatype)....
In Python please! Given an unsorted list (ls) of values (you do not know the datatype). Only two values appear in the list but they appear many times and are not sorted. Without using any significant additional space (i.e. you cannot copy the list) sort the elements in linear time going through the list only once. For example: Given the list [‘a’, ‘a’, ‘b’, ‘a’, ‘a’, ‘b’, ‘b’, ‘a’] after the function, the list is [‘a’, ‘a’, ‘a’, ‘a’, ‘a’,...
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
I saw an answer for this on another question posted, but I don't think the answer...
I saw an answer for this on another question posted, but I don't think the answer was exactly what I was looking for. Can anyone help guide me in the right direction in regards to this question and its subquestions? Thanks. The proton and electron are particles found to have equal and opposite charges to the precision that the measurements have been made so far. Why is it important that the proton and electron have exactly the same magnitude for...
I know that there are several different answers that has already been posted for this. I...
I know that there are several different answers that has already been posted for this. I have tried all of the options but wanted to see if I can get a correct one that actually works. Assume that a gallon of paint covers about 350 square feet of wall space. Create an application with a main() method that prompts the user for the length, width, and height of a rectangular room. Pass these three values to a method that does...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT