AbdulFathaah

2 complex numbers C++

Dec 10th, 2023
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. /*program to read and display 2 complex numbers*/
  2. #include<iostream.h>
  3. #include<conio.h>
  4.  
  5. class complex //class declaration
  6. {
  7. private : float real;
  8. float imag;
  9. public : void read();
  10. void display();
  11. };
  12. void complex :: read()
  13. {
  14. cout<<"Enter value for real part: ";
  15. cin>>real;
  16. cout<<"Enter value for imaginary part: ";
  17. cin>>imag;
  18. }
  19. void complex :: display()
  20. {
  21. cout<<real<<"+"<<imag<<"i"<<endl;
  22. }
  23. int main()
  24. {
  25. complex r1,r2;
  26. clrscr();
  27. r1.read();
  28. r1.display();
  29. cout<<"\n";
  30. r2.read();
  31. r2.display();
  32. getch();
  33. return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment