Posts

Showing posts with the label methods

What is default arguments in cpp

What is default arguments in cpp PROGRAM: #include<iostream> using namespace std; class interest{ float p,r,n; public: void setdata( ){ cout<<"\n P: "; cin>>p; cout<<" R: "; cin>>r; cout<<" N: "; cin>>n; calc(p,n,r); calc(p,n);//!uses default arguments } float calc(float p,float n,float r=0.25){ //!default argument cout<<"\n\t\t\t Interset is : "<<(p*r*n); } }; int main(){ interest i; i.setdata(); return 0; }

How to overload function in cpp

Overload Function In cpp PROGRAM: #include<iostream> using namespace std; void sub(float i,float j){ cout<<"\nsub : "<<(i-j); } void sub(int i,int j){ cout<<"\nsub : "<<(i-j); } void add(int i,int j){ cout<<"\nadd :"<<(i+j); } void add(float i,float j){ cout<<"\nadd :"<<(i+j); } int main(){ int a,b,ad; float x,y; cout<<"integer value are : "; cin>>a>>b; cout<<"float value are : "; cin>>x>>y; add(a,b); add(x,y);//!arguments have different data types sub(a,b); sub(x,y);//!!arguments have different data types return 0; }