Assignment 3 Complex Calculator


Rate this product

Assignment 3
Complex Calculator
A complex number can be represented in the form a + bi where a and b are real numbers. In this
assignment, only the form a + bi, a – bi, and bi, where a and b are positive real numbers, are
accepted. For instance, 6 + 5i, 6 – 5i, and 5i are acceptable forms. Let’s refer to these as
“standard complex numbers”. In addition, it is possible to have complex number such as 2/3 +
1/2i, which is referred as “non-standard complex number” and represented by [a + bi]/r format
where a and b are non-negative integers and r is a non-zero integer. For instance 2/3 + 1/2i is
formatted as [4 + 3i]/6.
Complex arithmetic consists of addition (‘+’), subtraction (‘-’), multiplication (‘*’), division
(‘/’), and conjugate (‘%’). For example:
(a + bi) + (c + di) = (a + c) + (b + d)i
(a + bi) – (c + di) = (a – c) + (b – d)i
(a + bi) * (c + di) = (ac – bd) + (ad + bc)i
(a + bi) / (c + di) = ((ac + bd) + (bc – ad)i) / (c2 + d2
(a + bi)% = a – bi
Precedence of operators: ‘%’ has the highest precedence. ‘+’ and ‘-’ have the next precedence.
‘*’ and ‘/’ have the lowest precedence. Operator with the same precedence are evaluated in a
left-to-right order.
Your task is to design and implement several classes.
template <class T
class DoublyLinkedList
Node<T* head; //pointer to
the first node of a doubly linked list
Node<T* tail; //pointer to
the last node of a doubly linked list
int size; //size of a doubly
linked list
void addFront(T d); //add a
node at the beginning of a doubly
linked list
void popFront(); //remove a
node at the beginning of a doubly
linked list
class Complex
Complex(int r, int i, int d);
int re; //real part of a
complex number
int im; //imaginary part of a
complex number
int dem; //denominator part of
a complex number
string toString() const;
//Format [re + imi]/dem

void addBack(T d); // add a
node at the end of a doubly linked
void popBack(); // remove a
node at the end of a doubly linked
void addNode(T d, Node<T*
iter); //add a node in general
void deleteNode(T d, Node<T*
iter); //delete a node in general
Node<T* findNode(T d);
//return a pointer to a node in a
doubly linked list and return NULL
int getSize() const; //return
size of a doubly linked list
bool isEmpty() const; //return
true if empty and false otherwise
void displayList()
const;//display a doubly linked list
//Overloading operator for easy
Complex operator+(Complex a, Complex
Complex operator-(Complex a, Complex
Complex operator*(Complex a, Complex
Complex operator/(Complex a, Complex
ostream& operator<< (ostream& stream,
Complex a);
//Find gcd and lcm to reduce fraction
and add fraction
int gcd(int a, int b);
int lcm(int a, int b);
template <class T
class StackDoublyLinkedList : public
void displayStack() const;
//Display a stack
T getTop() const; //return
element at the top of a stack
template <class T
struct Node
T data; //data of a node
Node* prev; //pointer to previous
Node* next; //pointer to next node
All inputs for this assignment consist of algebraic expression of complex numbers and terminate
with an ‘=’ sign. Operands of these expression can be either a positive number or a standard
complex number. You will create a file named expression.txt to store all algebraic expression.
Also, suppose there are no spaces between operands and operators.
Sample input:
22+i*22-i =
Your program will execute all expressions in the expression.txt file and produce a result.txt file
in which contains all calculated answer. The format of each answer is the same as non-standard
complex number.
Sample output:
– Please include the following block at the beginning of your program
Class: CECS 282
Instructor: Minhthong Nguyen
Purpose of the program:
Last updated:
– Comment your code.
– Follow standard style for coding (refer to java docs).
Turn-in all files (header, cpp, and txt) to Dropbox and bring a physical copy of all files (header,
cpp, and txt) when you demo your program.

Open chat
Need help?
Can we help you?