Skip to content

Commit

Permalink
Complex class for operator overloading practice
Browse files Browse the repository at this point in the history
  • Loading branch information
bdhirsh committed Aug 24, 2018
1 parent a6acd32 commit 4bd0181
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 8 additions & 1 deletion firstApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.WriteLine("\n---- Stack Example ----\n");
Stack<string> s = new Stack<string>();
s.push("a");
s.push("b");
Expand All @@ -15,6 +15,13 @@ static void Main(string[] args)
Console.WriteLine("popped: " + s.pop());
Console.WriteLine("popped: " + s.pop());
Console.WriteLine("popped: " + s.pop());

Console.WriteLine("\n---- Complex Example ----\n");
Complex a = new Complex(1, 0);
Complex b = new Complex(0, 1);
Complex c = 3*a + 2*b;
Complex c_conj = Complex.conjugate(c);
Console.WriteLine("output: " + c_conj.real() + ", " + c_conj.imag());
}
}
}
8 changes: 4 additions & 4 deletions firstApp/Stack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public int size() {
}


class Entry<T> {
public Entry(T val, Entry<T> next) {
class Entry<S> {
public Entry(S val, Entry<S> next) {
this.val = val;
this.next = next;
}
public T val;
public Entry<T> next;
public S val;
public Entry<S> next;
}

}
Expand Down

0 comments on commit 4bd0181

Please sign in to comment.