Some important programs part 3
11. Series of Even and Odd Numbers using scope resolution operator:
#include<iostream>
using namespace std;
class EvenOdd
{
private:
int n,i;
public:
void get();
void print();
};
void EvenOdd::get()
{
cout<<"Enter the values of n:"<<endl;
cin>>n;
}
void EvenOdd::print()
{
cout<<"Series of Even Numbers"<<endl;
for(i=0;i<n;i=i+2)
cout<<i<<endl;
cout<<"Series of Odd Numbers"<<endl;
for(i=1;i<=n;i=i+2)
cout<<i<<endl;
}
int main()
{
EvenOdd eo;
eo.get();
eo.print();
return 0;
}
12. This Pointer:
#include<iostream>
using namespace std;
class Temp
{
private:
int a;
public:
void test()
{
this->a=14;
cout<<"Value of a[Using This Pointer is]"<<this->a<<endl;
}
};
int main()
{
Temp t;
t.test();
return 0;
}
13. Unary Operator
#include<iostream>
using namespace std;
class UnaryOPE
{
private:
int p,s;
public:
void get()
{
cout<<"Enter the value of P,S"<<endl;
cin>>p>>s;
}
void operator++()
{
++p;
++s;
}
void display()
{
cout<<"P="<<p<<endl;
cout<<"S="<<s<<endl;
}
};
int main()
{
UnaryOPE we;
we.get();
cout<<"Original value"<<endl;
we.display();
cout<<"Incremented values"<<endl;
++we;
we.display();
return 0;
}
14. New and Delete Operator:
0 Comments