adding cs235

This commit is contained in:
dm
2016-04-06 20:46:10 -07:00
parent 8e52ce1982
commit cf99ec6565
178 changed files with 13079 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
//Derek McQuay 647465151 CS 235 Fall 2012 midterm 1
#include "node.h"
node::node(const int exponent, const int coefficient, const char variable, node* next) :
exponent(exponent), coefficient(coefficient), variable(variable), next(next) {}
node::node(const int exponent, const char variable, node* next) : //construtor for when coefficient is assumed 1
exponent(exponent), coefficient(1), variable(variable), next(next) {}
ostream & operator<<(ostream & os, node n) { //used to correctly print out each node
if(n.coefficient == 0) {
os << "";
}
else if(n.coefficient == 1 && n.exponent == 0) {
os << n.coefficient;
}
else if(n.coefficient == -1 && n.exponent == 0) {
os << n.coefficient;
}
else if(n.exponent == 0) {
os << n.coefficient;
}
else if(n.coefficient == -1) {
os << "-" << n.variable << " ^ " << n.exponent;
}
else if(n.coefficient < 0 && n.exponent == 1) {
os << n.coefficient << n.variable;
}
else if(n.coefficient == 1 && n.exponent == 1) {
os << n.variable;
}
else if(n.exponent == 1) {
os << n.coefficient << " " << n.variable;
}
else if(n.coefficient == 1) {
os << n.variable << " ^ " << n.exponent;
}
else {
os << n.coefficient << " " << n.variable << " ^ " << n.exponent;
}
return os;
}