Click here to Skip to main content
16,006,493 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: ShellExecute and IE Pin
Stephane Rodriguez.30-Mar-03 8:44
Stephane Rodriguez.30-Mar-03 8:44 
GeneralRe: ShellExecute and IE Pin
tinkywinky30-Mar-03 9:10
tinkywinky30-Mar-03 9:10 
GeneralMFC and dynamic button Pin
Sztahoo28-Mar-03 23:00
Sztahoo28-Mar-03 23:00 
GeneralRe: MFC and dynamic button Pin
Brian Shifrin29-Mar-03 2:41
Brian Shifrin29-Mar-03 2:41 
GeneralRe: MFC and dynamic button Pin
Bartosz Bien29-Mar-03 11:12
Bartosz Bien29-Mar-03 11:12 
GeneralSubclass dialog item Pin
John-theKing28-Mar-03 22:33
John-theKing28-Mar-03 22:33 
GeneralRe: Subclass dialog item Pin
PJ Arends29-Mar-03 9:42
professionalPJ Arends29-Mar-03 9:42 
Generaloverloading operators..Plesae help Pin
Tozilla28-Mar-03 21:44
Tozilla28-Mar-03 21:44 
I have many errors when I compiled it. I think it's all from overloading operator. I have so many errors...this is one of them

binary '+' : no operator defined which takes a right-hand operand of type 'class FuelPurchase' (or there is no acceptable conversion. Can anyone fix please this for me?

Here's my coding

Header file of vehicle
<br />
#ifndef VEHICLE_H<br />
#define VEHICLE_H<br />
using namespace std;<br />
<br />
static const int LEN = 25;<br />
<br />
class Vehicle<br />
{ <br />
private:<br />
char name[LEN]; <br />
char model[LEN]; <br />
int year;<br />
int totalcost;<br />
int totallitres; <br />
<br />
public:<br />
Vehicle();<br />
Vehicle(const char *n, char *m, int y);<br />
Vehicle(const Vehicle &r); //copy constructor<br />
Vehicle operator +(const Journey& m) const;<br />
Vehicle operator +(const FuelPurchase& f) const; <br />
print(); <br />
<br />
<br />
};<br />
#endif<br />


source file of Vehicle
<br />
#include <iostream.h><br />
#include <iomanip.h><br />
#include <string.h><br />
#include "vehicle.h"<br />
<br />
using namespace std;<br />
<br />
Vehicle::Vehicle()<br />
{<br />
strcpy(name, "");<br />
strcpy(model, "");<br />
year = 0;<br />
}<br />
<br />
Vehicle::Vehicle(char *n, char *m, int y) <br />
{<br />
strncpy(name, n, LEN);<br />
strncpy(model, m, LEN);<br />
year = y;<br />
}<br />
<br />
Vehicle::Vehicle(const Vehicle &r) //copy constrcutor<br />
{<br />
name = r.name;<br />
model = r.model;<br />
year = r.year;<br />
totalcost = r.totalcost;<br />
totallitres = r.totallitres;<br />
<br />
}<br />
<br />
Vehicle:perator +(const Journey& m); //First additional operator<br />
{<br />
        Vehicle v;<br />
	v.totaldistance = totaldistance + m.distance;<br />
	return (*this);<br />
<br />
} <br />
<br />
Vehicle:perator +(const FuelPurchase& f); //Second additonal operator<br />
{ <br />
	Vehicle v;<br />
	v.totalcost = totalcost + f.cost; <br />
	v.totallitres = totallitres + f.litres; <br />
	return (*this);<br />
<br />
}<br />
<br />
<br />
Vehicle:Print() <br />
{ int distance=0,services=0,cost=0,litres=0; //all new vehicles begins with zero kilometers travelled and zero fuel<br />
double fueleconomy=0, average=0; //Set number of decimal places<br />
cout.setf(ios::fixed);<br />
cout.setf(ios::showpoint);<br />
cout.precision(1);<br />
<br />
cout <<"Vehicle: "<<endl; //Display the manufacturer, model, year of manufacture <br />
cout <<distance<<"km travelled requiring "<<litres<<" litres of fuel at a cost of$"<<cost<<endl;//total kilometers travleed, total fuel costs<br />
if (distance==0)<br />
{ <br />
cout <<"No travel has been recorded yet"<<endl;<br />
cout <<"No fuel has been purchased yet"<<endl;<br />
}<br />
<br />
else<br />
{ <br />
int fueleconomy = (litres/distance)*100; //fuel economy(liters per 100 kilometers)<br />
cout << "This vehicle achieved a fuel economy of "<<fueleconomy<<"litres/100km"<<endl;<br />
int services = distance/100;<br />
cout << "This vehicle should have undergone "<<services<<" service(s)"<<endl; //total number of services<br />
average = cost/litres;<br />
cout << "The average cost of fuel was $ "<<average<<endl;<br />
}<br />
return(0);<br />
}<br />



this si header file for journey
<br />
#ifndef JOURNEY_H<br />
#define JOURNEY_H<br />
<br />
class Journey<br />
{<br />
private:<br />
int distance;<br />
<br />
public:<br />
Journey();<br />
Journey(const int distance);<br />
<br />
};<br />
#endif<br />



this is source file file journey
<br />
#include <iostream><br />
#include "journey.h"<br />
using namespace std;<br />
<br />
Journey::Journey()<br />
{<br />
distance = 0;<br />
}<br />
<br />
Journey::Journey(int distance)<br />
{<br />
distance = d;<br />
}<br />


here's the header file for FuelPurchase
<br />
#ifndef FUELPURCHASE_H<br />
#define FUELPURCHASE_H<br />
<br />
class FuelPurchase<br />
{<br />
private:<br />
int cost;<br />
int litres;<br />
<br />
public:<br />
FuelPurchase();<br />
FuelPurchase(const int c, int l);<br />
<br />
};<br />
#endif<br />



This is source file for FuelPurchase
<br />
#include <iostream.h><br />
#include "fuelpurchase.h"<br />
using namespace std;<br />
<br />
FuelPurchase::FuelPurchase()<br />
{<br />
cost = 0;<br />
litres = 0;<br />
<br />
}<br />
<br />
FuelPurchase::FuelPurchase(int c, int l)<br />
{<br />
<br />
cost = c;<br />
litres = l;<br />
}<br />


Here's the main code...

<br />
#include <iostream><br />
#include <string><br />
<br />
using namespace std;<br />
<br />
#include "Vehicle.h"<br />
#include "FuelPurchase.h"<br />
#include "Journey.h"<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
Vehicle a("BMW", "A6", 2003);<br />
Vehicle b("Toyota", "A100", 2003);<br />
Vehicle c("Mercedes-Benz", "CL600", 2003);<br />
<br />
cout << "Original Statistical:" << endl;<br />
cout << "=====================" << endl;<br />
<br />
a.print();<br />
b.print();<br />
c.print();<br />
<br />
a = a + FuelPurchase(50, 60);<br />
a = a + Journey(150);<br />
a = a + FuelPurchase(12, 15);<br />
<br />
b = b + FuelPurchase(50, 60);<br />
b = b + Journey(250);<br />
b = b + FuelPurchase(22, 22);<br />
<br />
c = c + FuelPurchase(50, 60);<br />
c = c + Journey(350);<br />
c = c + FuelPurchase(50, 40);<br />
<br />
cout << "Final Statistics:" << endl;<br />
cout << "=================" << endl;<br />
<br />
a.print();<br />
b.print();<br />
c.print();<br />
<br />
return(0);<br />
}<br />

