CS Electrical And Electronics
@cselectricalandelectronics

Cpp code on Copy Constructor?

All QuestionsCategory: Cpp LanguageCpp code on Copy Constructor?
Anonymous asked 3 years ago
1 Answers
Anonymous answered 3 years ago

Copy Constructor
 

const double CALL_RATE = 1.0;

class Customer {
  int m_id;
  std::string m_name;
  std::string m_phone;
  double m_balance;

  public:
  Customer(int id, std::string name, std::string phone, double balance) {
m_id = id;
m_name = name;
m_phone = phone;
m_balance = balance;
}
Customer(int id, std::string name, std::string phone) {
m_id = id;
m_name = name;
m_phone = phone;
m_balance = 500;
} /*Customer(const Customer& ref) { m_id = ref.m_id; m_name = ref.m_name; m_phone = ref.m_phone; m_balance = ref.m_balance; }*/ void makeCall(int nmins) { m_balance -= nmins * CALL_RATE; } void recharge(double amount) { m_balance += amount; } double getBalance() { return m_balance; } void display() { std::cout << m_id << "," << m_name << "," << m_balance << "\n"; } }; int main() { Customer c1(1001, "Scott", "9800012345", 500.0); c1.makeCall(10); c1.recharge(100); // a1.display(); Customer c2; Customer c3(c1); c3.display(); return 0; };