- Code: Select all
int main()
{
RacingData car1, car2, car3, car4, car5, car6;
RacingData danikaTotalData, jeffTotalData, winner;
car1.setData("Danika Patrick", 185, 11, 20);
car2.setData("Danika Patrick", 103, 11, 30);
car3.setData("Danika Patrick", 73, 12, 40);
car4.setData("Jeff Gordon", 155, 10, 10);
car5.setData("Jeff Gordon", 127, 11, 15);
car6.setData("Jeff Gordon", 34, 12, 35);
// Add the data
danikaTotalData = car1 + car2 + car3;
jeffTotalData = car4 + car5 + car6;
Creating a class called RacingData for the overloaded operator I ended up with something like,
- Code: Select all
RacingData RacingData::operator+(const RacingData& RaceSum)const
{
string theName;
int otherScore, otherMinutes, otherSeconds;
RacingData tempVal;
RaceSum.getData(theName, otherScore, otherMinutes, otherSeconds);
tempVal.setData(name, score + otherScore, minutes + otherMinutes, seconds + otherSeconds);
tempVal.getData(theName, otherScore, otherMinutes, otherSeconds);
if (otherSeconds > 59)
{
otherMinutes= otherMinutes + (otherSeconds /60);
otherSeconds = otherSeconds % 60;
tempVal.setData(name, otherScore, otherMinutes, otherSeconds);
}
return tempVal;
I keep getting numbers that are incorrect and Im assuming it has to do with the way I wrote the overloaded operator, but its my first time doing it so I got confused? Can i get some insight on this.




