Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cmath>
- using namespace std;
- class NbComplexe
- {
- public:
- NbComplexe();
- NbComplexe(float re, float im);
- NbComplexe(NbComplexe const&);
- ~NbComplexe();
- void input ()
- {
- cout << "Saisir la partie réelle: ";
- cin >> re;
- cout << "Saisir la partie imaginaire: ";
- cin >> im;
- }
- void output ()
- {
- if (im >= 0) { cout << re << "+" << im << "i" << endl; }
- else { cout << re << "-" << abs(im) << "i" << endl; }
- }
- float real() const
- {
- return re;
- }
- float imaginary() const
- {
- return im;
- }
- private:
- float re, im;
- };
- NbComplexe::NbComplexe(void)
- {
- re = 0;
- im = 0;
- }
- NbComplexe::NbComplexe(float real, float imaginary)
- {
- re = real;
- im = imaginary;
- }
- NbComplexe::NbComplexe(NbComplexe const &nb_complexe)
- {
- re = nb_complexe.real();
- im = nb_complexe.imaginary();
- }
- NbComplexe::~NbComplexe()
- {
- }
- int main (int, char**)
- {
- NbComplexe* complexe1 = new NbComplexe();
- complexe1->input();
- complexe1->output();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement