Q:

Add operations to read and print Person objects to the code you wrote for the exercises in § 7.1.2 (p. 260)

0

Add operations to read and print Person objects to the code you wrote for the exercises in § 7.1.2 (p. 260).

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <string>
#include <iostream>

struct Person {
  std::string getName() const { return name; }
  std::string getAddress() const { return address; }

  std::string name;
  std::string address;
};

std::istream &read(std::istream &is, Person &rhs) {
  is >> rhs.name >> rhs.address;
  return is;
}

std::ostream &print(std::ostream &os, const Person &rhs) {
  os << rhs.getName() << " " << rhs.getAddress();
  return os;
}

int main() {
  Person p1;
  read(std::cin, p1);
  print(std::cout, p1) << std::endl;

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now