Click here to Skip to main content
13,868,739 members

C / C++ / MFC

 
AnswerRe: problem understanding a functionality of constructor. Pin
Richard MacCutchan27-Mar-18 6:18
protectorRichard MacCutchan27-Mar-18 6:18 
AnswerRe: problem understanding a functionality of constructor. Pin
CPallini27-Mar-18 6:36
mveCPallini27-Mar-18 6:36 
QuestionHackerrank:Down to Zero problem Pin
SrinivasaRamanujan25-Mar-18 11:23
memberSrinivasaRamanujan25-Mar-18 11:23 
AnswerRe: Hackerrank:Down to Zero problem Pin
David Crow25-Mar-18 16:41
memberDavid Crow25-Mar-18 16:41 
QuestionIn type conversion of 2 different classes can i convert both ways ? Pin
Tarun Jha25-Mar-18 6:14
memberTarun Jha25-Mar-18 6:14 
AnswerRe: In type conversion of 2 different classes can i convert both ways ? Pin
Victor Nijegorodov25-Mar-18 9:07
memberVictor Nijegorodov25-Mar-18 9:07 
GeneralRe: In type conversion of 2 different classes can i convert both ways ? Pin
Tarun Jha26-Mar-18 0:26
memberTarun Jha26-Mar-18 0:26 
AnswerRe: In type conversion of 2 different classes can i convert both ways ? Pin
CPallini25-Mar-18 11:50
mveCPallini25-Mar-18 11:50 
#include <iostream>
#include <cmath>
using namespace std;

class Polar;

//====================================================
class Rectangle
{
  float length, bredth;
public:
  Rectangle(){}
  Rectangle(float ,float);

  operator Polar();

  int getLength(){return(length);}
  int getBredth(){return(bredth);}
  void putLength(float x){length = x;}
  void putBredth(float y){bredth = y;}

  void putData(){cout<<"Length : "<<length<<"\tBreadth : "<<bredth<<endl;}
  ~Rectangle(){}
};


//====================================================

class Polar{
  float angle, rad;
public:

  Polar(){}
  Polar(float , float);

  operator Rectangle();

  int getAngle(){return(angle);}
  int getRadius(){return(rad);}
  void putAngle(float a){angle=a;}
  void putRadius(float r){rad = r;}

  void putData(){cout<<"Angle : "<<angle<<"\tRadius : "<<rad<<endl;}
  ~Polar(){}
};

//===========================================================
Rectangle::Rectangle(float x, float y)
{
  length = x;
  bredth = y;
}

Rectangle::operator Polar()
{
  Polar temp;
  float a = atan2(bredth, length), r = sqrt(length*length + bredth*bredth);
  temp.putAngle(a);
  temp.putRadius(r);

  return(temp);
}

//===========================================================
Polar::Polar(float x, float y)
{
  angle = x;
  rad = y;
}
Polar::operator Rectangle()
{
  Rectangle temp;
  float l = rad*cos(angle), b =rad*sin(angle);
  temp.putLength(l);
  temp.putBredth(b);
  return(temp);
}

//===========================================================
int main()
{
  float radians = 120 * M_PI / 180; // convert to radians

  // roundtrip polar->rectangle->polar
  Polar p1(radians, 25);
  p1.putData();

  Rectangle r1 = p1;
  r1.putData();

  Polar p2 = r1;
  p2.putData();

  return 0;
}

GeneralRe: In type conversion of 2 different classes can i convert both ways ? Pin
Tarun Jha26-Mar-18 0:25
memberTarun Jha26-Mar-18 0:25 
GeneralRe: In type conversion of 2 different classes can i convert both ways ? Pin
CPallini26-Mar-18 1:18
mveCPallini26-Mar-18 1:18 
QuestionAdding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha24-Mar-18 9:19
memberTarun Jha24-Mar-18 9:19 
AnswerRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Victor Nijegorodov24-Mar-18 9:35
memberVictor Nijegorodov24-Mar-18 9:35 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha24-Mar-18 11:06
memberTarun Jha24-Mar-18 11:06 
AnswerRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Richard MacCutchan24-Mar-18 22:13
protectorRichard MacCutchan24-Mar-18 22:13 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha25-Mar-18 6:08
memberTarun Jha25-Mar-18 6:08 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Richard MacCutchan25-Mar-18 6:32
protectorRichard MacCutchan25-Mar-18 6:32 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha25-Mar-18 7:37
memberTarun Jha25-Mar-18 7:37 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Richard MacCutchan25-Mar-18 8:16
protectorRichard MacCutchan25-Mar-18 8:16 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha25-Mar-18 9:06
memberTarun Jha25-Mar-18 9:06 
QuestionLinux C++ implementation of ioctl SOLVED Pin
Vaclav_23-Mar-18 9:50
memberVaclav_23-Mar-18 9:50 
AnswerRe: Linux C++ implementation of ioctl Pin
Jochen Arndt25-Mar-18 0:39
mveJochen Arndt25-Mar-18 0:39 
AnswerRe: Linux C++ implementation of ioctl Pin
leon de boer26-Mar-18 17:53
memberleon de boer26-Mar-18 17:53 
GeneralRe: Linux C++ implementation of ioctl Pin
Vaclav_4-Apr-18 6:08
memberVaclav_4-Apr-18 6:08 
QuestionVS2017: Cannot debug Dll's Pin
indrekm23-Mar-18 2:13
memberindrekm23-Mar-18 2:13 
SuggestionRe: VS2017: Cannot debug Dll's Pin
Richard MacCutchan23-Mar-18 2:21
protectorRichard MacCutchan23-Mar-18 2:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.190214.1 | Last Updated 23 Feb 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid