Pile Program

This is a discussion on Pile Program within the C++ Programming forums, part of the General Programming Boards category; yeah, you're right. i am new to C++ so that helped out alot. thanks again BMJ...

  1. #16
    Registered User
    Join Date
    Sep 2002
    Posts
    64
    yeah, you're right. i am new to C++ so that helped out alot. thanks again BMJ

  2. #17
    Registered User
    Join Date
    Sep 2002
    Posts
    64
    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?

  3. #18
    Registered User
    Join Date
    Sep 2002
    Posts
    137
    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
    http://uk.geocities.com/ca_chorltonkids

  4. #19
    Registered User
    Join Date
    Sep 2002
    Posts
    64
    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.

    class FlatElement
    {
    private:
    char symbol; // Input Character that represents the FlatElement
    string name; // Name of the FlatElement
    int relativeSize; // Represents the size of this element relative to others
    public:
    FlatElement(void); // Default Constructor
    FlatElement(char , char *, int ); // Constructor with values to initialize the data
    friend class Pile; // Allows Pile member functions to access private data
    };

    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

    const int PIECE_COUNT = 7;
    const FlatElement PIECE[7] = { FlatElement('m', "margarine", 1),
    FlatElement('i', "icing", 2), FlatElement('c', "cottage cheese", 3),
    FlatElement('n', "nuts", 4), FlatElement('w', "Cool Whip", 5)
    FlatElement('k', "Kona coffee", 6), FlatElement('v', "vanilla ice cream", 7) };

    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

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

  5. #20
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    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)

  6. #21
    Registered User
    Join Date
    Sep 2002
    Posts
    64
    hmmm, thanks?

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 01:27 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21