GeneralRe: overloading operators..Plesae help Pin
PJ Arends29-Mar-03 10:51
professionalPJ Arends29-Mar-03 10:51 
GeneralRe: overloading operators..Plesae help Pin
Tozilla29-Mar-03 20:42
Tozilla29-Mar-03 20:42 
Questionhow to draw a picture Pin
snollow28-Mar-03 20:33
snollow28-Mar-03 20:33 
AnswerRe: how to draw a picture Pin
Brian Shifrin29-Mar-03 2:48
Brian Shifrin29-Mar-03 2:48 
GeneralRe: how to draw a picture Pin
snollow30-Mar-03 16:19
snollow30-Mar-03 16:19 
Generalwinsock Pin
moraalg28-Mar-03 15:38
moraalg28-Mar-03 15:38 
GeneralRe: winsock Pin
valikac28-Mar-03 16:20
valikac28-Mar-03 16:20 
GeneralRe: winsock Pin
Rickard Andersson2029-Mar-03 10:21
Rickard Andersson2029-Mar-03 10:21 
GeneralRe: winsock Pin
Moak28-Mar-03 17:23
Moak28-Mar-03 17:23 
QuestionHow do I change the ip address of my computer?? Pin
IrishSonic28-Mar-03 15:36
IrishSonic28-Mar-03 15:36 
AnswerRe: How do I change the ip address of my computer?? Pin
moraalg28-Mar-03 15:40
moraalg28-Mar-03 15:40 
GeneralAdding a tab to the output window in vc6 Pin
Martin Slater28-Mar-03 15:06
Martin Slater28-Mar-03 15:06 
GeneralGet Error__ left of '.point' must have class/struct/union type Pin
wow999928-Mar-03 14:26
wow999928-Mar-03 14:26 
GeneralRe: Get Error__ left of '.point' must have class/struct/union type Pin
John R. Shaw28-Mar-03 15:58
John R. Shaw28-Mar-03 15:58 
GeneralCListBox and HSCROLL Pin
Member 12629228-Mar-03 11:48
Member 12629228-Mar-03 11:48 
GeneralRe: CListBox and HSCROLL Pin
Member 12629228-Mar-03 11:56
Member 12629228-Mar-03 11:56 
Generaldecimal fraction conversion Pin
Aaron Knox28-Mar-03 7:59
Aaron Knox28-Mar-03 7:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.