Contains the source code from the course work throughout my undergraduate Computer Engineering degree at Brigham Young University. There is a mixture of Go, Python, C, C++, Java, VHDL, Verilog, Matlab, Bash, Assembly, etc..
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

node.cpp 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //Derek McQuay 647465151 CS 235 Fall 2012 midterm 1
  2. #include "node.h"
  3. node::node(const int exponent, const int coefficient, const char variable, node* next) :
  4. exponent(exponent), coefficient(coefficient), variable(variable), next(next) {}
  5. node::node(const int exponent, const char variable, node* next) : //construtor for when coefficient is assumed 1
  6. exponent(exponent), coefficient(1), variable(variable), next(next) {}
  7. ostream & operator<<(ostream & os, node n) { //used to correctly print out each node
  8. if(n.coefficient == 0) {
  9. os << "";
  10. }
  11. else if(n.coefficient == 1 && n.exponent == 0) {
  12. os << n.coefficient;
  13. }
  14. else if(n.coefficient == -1 && n.exponent == 0) {
  15. os << n.coefficient;
  16. }
  17. else if(n.exponent == 0) {
  18. os << n.coefficient;
  19. }
  20. else if(n.coefficient == -1) {
  21. os << "-" << n.variable << " ^ " << n.exponent;
  22. }
  23. else if(n.coefficient < 0 && n.exponent == 1) {
  24. os << n.coefficient << n.variable;
  25. }
  26. else if(n.coefficient == 1 && n.exponent == 1) {
  27. os << n.variable;
  28. }
  29. else if(n.exponent == 1) {
  30. os << n.coefficient << " " << n.variable;
  31. }
  32. else if(n.coefficient == 1) {
  33. os << n.variable << " ^ " << n.exponent;
  34. }
  35. else {
  36. os << n.coefficient << " " << n.variable << " ^ " << n.exponent;
  37. }
  38. return os;
  39. }