-
Notifications
You must be signed in to change notification settings - Fork 0
/
Abstraction-example.cpp
64 lines (46 loc) · 1.09 KB
/
Abstraction-example.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include<iostream>
using namespace std;
class Customer{
string name;
int ac, balance;
int age;
public:
Customer(string name , int ac , int balance, int age){
this->name = name;
this->ac = ac;
this->balance = balance;
this->age = age;
}
void deposit(int amount){
if(amount > 0){
balance += amount;
}else{
cout<<"invalid amount"<<endl;
}
}
void updateAge(int age){
if(age >= 0 && age < 100){
this->age = age;
}else{
cout<<"invalid age"<<endl;
}
}
void withdraw(int amount){
if(amount <= balance && amount > 0){
balance -= amount;
}
}
void display(){
cout<<name<<" "<<ac<<" "<<balance<<" "<<age<<""<<endl;
}
};
int main(){
Customer A1("Prashant" , 1 , 1000 , 22);
Customer A2("Navnath" , 2 , 2000 , 22);
Customer A3("Rohit" , 3,3000, 18);
A1.deposit(+10);
A1.display();
A3.display();
A3.updateAge(19);
A3.display();
}