Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need to do the programming in C++ An organization that your little cousin belong

ID: 3843637 • Letter: N

Question

Need to do the programming in C++

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.out", 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. The interface is provided at the end of this assignment. You can use either array or LinkedList as the fundamental data structure.

Deliverables

Part I

- Your design (objected-oriented design). (use diagrams, pseudo-code, 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

Inte rface 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.

Explanation / Answer

The full IMPLEMENTATION of UnsortedType.h class is not provided.
If you provide only the interfaces info, it would be hard to code.

Also, the input ItemType class is not provided.

I have written a simple program for this question.
It may be useful to you.

CODE:
#include <iostream>
#include <map>
using namespace std;

int main(){
int numEntries = 0;
int classId, itemsSold;
cout << "Cookie Sale program" << endl;

std::map<int,int> records;

cout << "Enter the number of Entries" << endl;
cin >> numEntries;

// to load the map with the classId and items sold info.
for(int i=0;i<numEntries;i++){
cout << "Enter class Id and items sold" << endl;
cin >> classId;
cin >> itemsSold;

// check if the classId is already there in the map.
if (records[classId]){
records[classId] = records[classId] + itemsSold;
}
else
records[classId] = itemsSold;
}

std::map<int,int>::iterator it = records.begin();
  
// finding the class which has higher sales.
int max = 0;

for (it=records.begin(); it!=records.end(); ++it){
if (max < it->second){
max = it->second;
classId = it->first;
}
}

cout << "Class with higher sales is " << classId << endl;

}

OUTPUT:
$ g++ box.cpp
$ ./a.out
Cookie Sale program
Enter the number of Entries
7   
Enter class Id and items sold
3 23
Enter class Id and items sold
4 1
Enter class Id and items sold
2 13
Enter class Id and items sold
2 7
Enter class Id and items sold
4 5
Enter class Id and items sold
1 6
Enter class Id and items sold
10 16
Class with higher sales is 3

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote