Answer to Question #248855 in C++ for Kumar

Question #248855

Write a program to add two distance object using operator member function.


1
Expert's answer
2021-10-09T06:16:13-0400
#include <iostream>

struct dest {
 double value;
};

struct dest operator+(const struct dest &a, const struct dest &b) {
 return (struct dest) { a.value + b.value };
}

int main() {
 struct dest a = { 4 };
 struct dest b = { 23 };
 struct dest c = a + b;
 std::cout << c.value << std::endl;
 return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS