Follow us on FB

Thursday, May 30, 2013

Operator overloading . adding angle and radius ( polar)

#include<iostream>
#include<math.h>
using namespace std;
class polar
{
    private:
        float radius;
        float angle;
    public:
        float getx()
        {
            return radius*cos(angle);
        }
        float gety()
        {
            return radius*sin(angle);
        }
        polar()
        {
            radius=0;
            angle=0;
        }
        polar(float r,float a)
        {
            radius=r;
            angle=a;
        }
        void show()
        {
            cout<<"radius : "<<radius<<endl;
            cout<<"angle : "<<angle<<endl;
        }
        polar operator +(polar p5)
        {
            float x=getx()+p5.getx();
            float y=gety()+p5.gety();
            float r=sqrt(x*x+y*y);
            float a=atan(y/x);
            return polar(r,a);
        }
   
};
int main()
{
    polar p1(5,30),p2(8,60);
    polar p3=p1+p2;
    p3.show();
    system("pause");
}

mind guess game (interesting) in dev c++

#include<iostream>
#include<conio.h>
#include<string>
#include<ctime>
#include<cstdlib>
using namespace std;
int main(){
srand(time(0));
float g,r,l;
char op;
cout<<"\t\t.....M Haseeb Jaffur......."<<endl;
cout<<endl<<"Note:   'y' for next step and 'any no ' for exit game\t"<<endl;
cout<<"\nthink rupees (2 to 100) in your mind "<<endl;
cout<<"\t enter 'y' for next step: ";
cin>>op;
if(op=='y'|| op=='Y'){
   
r=rand()%50;
cout<<endl<<"1 . add my "<<r<<" rupees in your rupees";
g=r;
cout<<"\n\t enter 'y' for next step: ";
cin>>op;
if(op=='y'|| op=='Y')    {
r=rand()%50;
cout<<endl<<"2 . add "<<r<<" rupees of your friend ";
g+=r;
cout<<"\n\tenter 'y' for next step : ";
cin>>op;
if(op=='y' || op=='Y')        {
cout<<endl<<"3 . give half of the total to the mosque";
g/=2;
cout<<"\n\tenter 'y' for next step : ";
cin>>op;
if(op=='y' || op=='Y')
r=rand()%50;            {
cout<<endl<<"4 . give "<<r<<" rupees to a poor man";
g-=r;
cout<<"\n\tenter 'y' for next step : ";
cin>>op;
if(op=='y' || op=='Y')                {
cout<<endl<<"5 . give half of your thinking rupees to a child";
cout<<"\n\tenter 'y' for next step : ";
cin>>op;
if(op=='y' || op=='Y')
r=rand()%5;                    {
cout<<endl<<"6 . remaining rupees divided by 2 "<<endl;
g/=r;
cout<<"\n\tenter 'y' for next step : ";
cin>>op;
if(op=='y' || op=='Y')
r=rand()%50;                        {
cout<<"7 . add "<<r<<" in remaining rupees ";
g+=r;
cout<<"\n\t.....enter 'y' for your solution...... : ";
cin>>op;
if(op=='y' || op=='Y')                            {
cout<<endl<<"\n\t\t...Now your ramaining rupees is : "<<g;
    }}}}}}}}
if(op!='y'&& op!='Y'){
cout<<"...........thank you for visiting.......";
cout<<"\n.........you..have..no...rusult.......";
cout<<"\n*********you can get more fun if you complete the game********"<<endl;
}
system("pause");
}

 

Copyright @ 2013 placeoflearn.