yeah, you're right. i am new to C++ so that helped out alot. thanks again BMJ

09-13-2002

1999grandamse

okay, the code BMJ provided works excellent. HOWEVER, how do i implement this with an array of N size? meaning, the user inputs the array and then it is sorted?? I can't seem to get this working right?

09-13-2002

crag2804

I'd guess you will have to dynamically allocate the memory with malloc and then use the memory as an array. Post the code you can't get to work and we'll nudge you in the right direction

09-13-2002

1999grandamse

i'm getting a headache....okay, maybe i don't need an array of N size. here is the program description. do you think i can define a max number size and it will work okay? take a look...let me know of any other suggestions you may have. i'm having some trouble with this one.

************************************************** **
For this project, you are required to use at least three classes of objects: a class called BadNews to be used to handle exceptions, a class called FlatElement to be used to represent flat things, and a class called Pile which is a container for FlatElements with restricted actions. The overall goal is to produce a program that is able to accept input specifications of Piles of FlatElements and to Standardize and display the resulting Pile. The following Interfaces for the classes are provided to you. You are to write the member functions for the classes and then write a main and a Standardize function to interact with a user at the keyboard. You may use in-line functions for the constructors, if you wish.
class BadNews
{
public:
char bad; // Invalid character from an input stream
BadNews(char ); // Constructor to be used in exception handling
};

The user at the keyboard is expected to specify the contents of a Pile of FlatElements by entering a string of characters in which each character represents a particular kind of FlatElement. If your program were to deal with plastic container lids as FlatElements, a margarine lid might be represented by 'm', a nut container lid by 'n', a cottage cheese lid by 'c', vanilla ice cream by a 'v', etc. So, the entry of the string cnvmn represents lids from cottage cheese, nuts, vanilla ice cream, margarine, and a second nuts lid (the cottage cheese lid is on top of the Pile). An exception should be thrown if an input string contains an inappropriate character, something other that the characters representing particular the FlatElements being used.

FlatElements are things that are relatively flat, for example, coins, books, plastic lids, pancakes, boards, sheets of paper. FlatElements can be placed one on top of another to form Piles of FlatElements. Each has an input representation, symbol, an output representation, name, and a relativeSize. The relativeSize is based on the diameter of the FlatElements; in the case of plastic lids, margarine lids might be size 1, icing container lids size 2, cottage cheese lids size 3, and so on.

class Pile
{
private:
FlatElement store[100]; // Array of FlatElements
int size; // Number of FlatElements in the Pile
public:
Pile (void); // Default constructor
void Input(void); // Reads in a string of characters and builds a
// Pile based on the symbols specified
int Hooofe (const FlatElement &); // Returns the position of the Highest Out Of Order
// FlatElement of the specified FlatElement type
int Looofe (const FlatElement &); // Returns the position of the Lowest Out Of Order
// FlatElement of the specified FlatElement type
int LowestSmaller (const FlatElement &); // Returns the array position of the Lowest
// FlatElement Smaller than the specified one
void Add (const Pile &); // Puts the specified Pile on top of the Pile object
void Flip (int); // Reverses the order of the FlatElements on the
// Pile from the top down to the specified position
void Output(void); // Displays the names from the Pile, top down
};

You are to write the member functions for the three classes. In order to do this, you should define a constant to represent the number of FlatElements you will be working with and an array of FlatElements to represent the particular items that you will be using. For example, if the FlatElements were plastic lids, you might declare

The member functions of Pile will need to use these constants to do their job. By separating these constants from the classes, it is possible to use the same classes with Piles of different kinds of FlatElements. NO FUNCTIONS OTHER THAN THOSE SPECIFIED ABOVE MAY BE PART OF THE PILE CLASS. In fact, you do not even need one of these functions to write the client program described below.

Your program is meant to deal with coins as FlatElements; so, a penny is represented as a 'p', a nickel as 'n', a dime as 'd', a quarter as 'q', a half-dollar as 'h', and a dollar as '$'. So, entry of the string qnpn represents the Pile: quarter, nickel, penny, nickel in which the quarter is on top of the Pile and the second nickel at the bottom. Your program should repeatedly prompt the user at the keyboard to enter the specification of a Pile of coins, read in the specification and form a Pile, add this Pile to the existing Pile, standardize the updated Pile, and display the contents of the accumulating Pile.

To add one Pile to another, place the Pile being added on top of the existing Pile. To standardize a Pile, rearrange its contents so that no FlatElement of a larger relativeSize is higher in the Pile than any FlatElements of a smaller relativeSize. You must write a Standardize function that is part of the client program to do the standardization. Do NOT write Standardize as a member function

************************************************** **

09-13-2002

BMJ

Erm, I'm sure no one here wants to do your homework.

After reading the description, I don't know if what I gave you would even help! However, it's still not very hard ;) (sorry)