Help with Homework project

Dec 12, 2021 at 4:19am
The current program I am working on for school is as follows:

Define a class named Complex that will represent complex numbers. A
complex number is a number of the form

a+b*i,

where, for our purposes, a and b are integers and i represents sqrt(-1).
In your class, include a constructor that takes two parameters and
initializes a and b to the first and second parameter respectively, and include
a constructor that takes one parameter and initializes a to the value of the
parameter and b to 0. Also include a default constructor that initializes both a
and b to 0. Overload all of the followind operators so that they correctly apply
to the class Complex: ==, +, -, *, >>, and <<.
Using your Complex class, write a program that would let the user input two
complex numbers, and then print out their sum, difference, product, and whether
they are equal to one another.

I was wondering if anyone could help me get started with creating the Complex class as much as they could as I am very bad with working with them. Thanks!
Dec 12, 2021 at 4:25am
You have written some code to get started, haven't you? Show what you have so far.
Dec 12, 2021 at 10:54am
help me get started with creating the Complex class


1
2
3
4
5
6
7
8
class Complex {
public:
	Complex(int a_ = 0, int b_ = 0) : a(a_), b(b_) {}

private:
	int a{}, b{};
};

Dec 13, 2021 at 4:11am
Your post was titled 'Homework project'
may we see the homework project?
Dec 13, 2021 at 4:11pm
seeplus, just a little thing: You don't need "decorators" on the variable names with initializer list syntax.
1
2
3
4
5
6
7
class Complex {
public:
	Complex(int a = 0, int b = 0) : a(a), b(b) {}

private:
	int a{}, b{};
};
Dec 13, 2021 at 4:24pm
@Ganado., I know - but I don't like seeing things like a(a) etc. We never have a member function (including constructors) param name with the same name as a member variable....
Dec 13, 2021 at 4:31pm
I see, understood.
Topic archived. No new replies allowed.