Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1019301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:59:27+00:00 2026-05-16T10:59:27+00:00

Here I am trying to implement a class for complex numbers using books and

  • 0

Here I am trying to implement a class for complex numbers using books and the Internet. Here is the code:

#include <iostream>
#include <ostream>
using namespace std;
class  Complex{
    private:
        float re,im;

    public:
        Complex(float x,float y){
            re=x;
            im=y;
        }

        float Re() const{
            re;
        }

        float Im() const {
            return  im;
        }

        Complex&  operator*=(const Complex& rhs){
            float t=Re();
            re = Re()*rhs.Re()-Im()*rhs.Im();

            im = t*rhs.Im()+Im()*rhs.Re();
            return *this;
        }
};

ostream& operator<<(ostream& t,const Complex& c){
    t << c.Re() << " " << c.Im(); 
    return t;
}

int main(){
    Complex s(3.45,23.12);
    return 0;
}

It compiles fine, but I can’t find a way to print the real and imaginary parts of the number on the screen?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:59:28+00:00Added an answer on May 16, 2026 at 10:59 am
    #include <iostream>
    
    // ...
    
    Complex s(3.45,23.12);
    std::cout << s; 
    

    See this answer for why I think using namespace std; is a bad idea.

    Also, I suppose implementing a class for complex numbers is an exercise? Because the standard library already has one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement postfix-expression evaluation, here is my code: #include<iostream> #include<string.h> using
I'm trying to implement a queue using an array. Here is my code: #include
Hello i'm trying to implement an AsynController, here is my code: [NoCache] public class
I am trying to implement form validation using cakephp models. Here are my code
I'm trying to implement my own version of vector class without using iterators. Here
I'm trying to implement std::is_enum . Here is my code so far: template<typename T>
Here is code in which I am trying to implement a queue using linked
I am trying to implement a closest point program. Here is the code: #include
I am trying to implement FactoryBean. Here is my code: public class SkilledEmployee extends
I'm trying to implement a website screen shot class as described here http://www.plentyofcode.com/2007/09/website-screenshot-capture-with-aspnet.html The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.