Thread: Inheritance and program structure planning please help a newbie

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    14

    Inheritance and program structure planning please help a newbie

    Hello all, I've been away from programming a good few years and am back in school now trying to picked up where I left off. I'm currently in a C++ data structures class, and we're learning about classes and inheritance. Needless to say, these last 2 weeks have been spent reading 100's of pages trying to get up-to-date and rejog my memory. Here's my current challenge:

    I'm to design an energy conservation program which allows the user to keep track of various technologies (categories) which each have a certain number of devices within each technology category.

    For instance, the database always starts out empty. The user has the option to add a new technology through the client. So the user adds the technologies 'Solar' and 'Gas' seperately, and then returns to the main menu and chooses the 'add a device using a particular technology' option.

    Then, for example, they select the 'Solar' category, and add the devices 'CBR 400' and 'YXT 9B' to the Solar category, each with an efficiency rating of 200.4 and 173.3 respectively.

    They keep continuing to add/remove various technogies/and or devices in this same order.

    Now, here's my main concern...is the class implementations.

    Here's a list of the data needed to be kept track of (really pretty simple):


    Technology: (name)
    Devices: (name, efficiency rating)

    Here's the important part...the user can select a menu option that displays all the devices in their sorted efficiency rating, from greatest to least (higher the efficiency rating, the closer to the head of the list it will be placed). So in essence, you want the program to be able to display all the devices (devoid of their technological categories) with their efficiency ratings sorted.

    If I'm using single inheritance, how should I go about doing this?

    We are to keep track of the technologies and devices as an array of trees, which I'm assuming means each technology will be the head of a tree and its devices are its branches, with multiple technologies (trees) being sequentially linked by an array with indexing. But what classes should I use and how should they all relate?

    I'm not sure if I should make 'Technology' class, because all it does is hold the name of the technology to be created, and then make a 'Device' class an inherited class of technology, with two pieces of info (name and efficiency rating). But technically, would a device have an 'is a' relationship with a technology? It doesn't seem right that a 'CBR 400' 'is a' 'Solar.' Or maybe I'm just looking too hard into this.

    I know I'll need some way to store the nodes represented by each device for a double linked list, so should I have a Linked List class with a Node class derived from it? I'm just really struggling with the design portion of this. I already know I'll need public functions for 'add_technology', 'remove_technology (which consequently will also delete every device in its category)', as well as 'add_device' and 'remove_device' and 'sort_device' (sort it into the list as each object is added) as well as 'display_devices.'

    I'm just really confused as to how to start tackling this. Any help would be greatly appreciated as to how you guys would go about doing this single inheritance program efficiently. Not asking for code, just how you would structure your classes and/or functions and/or structs. Any psuedo bone structure code would be awesome. I just want to begin tackling this program Thanks a bunch

  2. #2
    Registered User
    Join Date
    Feb 2005
    Posts
    14
    anyone, please?

    I was thinking of storing the technologies as a class and then creating an array of technologies (with member functions to add and delete a technology) and then having pointers to a double linked list class which has a derived class of device nodes, with member functions to add devices, remove devices (and sort them upon insertion/deletion), and display devices.

    Does this sound logical? Or is there a better way? My only concern is, when I delete a technology, it should also delete all the devices under that technology (which would be using the member function in the node class to delete all the device nodes until there are no more left)...but don't the base classes NOT have access to the derived member classes functions? Isn't it only the other way around?

    Thanks again for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 06-08-2009, 03:03 PM
  2. Replies: 1
    Last Post: 12-30-2007, 10:08 AM
  3. Inheritance and Dynamic Memory Program Problem
    By goron350 in forum C++ Programming
    Replies: 1
    Last Post: 07-02-2005, 02:38 PM
  4. How to write a program as good as possible?
    By jinhao in forum C++ Programming
    Replies: 9
    Last Post: 06-15-2005, 12:59 PM