CS Electrical And Electronics
@cselectricalandelectronics

Cpp code on Default Constructor?

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

Default 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() {
m_id = 1001;
m_name = "";
m_phone = "";
m_balance = 100;
}
void makeCall(int nmins) { m_balance -= nmins * CALL_RATE; }
void recharge(double amount) { m_balance += amount; }
double getBalance() { return m_balance; }
void display() {
//print m_id,m_name,m_phone, m_balance
}
};
int main() {
Customer c1(1001, "Scott", 500.0);
c1.makeCall(10);
c1.recharge(100);
c1.display();

Customer c2;
c2.display();
return 0;
};