473,385 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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).
Jan 11 '15 #1
1 1317
weaknessforcats
9,208 Expert Mod 8TB
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.
Jan 12 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Oracle3001 | last post by:
Hi All, I am looking to use SVD to solve an equation of the form Aa = B, where a is 1 row x 11 col A is 2 rows x 11 col B is 2 rows x 1 col I know from the information I am reading I need...
2
by: Nikolay Bogolioubov | last post by:
Anybody knows where can I get a good "intermediate to expert" level C++ questions list. Need about 500 questions. Appreciate any ideas.
7
by: Morten Aune Lyrstad | last post by:
Hi there! I have written this message before, but for some reason it did not appear to show up on the board. If it does, then I have a problem with my newsgroup app, and I apologize for double...
20
by: Steve Jorgensen | last post by:
A while back, I started boning up on Software Engineering best practices and learning about Agile programming. In the process, I've become much more committed to removing duplication in code at a...
4
by: Tim | last post by:
There are a set of clients who need to be notified of certain events. I have used events and delegates (publisher-Subscriber model) for the notification mechanism. All the clients register with...
3
by: lwoods | last post by:
Example: $x=array('a'=>'ant','b'=>'boat'); $s='a'; $y='$s'; echo $x; I want to echo the value of key 'a' by indirectly referencing it via the variable $y. The above is NOT correct, I know.
8
by: Robert | last post by:
Hi! So far I have been doing "inheritance" in Javascript like this: ****** function TestObject(value) { this.value = value; }
3
by: needin4mation | last post by:
The code is taken from the book Professional C#: abstract class GenericCustomer { private string name; public GenericCustomer(string name) { this.name = name; }...
4
by: sip.address | last post by:
Hi there, When creating interfaces and implementations, the usual thing is doing somethign like class Interface { public: virtual void f() = 0; virtual void g() = 0; };
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.