[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

How to develop these class?

A Vehicle class:
• A constructor that allows each attribute of the Vehicle class to be initialised. By using
  default parameters, this constructor should also be able to act as a default constructor;
• A copy constructor;
• An addition operator function that accepts an object of type Journey as a parameter;
• An addition operator function that accepts an object of type FuelPurchase as a parameter;
• A method Print() that displays the manufacturer, model, year of manufacture, total
  kilometers travelled, total fuel costs, total number of services, and fuel economy (litres per
  100 kilometres); and
• Any necessary attributes and methods required to support the program functionality.
A Journey class:
• A constructor that allows each attribute of the Journey class to be initialised; and
• Any necessary attributes and methods required to support the program functionality.
A FuelPurchase class:
• A constructor that allows each attribute of the FuelPurchase class to be initialised; and
• Any necessary attributes and methods required to support the program functionality.
0
lkw714
Asked:
lkw714
  • 7
  • 5
  • 2
  • +3
1 Solution
 
nagvivCommented:
Hi,

Please do not expect us to do your homework. I fthere is any genuine problem, then ask that. We will be able to solve that for you. My suggestion is first attempt these questions and if there is still any problem left then you can ask us. We will try to help you out.

Regards,

G. Nagraj
0
 
unknownmatCommented:
You decide what attributes/data-types need to be in each class, and add them to their respective classes.  Any good beginner book (and if your class book isn't very good, there are tons of the web) should provide you with class syntax/conventions far better than I could.

The only thing that's a bit screwy is the 'addition operator' requirements.  You will need to look up the topic of 'operator overloading'.  If you are coming from a language that doesn't support operator overloading, then this concept will seem very strange at first.  Just toy with it, and it will quickly become very natural.

Hope that helps.

Matt
0
 
kris_rrkCommented:
Hope this helps:  I am not fully answering your question, but I am providing enough for you to proceed from here and learn on your own.

class Vehicle {
public:
   Vehicle(double=0, name="");//ctor
   Vehicle( const Vehicle & );//copy ctor
   Vehicle operator+( const Journey& );//+ operators
   Vehicle opeartor+( const FuelPurchase& );
   void Print() const; //print

private:
   //supply some more relevant attributes!  
   string name;
   double cost;
};

class Journey {
public:
   Journey(...); //do something like above
   //supply some methods that you think will be relevant
private:
   //supply some attributes
};

class FuelPurchase {
public:
   FulePurchase(); //do something like above
   //add some more relevant methods
private:
   //supply some attributes
};
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
fl0ydCommented:
"This is way too easy for me."

If you want to be able to say something like this in the future then put your brains to work and solve the homework yourself.

.f
0
 
kris_rrkCommented:
lkw,

Why haven't you awarded me any points yet?  I think my answer must have been helpful enough.  If I receive no response, I will have to post to community support and/or contact EE for the points.

k
0
 
fl0ydCommented:
Maybe because your code is wrong? Or isn't your compiler choking on the c'tor?

.f
0
 
kris_rrkCommented:
I provided just the header part, not the implementation part.  Giving the implementation would be too much help, unless the original poster has some specific questions.
0
 
fl0ydCommented:
Hmmm, still, my compiler won't eat something like

    Vehicle( double = 0, name = "" );

be it a header or implementation file... Plus, the semi-const-correctness could easily be done properly.

Anyway, I do agree with you that not assigning points is about as disrespectful as breaking EE guidelines, in particular it is prohibited to solve homework.

.f
0
 
kris_rrkCommented:
Oops, i meant
Vehicle(double=0,string="");
0
 
fl0ydCommented:
not quite there yet, but getting closer...

.f
0
 
kris_rrkCommented:
Thank you lkw.  If you have any more questions, please feel free to ask.

K
0
 
lkw714Author Commented:
Could u help me more? Send me your e-mail.
0
 
lkw714Author Commented:
Could u help me more? Send me your e-mail.
0
 
kris_rrkCommented:
Sure.

You can email me at

___x0ngjxv02___{at}___sneakemail___{dot}___com

Completely remove all the underscores and change {at} and {dot} to @ and . respectively.  I may not reply as promptly as you might wish.

K
0
 
fl0ydCommented:
Ok, the correct c'tor should look something like this:

Vehicle( const double d = 0.0f, const std::string str = "" ) : cost( d ), name( str ) {}

Just meant to clearify the "not quite there yet".

.f
0
 
kris_rrkCommented:
fl0yd,

Okay.
0
 
nickbrookewoodCommented:
that is a homework assignment, from a uni course that i am doing..........
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 7
  • 5
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now