Advertisement
TechOPGOHIL

Untitled

Dec 3rd, 2023
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include<iostream.h>
  2. #include<conio.h>
  3. class gram; //source class
  4. class kilo
  5. {
  6. float x;
  7. public:
  8. kilo()
  9. { x=0; }
  10. kilo(float y)
  11. { x=y; }
  12. void show()
  13. { cout<<"Kilo : "<<x<<endl; }
  14. };
  15. class gram
  16. {
  17. float a;
  18. public:
  19. gram()
  20. { a=0; }
  21. gram(float b)
  22. { a=b; }
  23. void show()
  24. { cout<<"Gram : "<<a<<endl; }
  25. operator kilo() //cast operator in source class
  26. {
  27. float z;
  28. z=(a/1000);
  29. return(z);
  30. }
  31. };
  32. void main()
  33. {
  34. clrscr();
  35. kilo k;
  36. gram g(5750);
  37. g.show();
  38. k=g; //call casting operator
  39. k.show();
  40. getch();
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement