Answer to Question #269610 in C++ for Jagan

Question #269610

Develop a C++ program to compare weights of two persons and displays the most weight between two using this pointer.



1
Expert's answer
2021-11-21T17:33:43-0500
#include <iostream>

struct person {
  std::string name;
  double weight;
  struct person(std::string name, double weight) {
    this.name = name;
    this.weight = weight;
  }
};

int main()
{
  struct person *a = new struct person("asdgfdg", 435.435);
  struct person *b = new struct person("fdg", 34.435);
  if (a->weight > b.weight) 
    std::cout << a.name << std::endl;
  if (a->weight < b.weight)
    std::cout << b.name << std::endl;
  if (a.weight == b.weight)
    std::cout << "They are the same weight" << 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