Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to develop these class?

Posted on 2003-03-21
17
Medium Priority
?
207 Views
Last Modified: 2010-04-01
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
Comment
Question by:lkw714
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 2
  • +3
17 Comments
 
LVL 1

Expert Comment

by:nagviv
ID: 8179528
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
 

Expert Comment

by:unknownmat
ID: 8179538
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
 
LVL 1

Accepted Solution

by:
kris_rrk earned 300 total points
ID: 8184738
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 8

Expert Comment

by:fl0yd
ID: 8184761
"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
 
LVL 1

Expert Comment

by:kris_rrk
ID: 8188072
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
 
LVL 8

Expert Comment

by:fl0yd
ID: 8188312
Maybe because your code is wrong? Or isn't your compiler choking on the c'tor?

.f
0
 
LVL 1

Expert Comment

by:kris_rrk
ID: 8188332
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
 
LVL 8

Expert Comment

by:fl0yd
ID: 8188378
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
 
LVL 1

Expert Comment

by:kris_rrk
ID: 8188402
Oops, i meant
Vehicle(double=0,string="");
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 8189316
not quite there yet, but getting closer...

.f
0
 
LVL 1

Expert Comment

by:kris_rrk
ID: 8192502
Thank you lkw.  If you have any more questions, please feel free to ask.

K
0
 

Author Comment

by:lkw714
ID: 8192561
Could u help me more? Send me your e-mail.
0
 

Author Comment

by:lkw714
ID: 8192577
Could u help me more? Send me your e-mail.
0
 
LVL 1

Expert Comment

by:kris_rrk
ID: 8192691
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
 
LVL 8

Expert Comment

by:fl0yd
ID: 8193624
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
 
LVL 1

Expert Comment

by:kris_rrk
ID: 8197908
fl0yd,

Okay.
0
 

Expert Comment

by:nickbrookewood
ID: 8739168
that is a homework assignment, from a uni course that i am doing..........
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question