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 8826531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:09:36+00:00 2026-06-14T07:09:36+00:00

I have code that is supposed to show addition, subtraction, etc. of complex numbers

  • 0

I have code that is supposed to show addition, subtraction, etc. of complex numbers with no input from the user necessary. I have three classes: test.cpp, complex.cpp, and complex.h to run the program, define the constructors and methods, and create a header class respectively. However, when I run my code I get a series of errors that I’ve been trying to figure out for a while now.

complex.h

//complex class definition
#ifndef COMPLEX_H
#define COMPLEX_H


//class complex
class Complex
{
public:
    Complex(); //default no arg constructor
    Complex(double a); //one arg constructor
    Complex(double a, double b); //two arg constructor
    Complex operator+(const Complex &) const; //addition method
    Complex operator-(const Complex &) const; //subtraction method
    Complex operator*(const Complex &) const; //multiplication method
    Complex operator/(const Complex &) const; //division method
    void print() const; //output
private:
    double a; //real number
    double b; //imaginary number
}; //end class Complex

#endif

complex.cpp

#include "stdafx.h"
#include <iostream>
#include "complex.h"
using namespace std;

//no arg constructor
Complex::Complex()
{
    a = 0;
    b = 0;
}

//one arg instructor
Complex::Complex(double real)
{
    a = real;
    b = 0;
}

//two arg constructor
Complex::Complex(double real, double imaginary)
{
    a = real;
    b = imaginary;
}

//addition
Complex Complex::operator+(const Complex &number2) const
{
    return a + number2.a, b + number2.b;
}

//subtraction
Complex Complex::operator-(const Complex &number2) const
{
    return a - number2.a, b - number2.b;
}

//multiplication
Complex Complex::operator*(const Complex &number2) const
{
    return a * number2.a, b * number2.b;
}

//division
Complex Complex::operator/(const Complex &number2) const
{
    return a / number2.a, b / number2.b;
}

//output display for complex number
void Complex::print() const
{
    cout << '(' << a << ", " << b << ')';
}

test.cpp

#include <iostream>
#include <complex>
#include "complex.h"
#include "stdafx.h"
using namespace std;

int main()
{
    Complex b(1.0, 0.0);
    Complex c(3.0, -1.0);

    /*cout << "a: ";
    a.print();

    system ("PAUSE");*/

};

In test right now as the code shows the lower parts are commented out and I have attempted to only call two of the three constructors to see if I can get any of this working.

The errors I receive:

    error C2065: 'Complex' : undeclared identifier
    error C2065: 'Complex' : undeclared identifier
    error C2146: syntax error : missing ';' before identifier 'b'
    error C2146: syntax error : missing ';' before identifier 'c'
    error C3861: 'b': identifier not found  
    error C3861: 'c': identifier not found

I am trying to run this in Visual Studio 2010. Can someone please help?

  • 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-06-14T07:09:38+00:00Added an answer on June 14, 2026 at 7:09 am

    You may facing a problem with stdafx.h issue

    At least you should try to put #include "stdafx.h before every other include
    Or
    you could try to set your project property to not use stdafx.h

    1. right click on project and select Properties
    2. go to C/C++ -> Precompiled Headers 
    3. select "Not Using Precompiled Headers"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that is supposed to return an NSString. Instead it is
I am new to the web development. I have a code that's supposed to
I have a piece of Python code that is supposed to open a new
I have a very simple bit of code that is supposed to capture the
The following code is supposed to find electors that do not have a postal
I have a text input search that is supposed to filter divs based on
I have an iPhone application that is supposed to show images inside a UIScrollView.
On the following page I have a popup that is supposed to show beside
Background I have the following code that is supposed to refresh data when a
I have some code here that is supposed change display: none to display: block

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.