Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ program. An organization that your little cousin belongs to is selling low-fat cookies. If your cousin's class sells more cookies than any other

In C++ program. 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 below. 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

The working Header file is already given below. Just implement a .cpp

#ifndef UNSORTEDTYPE_H

#define UNSORTEDTYPE_H

#define MAX_ITEM 25

using namespace std;

template

class UnsortedType // Declares a class data type

{

public: // 8 public member functions

UnsortedType(); //Default constructor

bool IsFull() const;

int LengthIs() const;

void RetrieveItem(ItemType& item, bool& found);

void InsertItem(ItemType item);

void DeleteItem(ItemType item);

void ResetList();

void GetNextItem(ItemType& item);

private: // 3 private data members

int length;

ItemType info[MAX_ITEM];

int currententPos;

};

template

UnsortedType::UnsortedType()

// Pre: None.

// Post: List is empty.

{

length = 0;

}

template

void UnsortedType::InsertItem(ItemType item)

// Pre: List has been initialized. List is not full.

// item is not in list.

// Post: item is in the list.

{

if (IsFull())

{

cerr << "Array is full." << endl;

return;

}

bool found;

RetrieveItem(item, found);

if (found)

{

cerr << "Item already exit." << endl;

return;

}

info[length] = item;

length++;

}

template

int UnsortedType::LengthIs() const

// Pre: List has been inititalized.

// Post: Function value == ( number of elements in

// list ).

{

return length;

}

template

bool UnsortedType::IsFull() const

// Pre: List has been initialized.

// Post: Function value == ( list is full ).

{

return (length == MAX_ITEM);

}

template

void UnsortedType::RetrieveItem(ItemType& item, bool& found)

// Pre: Key member of item is initialized.

// Post: If found, items key matches an elements key in the list and a copy

// of that element has been stored in item; otherwise, item is unchanged.

{

found = false;

ResetList();

ItemType myItem;

for (int i = 0; i < length; i++)

{

GetNextItem(myItem);

if (myItem.id == item.id)

{

found = true;

item = myItem;

return;

}

}

}

template

void UnsortedType::DeleteItem(ItemType item)

// Pre: items key has been inititalized.

// An element in the list has a key that matches items.

// Post: No element in the list has a key that matches items.

{

ResetList();

ItemType myItem;

for (int i = 0; i < length; i++)

{

GetNextItem(myItem);

if (myItem.id == item.id)

{

length--;

info[i] = info[length];

return;

}

}

}

template

void UnsortedType::ResetList()

// Pre: List has been inititalized.

// Post: currentent position is prior to first element in list.

{

currententPos = -1;

}

template

void UnsortedType::GetNextItem(ItemType& item)

// Pre: List has been initialized. currentent position is defined.

// Element at currentent position is not last in list.

// Post: currentent position is updated to next position.

// item is a copy of element at currentent position.

{

currententPos++;

item = info[currententPos];

}

#endif

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions

Question

9. Use the additive cipher with k=5 to encrypt the plaintext 'MTCS

Answered: 1 week ago