Inheritance (Need Help to solve this question)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alpha243
    New Member
    • Jan 2015
    • 1

    #1

    Inheritance (Need Help to solve this question)

    Create a class File with fields: name (string), size (in bytes, integer), directory (string). Create a constructor and a method of calculation size (in Mbytes, double). Create also a method of moving file to trash folder (that is, changing directory to value “Trash”). Create a method Info that returns information about the file (string).
    Create a derived class Document with an additional field: program name to handle this file (string, f.e. MS Word, MS Excel, C++Builder). Create a constructor and a method Info with additional data. Create a method of changing program association (that is changing of program name).
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    First forget all the constructors, destructors and assignment operators. They have nothing to do with inheritance. They are just overhead shop-keeping functions.

    Second, draw this hierarchy out on paper. At first put in only the class names and the methods. After all, it is the methods you will use and not the data members. You put those in last so your methods work.

    MAKE SURE YOU ARE TALKING ABOUT INHERITABCE AND NOT POLYMORPHISM!

    After the paper drawing is complete write your C++ classes and methods.

    Lastly add constructors, destructors and assignment operators as needed to remove all compiler errors.

    Remember, a class with a constructor also needs a destructor and an assignment operator.

    Comment

    Working...