adding cs235
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
CXXFLAGS= -Wall -g -std=c++0x
|
||||
OBJECTS=main.o node.o polylist.o polyman.o
|
||||
EXE=main
|
||||
|
||||
all: $(EXE)
|
||||
|
||||
|
||||
$(EXE): main.o
|
||||
$(CXX) $(CXXFLAGS) $(OBJECTS) -o $@
|
||||
main.o: main.cpp node.o polylist.o polyman.o
|
||||
polylist.o: polylist.cpp polylist.h
|
||||
polyman.o: polyman.cpp polyman.h
|
||||
node.o: node.cpp node.h
|
||||
|
||||
run: $(EXE)
|
||||
@./$(EXE)
|
||||
|
||||
clean:
|
||||
@rm -vf *.o
|
||||
@rm -vf $(EXE)
|
||||
|
||||
drun: $(EXE)
|
||||
gdb ./$(EXE)
|
||||
|
||||
valgrind: $(EXE)
|
||||
valgrind --tool=memcheck --leak-check=yes ./$(EXE)
|
||||
@@ -0,0 +1,68 @@
|
||||
//YOU MAY NOT MODIFY THIS DOCUMENT
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class PolynomialListInterface
|
||||
{
|
||||
|
||||
public:
|
||||
/*
|
||||
* You must create a Node class that will hold each polynomial segment and will be used to create the
|
||||
* links in your PolynomialList.
|
||||
* Your Node will likely have 3 private variables in addition to a Node * next you may have.
|
||||
* These 3 variables will be for the Coefficient, the Variable, and the Exponent respectively.
|
||||
* i.e. 2x^7
|
||||
* Coefficient = 2
|
||||
* Variable = x
|
||||
* Exponent = 7
|
||||
*/
|
||||
PolynomialListInterface(void){}
|
||||
virtual ~PolynomialListInterface(void){}
|
||||
|
||||
/*
|
||||
insert
|
||||
|
||||
A node with the given term should be inserted at the appropriate spot in the list.
|
||||
A term can be accepted only with Coefficient value > 0, and exponent value non-negative.
|
||||
If the term is invalid, do not add it to the list.
|
||||
i.e. If the given term segment is 3x^5 and your list contains 2x^8, x^4, 11x^2
|
||||
the node should be added after 2x^8. Your updated list should look like 2x^8, 3x^5, x^4, 11x^2.
|
||||
|
||||
*/
|
||||
virtual void insert(string term) = 0;
|
||||
|
||||
/*
|
||||
clear
|
||||
|
||||
Remove all nodes from the list.
|
||||
*/
|
||||
virtual void clear() = 0;
|
||||
|
||||
/*
|
||||
at
|
||||
|
||||
Returns the polynomial of the node at the given index. The list begins at
|
||||
index 0.
|
||||
|
||||
If the given index is out of range of the list, return "invalid";
|
||||
*/
|
||||
virtual string at(int index) = 0;
|
||||
|
||||
/*
|
||||
size
|
||||
|
||||
Returns the number of nodes in the list.
|
||||
*/
|
||||
virtual int size() = 0;
|
||||
|
||||
/*
|
||||
* This function should string together all of the nodes and print out the entire polynomial separated with '+' signs.
|
||||
* If an exponent of 0 exists however, you should print only the Coefficient.
|
||||
* i.e. list of Nodes = (2x^4)->(4x^2)->(3x^1)->(11x^0)
|
||||
* printList() = return "2 x ^ 4 + 4 x ^ 2 + 3 x ^ 1 + 11 x";
|
||||
*/
|
||||
virtual string printList() = 0;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,84 @@
|
||||
//YOU MAY NOT MODIFY THIS DOCUMENT
|
||||
#ifndef POLYNOMIALMANAGERINTERFACE_H_
|
||||
#define POLYNOMIALMANAGERINTERFACE_H_
|
||||
#include "PolynomialListInterface.h"
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class PolynomialManagerInterface {
|
||||
public:
|
||||
PolynomialManagerInterface(){}
|
||||
virtual ~PolynomialManagerInterface(){}
|
||||
|
||||
/*
|
||||
* addLists()
|
||||
* This function goes through the process of adding your two list's together and returning the resulting list.
|
||||
* Like terms should be added together correctly, creating one Node for the final list.
|
||||
* If both of the lists are empty, return an empty list. This list must be sorted in correct polynomial order by degree.
|
||||
* i.e.
|
||||
* (2x^4)->(4x^2)->(3x^1)->(11x^0), not (2x^4)->(3x^1)->(11x^0)->(4x^2) or anything else.
|
||||
*/
|
||||
virtual PolynomialListInterface * addLists() = 0;
|
||||
|
||||
/*
|
||||
* subtractLists()
|
||||
* This function goes through the process of subtracting your list two from your list one and returning the resulting list.
|
||||
* Like terms should be subtracted correctly, creating one Node for the final list. If a resulting coefficient is 0, that node should be removed.
|
||||
* If both of the lists are empty, return an empty list. This list must be sorted in correct polynomial order by degree.
|
||||
* i.e.
|
||||
* (2x^4)->(4x^2)->(3x^1)->(11x^0), not (2x^4)->(3x^1)->(11x^0)->(4x^2) or anything else.
|
||||
*/
|
||||
virtual PolynomialListInterface * subtractLists() = 0;
|
||||
|
||||
/*
|
||||
* fillListOne(string term)
|
||||
* This adds a single term at a time.
|
||||
* This function will be called many times while your first list is being filled.
|
||||
* You should add the new term at the appropriate spot in the list
|
||||
* which may involve adding it to an existing polynomial list, the list should be ordered by degrees.
|
||||
* All segments will have at least a variable and an exponent, however the Coefficient may be an implied 1.
|
||||
* i.e. x^6 is valid, but 2x is not.
|
||||
* If the term is not valid, it should not be added to the list.
|
||||
*
|
||||
*/
|
||||
virtual void fillListOne(string term) = 0;
|
||||
|
||||
/*
|
||||
* fillListTwo(string term)
|
||||
* This adds a single term at a time.
|
||||
* This function will be called many times while your second list is being filled.
|
||||
* You should add the new term at the appropriate spot in the list
|
||||
* which may involve adding it to an existing polynomial list, the list should be ordered by degrees.
|
||||
* All segments will have at least a variable and an exponent, however the Coefficient may be an implied 1.
|
||||
* i.e. x^6 is valid, but 2x is not.
|
||||
* If the term is not valid, it should not be added to the list.
|
||||
*/
|
||||
virtual void fillListTwo(string term) = 0;
|
||||
|
||||
/*
|
||||
* clearListOne()
|
||||
* This function should empty your first list entirely.
|
||||
*/
|
||||
virtual void clearListOne() = 0;
|
||||
|
||||
/*
|
||||
* clearListTwo()
|
||||
* This function should empty your second list entirely.
|
||||
*/
|
||||
virtual void clearListTwo() = 0;
|
||||
|
||||
/*
|
||||
* getListOne()
|
||||
* Returns a pointer to the first list.
|
||||
*/
|
||||
virtual PolynomialListInterface * getListOne() = 0;
|
||||
|
||||
/*
|
||||
* getListTwo()
|
||||
* Returns a pointer to the second list.
|
||||
*/
|
||||
virtual PolynomialListInterface * getListTwo() = 0;
|
||||
};
|
||||
|
||||
#endif /* POLYNOMIALMANAGERINTERFACE_H_ */
|
||||
@@ -0,0 +1,433 @@
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "node.h"
|
||||
#include "polylist.h"
|
||||
#include "polyman.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
//node::node(const int exponent, const int coefficient, const char variable, node* next) :
|
||||
node n(0,0,'x',NULL);
|
||||
node n1(0,1,'x',NULL);
|
||||
node n2(1,0,'x',NULL);
|
||||
node n3(1,1,'x',NULL);
|
||||
node n4(1,'x',NULL);
|
||||
node n5(0,'x',NULL);
|
||||
node n6(1,'x',NULL);
|
||||
|
||||
stringstream s;
|
||||
|
||||
s << n;
|
||||
assert(s.str() == "");
|
||||
s.str("");
|
||||
|
||||
s << n1;
|
||||
assert(s.str() == "1");
|
||||
s.str("");
|
||||
|
||||
s << n2;
|
||||
assert(s.str() == "");
|
||||
s.str("");
|
||||
|
||||
s << n3;
|
||||
assert(s.str() == "x");
|
||||
s.str("");
|
||||
|
||||
string a1 = "1 x ^ 1";
|
||||
vector<string> v = parse_expression(a1);
|
||||
assert(v[0] == "1");
|
||||
assert(v[1] == "x");
|
||||
assert(v[3] == "1");
|
||||
assert(is_valid(v) == true);
|
||||
|
||||
string a2 = "123 g ^ 152";
|
||||
v = parse_expression(a2);
|
||||
assert(is_valid(v) == true);
|
||||
|
||||
string a3 = "a b c";
|
||||
v = parse_expression(a3);
|
||||
assert(is_valid(v) == false);
|
||||
|
||||
string a4 = "";
|
||||
v = parse_expression(a4);
|
||||
assert(is_valid(v) == false);
|
||||
|
||||
string a5 = "1 x";
|
||||
v = parse_expression(a5);
|
||||
assert(is_valid(v) == true);
|
||||
|
||||
string a6 = "x";
|
||||
v = parse_expression(a6);
|
||||
assert(is_valid(v) == true);
|
||||
|
||||
string a7 = "morethanonecharacter";
|
||||
v = parse_expression(a7);
|
||||
assert(is_valid(v) == false);
|
||||
|
||||
string a8 = "$";
|
||||
v = parse_expression(a8);
|
||||
assert(is_valid(v) == false);
|
||||
|
||||
string a9 = "1 & ^ x";
|
||||
v = parse_expression(a9);
|
||||
assert(is_valid(v) == false);
|
||||
|
||||
string b1 = "123 g ^ %";
|
||||
v = parse_expression(b1);
|
||||
assert(is_valid(v) == false);
|
||||
|
||||
string b2 = "1r32 g ^ 152";
|
||||
v = parse_expression(b2);
|
||||
assert(is_valid(v) == false);
|
||||
|
||||
string b3 = "123 ^ 152";
|
||||
v = parse_expression(b3);
|
||||
assert(is_valid(v) == false);
|
||||
|
||||
string b4 = "123 g ^";
|
||||
v = parse_expression(b4);
|
||||
assert(is_valid(v) == false);
|
||||
|
||||
string b5 = "5 x ^ -2";
|
||||
v = parse_expression(b5);
|
||||
assert(is_valid(v) == false);
|
||||
|
||||
polylist p;
|
||||
stringstream sr;
|
||||
|
||||
p.insert("x");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "1");
|
||||
|
||||
p.insert("2 x");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "3");
|
||||
|
||||
p.insert("-5 x");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "-2");
|
||||
|
||||
assert(p.size() == 1);
|
||||
|
||||
p.insert("x ^ 1");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "x + -2");
|
||||
|
||||
assert(p.size() == 2);
|
||||
|
||||
p.insert("x ^ 4");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "x ^ 4 + x + -2");
|
||||
|
||||
|
||||
assert(p.size() == 3);
|
||||
|
||||
p.insert("x ^ 5");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "x ^ 5 + x ^ 4 + x + -2");
|
||||
|
||||
p.insert("x ^ -1");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "x ^ 5 + x ^ 4 + x + -2");
|
||||
|
||||
p.insert("x ^ 4");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "x ^ 5 + 2 x ^ 4 + x + -2");
|
||||
|
||||
p.insert("x ^ 4");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "x ^ 5 + 3 x ^ 4 + x + -2");
|
||||
|
||||
p.insert("x ^ 4");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "x ^ 5 + 4 x ^ 4 + x + -2");
|
||||
|
||||
p.insert("x ^ 5");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "2 x ^ 5 + 4 x ^ 4 + x + -2");
|
||||
|
||||
|
||||
assert(p.size() == 4);
|
||||
|
||||
p.insert("x ^ 1");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "2 x ^ 5 + 4 x ^ 4 + 2 x + -2");
|
||||
|
||||
p.insert("x");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "2 x ^ 5 + 4 x ^ 4 + 2 x + -1");
|
||||
|
||||
p.insert("x ^ 7");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "x ^ 7 + 2 x ^ 5 + 4 x ^ 4 + 2 x + -1");
|
||||
|
||||
p.insert("x ^ -7");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "x ^ 7 + 2 x ^ 5 + 4 x ^ 4 + 2 x + -1");
|
||||
|
||||
p.insert("x ^ 7");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "2 x ^ 7 + 2 x ^ 5 + 4 x ^ 4 + 2 x + -1");
|
||||
|
||||
assert(p.size() == 5);
|
||||
|
||||
p.insert("2 x ^ 3");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "2 x ^ 7 + 2 x ^ 5 + 4 x ^ 4 + 2 x ^ 3 + 2 x + -1");
|
||||
|
||||
|
||||
p.insert("2 x ^ 3");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "2 x ^ 7 + 2 x ^ 5 + 4 x ^ 4 + 4 x ^ 3 + 2 x + -1");
|
||||
|
||||
|
||||
p.insert("2 x ^ 2");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "2 x ^ 7 + 2 x ^ 5 + 4 x ^ 4 + 4 x ^ 3 + 2 x ^ 2 + 2 x + -1");
|
||||
|
||||
p.insert("2 x ^ 7");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "4 x ^ 7 + 2 x ^ 5 + 4 x ^ 4 + 4 x ^ 3 + 2 x ^ 2 + 2 x + -1");
|
||||
|
||||
p.insert("2 x ^ 0");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "4 x ^ 7 + 2 x ^ 5 + 4 x ^ 4 + 4 x ^ 3 + 2 x ^ 2 + 2 x + 1");
|
||||
|
||||
p.insert("-4 x ^ 4");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "4 x ^ 7 + 2 x ^ 5 + 4 x ^ 3 + 2 x ^ 2 + 2 x + 1");
|
||||
|
||||
p.insert("2 x ^ 3");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "4 x ^ 7 + 2 x ^ 5 + 6 x ^ 3 + 2 x ^ 2 + 2 x + 1");
|
||||
|
||||
p.insert("8 x ^ 4");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "4 x ^ 7 + 2 x ^ 5 + 8 x ^ 4 + 6 x ^ 3 + 2 x ^ 2 + 2 x + 1");
|
||||
|
||||
p.insert("2 x ^ -3");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "4 x ^ 7 + 2 x ^ 5 + 8 x ^ 4 + 6 x ^ 3 + 2 x ^ 2 + 2 x + 1");
|
||||
|
||||
p.insert("-1 x ^ 3");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "4 x ^ 7 + 2 x ^ 5 + 8 x ^ 4 + 5 x ^ 3 + 2 x ^ 2 + 2 x + 1");
|
||||
|
||||
p.insert("-2 x ^ 7");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "2 x ^ 7 + 2 x ^ 5 + 8 x ^ 4 + 5 x ^ 3 + 2 x ^ 2 + 2 x + 1");
|
||||
|
||||
p.insert("2 x ^ 9");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "2 x ^ 9 + 2 x ^ 7 + 2 x ^ 5 + 8 x ^ 4 + 5 x ^ 3 + 2 x ^ 2 + 2 x + 1");
|
||||
|
||||
p.insert("-2 x ^ 9");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "2 x ^ 7 + 2 x ^ 5 + 8 x ^ 4 + 5 x ^ 3 + 2 x ^ 2 + 2 x + 1");
|
||||
|
||||
p.insert("10 x ^ 7");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "12 x ^ 7 + 2 x ^ 5 + 8 x ^ 4 + 5 x ^ 3 + 2 x ^ 2 + 2 x + 1");
|
||||
|
||||
p.insert("x");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "12 x ^ 7 + 2 x ^ 5 + 8 x ^ 4 + 5 x ^ 3 + 2 x ^ 2 + 2 x + 2");
|
||||
|
||||
p.insert("x ^ 7");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "13 x ^ 7 + 2 x ^ 5 + 8 x ^ 4 + 5 x ^ 3 + 2 x ^ 2 + 2 x + 2");
|
||||
|
||||
p.insert("-10 x ^ 7");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "3 x ^ 7 + 2 x ^ 5 + 8 x ^ 4 + 5 x ^ 3 + 2 x ^ 2 + 2 x + 2");
|
||||
|
||||
p.insert("10 x");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "3 x ^ 7 + 2 x ^ 5 + 8 x ^ 4 + 5 x ^ 3 + 2 x ^ 2 + 2 x + 12");
|
||||
|
||||
p.insert("-10 x");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "3 x ^ 7 + 2 x ^ 5 + 8 x ^ 4 + 5 x ^ 3 + 2 x ^ 2 + 2 x + 2");
|
||||
|
||||
p.insert("-2 x");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "3 x ^ 7 + 2 x ^ 5 + 8 x ^ 4 + 5 x ^ 3 + 2 x ^ 2 + 2 x");
|
||||
|
||||
p.insert("2 x ^ 0");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "3 x ^ 7 + 2 x ^ 5 + 8 x ^ 4 + 5 x ^ 3 + 2 x ^ 2 + 2 x + 2");
|
||||
|
||||
p.insert("x ^ 3");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "3 x ^ 7 + 2 x ^ 5 + 8 x ^ 4 + 6 x ^ 3 + 2 x ^ 2 + 2 x + 2");
|
||||
|
||||
p.insert("");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "3 x ^ 7 + 2 x ^ 5 + 8 x ^ 4 + 6 x ^ 3 + 2 x ^ 2 + 2 x + 2");
|
||||
|
||||
p.insert("-3 x ^ 7");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "2 x ^ 5 + 8 x ^ 4 + 6 x ^ 3 + 2 x ^ 2 + 2 x + 2");
|
||||
|
||||
p.insert("-2 x ^ 5");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "8 x ^ 4 + 6 x ^ 3 + 2 x ^ 2 + 2 x + 2");
|
||||
|
||||
p.insert("-2 x ^ 2");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "8 x ^ 4 + 6 x ^ 3 + 2 x + 2");
|
||||
|
||||
p.insert("-3 x ^ 7");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "-3 x ^ 7 + 8 x ^ 4 + 6 x ^ 3 + 2 x + 2");
|
||||
|
||||
p.insert("-3 x ^ 7");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "-6 x ^ 7 + 8 x ^ 4 + 6 x ^ 3 + 2 x + 2");
|
||||
|
||||
p.insert("9 x ^ 7");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "3 x ^ 7 + 8 x ^ 4 + 6 x ^ 3 + 2 x + 2");
|
||||
|
||||
p.clear();
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "");
|
||||
|
||||
assert(p.size() == 0);
|
||||
|
||||
p.insert("9 x ^ 7");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "9 x ^ 7");
|
||||
|
||||
assert(p.size() == 1);
|
||||
|
||||
p.clear();
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "");
|
||||
|
||||
assert(p.size() == 0);
|
||||
|
||||
p.insert("x ^ 7");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "x ^ 7");
|
||||
|
||||
p.insert("-x ^ 7");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "");
|
||||
|
||||
p.clear();
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "");
|
||||
|
||||
assert(p.size() == 0);
|
||||
|
||||
p.insert("2 x");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "2");
|
||||
|
||||
p.clear();
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "");
|
||||
|
||||
assert(p.size() == 0);
|
||||
|
||||
p.insert("x");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "1");
|
||||
|
||||
p.remove(0);
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "");
|
||||
|
||||
p.insert("-x");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "-1");
|
||||
|
||||
p.insert("2 x");
|
||||
sr.str("");
|
||||
sr << p.printList();
|
||||
assert(sr.str() == "1");
|
||||
|
||||
node n7(3, -1, 'x',NULL);
|
||||
|
||||
polyman m;
|
||||
m.addLists();
|
||||
m.subtractLists();
|
||||
m.fillListOne("x");
|
||||
m.fillListOne("2 x");
|
||||
m.fillListOne("3 x ^ 3");
|
||||
m.fillListOne("4aqkjx");
|
||||
m.fillListOne("-4 x ^ 323");
|
||||
m.fillListOne("-2 x ^ 400");
|
||||
m.fillListOne("x");
|
||||
m.fillListOne("x");
|
||||
m.fillListOne("x");
|
||||
m.fillListOne("x");
|
||||
m.fillListTwo("-6 x");
|
||||
m.fillListTwo("-4 x ^ 323");
|
||||
m.fillListTwo("-x ^ 3");
|
||||
m.fillListTwo("7 x ^ 8");
|
||||
m.fillListTwo("4 x ^ 3");
|
||||
m.fillListTwo("-x");
|
||||
m.fillListTwo("14 x");
|
||||
m.addLists();
|
||||
m.subtractLists();
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//Derek McQuay 647465151 CS 235 Fall 2012 midterm 1
|
||||
#ifndef __NODE_H__
|
||||
#define __NODE_H__
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class node {
|
||||
public:
|
||||
node(const int, const int, const char, node*);
|
||||
node(const int, const char, node*);
|
||||
int exponent;
|
||||
int coefficient;
|
||||
char variable;
|
||||
node* next;
|
||||
friend ostream & operator<<(ostream & os, node n);
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,438 @@
|
||||
//Derek McQuay 647465151 CS 235 Fall 2012 midterm 1
|
||||
#include "polylist.h"
|
||||
|
||||
polylist::polylist(): head(NULL) {}
|
||||
polylist::~polylist() {clear();}
|
||||
|
||||
void polylist::insert(string term) {
|
||||
vector<string> v = parse_expression(term);
|
||||
if(!is_valid(v)) {
|
||||
return;
|
||||
}
|
||||
if(v.size() == 1) { //expression of the form x
|
||||
if(v[0][0] == '-') {
|
||||
insertTail(0, -1, v[0][1]);
|
||||
}
|
||||
else {
|
||||
insertTail(0, 1, v[0][0]);
|
||||
}
|
||||
}
|
||||
if(v.size() == 2) { // expresion of the form 2 x
|
||||
int exp = atoi(v[0].c_str());
|
||||
insertTail(0, exp, v[1][0]);
|
||||
}
|
||||
if(v.size() == 3) { // expression of the form x ^ 4
|
||||
int exp = atoi(v[2].c_str());
|
||||
int after_exp = 0;
|
||||
if(exp == 0) {
|
||||
if(v[0][0] == '-') {
|
||||
insertTail(exp, -1, v[0][0]);
|
||||
}
|
||||
else {
|
||||
insertTail(exp, 1, v[0][0]);
|
||||
}
|
||||
}
|
||||
node* node_ptr = head;
|
||||
while(node_ptr != NULL) {
|
||||
if(node_ptr->exponent <= exp) {
|
||||
after_exp++;
|
||||
break;
|
||||
}
|
||||
after_exp++;
|
||||
node_ptr = node_ptr->next;
|
||||
}
|
||||
string before = at(after_exp - 1);
|
||||
vector<string> previous_vector = parse_expression(before);
|
||||
if(previous_vector.size() == 1) {
|
||||
if(node_ptr == head) {
|
||||
if(node_ptr == head && size() == 0) {
|
||||
if(v[0][0] == '-') {
|
||||
insertHead(exp, -1, v[0][0]);
|
||||
}
|
||||
else {
|
||||
insertHead(exp, 1, v[0][0]);
|
||||
}
|
||||
}
|
||||
else if(node_ptr->exponent == exp) {
|
||||
node_ptr->coefficient += 1;
|
||||
if(node_ptr->coefficient == 0) {
|
||||
remove(exp);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(v[0][0] == '-') {
|
||||
insertHead(exp, -1, v[0][1]);
|
||||
}
|
||||
else {
|
||||
insertHead(exp, 1, v[0][0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
node_ptr->coefficient += 1;
|
||||
if(node_ptr->coefficient == 0) {
|
||||
remove(exp);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(previous_vector.size() == 2) {
|
||||
if(v[0][0] == '-') {
|
||||
insertHead(exp, -1, v[0][1]);
|
||||
}
|
||||
else {
|
||||
insertHead(exp, 1, v[0][0]);
|
||||
}
|
||||
}
|
||||
if(previous_vector.size() == 3) {
|
||||
int insertionNodeExponent = atoi(previous_vector[2].c_str());
|
||||
if(insertionNodeExponent == exp) {
|
||||
node* node_ptr2 = head;
|
||||
while(node_ptr2 != NULL) {
|
||||
if(node_ptr2->exponent == exp) {
|
||||
if(v[0][0] == '-') {
|
||||
node_ptr2->coefficient -= 1;
|
||||
}
|
||||
else {
|
||||
node_ptr2->coefficient += 1;
|
||||
}
|
||||
if(node_ptr2->coefficient == 0) {
|
||||
remove(exp);
|
||||
}
|
||||
}
|
||||
node_ptr2 = node_ptr2->next;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(v[0][0] == '-') {
|
||||
insertAfter(exp, -1, v[0][1], insertionNodeExponent);
|
||||
}
|
||||
else {
|
||||
insertAfter(exp, 1, v[0][0], insertionNodeExponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(previous_vector.size() == 4) {
|
||||
int insertionNodeExponent = atoi(previous_vector[3].c_str());
|
||||
if(insertionNodeExponent == exp) {
|
||||
node* node_ptr2 = head;
|
||||
while(node_ptr2 != NULL) {
|
||||
if(node_ptr2->exponent == exp) {
|
||||
node_ptr2->coefficient += 1;
|
||||
if(node_ptr2->coefficient == 0) {
|
||||
remove(exp);
|
||||
}
|
||||
}
|
||||
node_ptr2 = node_ptr2->next;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(v[0][0] == '-') {
|
||||
insertAfter(exp, -1, v[0][1], insertionNodeExponent);
|
||||
}
|
||||
else {
|
||||
insertAfter(exp, 1, v[0][0], insertionNodeExponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(v.size() == 4) { //expression of the form "2 x ^ 3"
|
||||
int coef = atoi(v[0].c_str());
|
||||
int exp = atoi(v[3].c_str());
|
||||
int after_exp = 0;
|
||||
node* node_ptr = head;
|
||||
if(exp == 0) {
|
||||
insertTail(exp, coef, v[1][0]);
|
||||
return;
|
||||
}
|
||||
while(node_ptr != NULL) {
|
||||
if(node_ptr->exponent <= exp) {
|
||||
break;
|
||||
}
|
||||
after_exp++;
|
||||
node_ptr = node_ptr->next;
|
||||
}
|
||||
string before = at(after_exp - 1);
|
||||
vector<string> previous_vector = parse_expression(before);
|
||||
if(previous_vector.size() == 1) {
|
||||
if(node_ptr == head) {
|
||||
if(node_ptr == head && size() == 0) {
|
||||
insertHead(exp, coef, v[1][0]);
|
||||
}
|
||||
else if(node_ptr->exponent == exp) {
|
||||
node_ptr->coefficient += coef;
|
||||
if(node_ptr->coefficient == 0) {
|
||||
remove(exp);
|
||||
}
|
||||
}
|
||||
else {
|
||||
insertHead(exp, coef, v[1][0]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
node_ptr->coefficient += coef;
|
||||
if(node_ptr->coefficient == 0) {
|
||||
remove(exp);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(previous_vector.size() == 2) {
|
||||
insertHead(exp, coef, v[1][0]);
|
||||
}
|
||||
if(previous_vector.size() == 3) {
|
||||
int insertionNodeExponent = atoi(previous_vector[2].c_str());
|
||||
if(node_ptr->exponent == exp) {
|
||||
node* node_ptr2 = head;
|
||||
while(node_ptr2 != NULL) {
|
||||
if(node_ptr2->exponent == exp) {
|
||||
node_ptr2->coefficient += coef;
|
||||
if(node_ptr2->coefficient == 0) {
|
||||
remove(exp);
|
||||
}
|
||||
}
|
||||
node_ptr2 = node_ptr2->next;
|
||||
}
|
||||
}
|
||||
else{
|
||||
insertAfter(exp, coef, v[1][0], insertionNodeExponent);
|
||||
}
|
||||
}
|
||||
if(previous_vector.size() == 4) {
|
||||
int insertionNodeExponent = atoi(previous_vector[3].c_str());
|
||||
if(node_ptr == NULL) {
|
||||
insertTail(exp, coef, v[1][0]);
|
||||
}
|
||||
else {
|
||||
if(node_ptr->exponent == exp) {
|
||||
node* node_ptr2 = head;
|
||||
while(node_ptr2 != NULL) {
|
||||
if(node_ptr2->exponent == exp) {
|
||||
node_ptr2->coefficient += coef;
|
||||
if(node_ptr2->coefficient == 0) {
|
||||
remove(exp);
|
||||
}
|
||||
}
|
||||
node_ptr2 = node_ptr2->next;
|
||||
}
|
||||
}
|
||||
else {
|
||||
insertAfter(exp, coef, v[1][0], insertionNodeExponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void polylist::clear() {
|
||||
node* node_ptr = head;
|
||||
while(head) {
|
||||
node_ptr = head;
|
||||
head = head->next;
|
||||
delete node_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
string polylist::at(int index) {
|
||||
if(index < 0) {
|
||||
return "invalid";
|
||||
}
|
||||
if(size() <= index) {
|
||||
return "invalid";
|
||||
}
|
||||
node* node_ptr = head;
|
||||
for(int i = 0; i < index; i++){
|
||||
node_ptr = node_ptr->next;
|
||||
}
|
||||
if(head == NULL)
|
||||
return "invalid";
|
||||
stringstream s;
|
||||
s << *node_ptr;
|
||||
return s.str();
|
||||
}
|
||||
|
||||
int polylist::size() {
|
||||
int size_of_list = 0;
|
||||
node* node_ptr = head;
|
||||
while(node_ptr != NULL) {
|
||||
size_of_list++;
|
||||
node_ptr = node_ptr->next;
|
||||
}
|
||||
return size_of_list;
|
||||
}
|
||||
|
||||
string polylist::printList() {
|
||||
stringstream s;
|
||||
if(head == NULL)
|
||||
return "";
|
||||
node* node_ptr = head;
|
||||
while(node_ptr != NULL) {
|
||||
if(node_ptr->next == NULL) {
|
||||
s << *node_ptr;
|
||||
return s.str();
|
||||
}
|
||||
else {
|
||||
s << *node_ptr << " + ";
|
||||
node_ptr = node_ptr->next;
|
||||
}
|
||||
}
|
||||
return s.str();
|
||||
}
|
||||
|
||||
void polylist::remove(int exponent) {
|
||||
node* node_ptr = head;
|
||||
if(node_ptr->exponent == exponent) {
|
||||
node* ptr = head;
|
||||
head = head->next;
|
||||
delete ptr;
|
||||
return;
|
||||
}
|
||||
while(node_ptr != NULL) {
|
||||
if(node_ptr->next == NULL)
|
||||
return;
|
||||
if(node_ptr->next->exponent == exponent) {
|
||||
node* ptr = node_ptr->next;
|
||||
node_ptr->next = node_ptr->next->next;
|
||||
delete ptr;
|
||||
}
|
||||
node_ptr = node_ptr->next;
|
||||
}
|
||||
}
|
||||
|
||||
void polylist::insertHead(int exponent, int coefficient, char variable) {
|
||||
head = new node(exponent, coefficient, variable, head);
|
||||
}
|
||||
|
||||
void polylist::insertTail(int exponent, int coefficient, char variable) {
|
||||
if(head == NULL) {
|
||||
insertHead(exponent, coefficient, variable);
|
||||
return;
|
||||
}
|
||||
node* node_ptr = head;
|
||||
while(node_ptr != NULL) {
|
||||
if(node_ptr->next == NULL) {
|
||||
if(node_ptr->exponent == exponent) {
|
||||
node_ptr->coefficient += coefficient;
|
||||
if(node_ptr->coefficient == 0) {
|
||||
remove(exponent);
|
||||
}
|
||||
}
|
||||
else{
|
||||
node_ptr->next = new node(exponent, coefficient, variable, NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
node_ptr = node_ptr->next;
|
||||
}
|
||||
}
|
||||
|
||||
void polylist::insertAfter(int exponent, int coefficient, char variable, int insertionNodeExponent) {
|
||||
node* node_ptr = head;
|
||||
while(node_ptr != NULL) {
|
||||
if(node_ptr->exponent == insertionNodeExponent) {
|
||||
if(head == node_ptr) {
|
||||
insertHead(exponent, coefficient, variable);
|
||||
}
|
||||
else{
|
||||
node* temp = new node(exponent, coefficient, variable, NULL);
|
||||
temp->next = node_ptr->next;
|
||||
node_ptr->next = temp;
|
||||
}
|
||||
}
|
||||
node_ptr = node_ptr->next;
|
||||
}
|
||||
}
|
||||
|
||||
bool is_valid(vector<string> expression) {
|
||||
if(expression.empty()) { //if expression is size 0
|
||||
return false;
|
||||
}
|
||||
if(expression.size() == 1) { //if expression is size one. only case if "x"
|
||||
if(expression[0][0] == '-') {
|
||||
if(expression[0] == "-x")
|
||||
return true;
|
||||
if(!isalpha(expression[0][1]) or expression[0].size() > 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(!isalpha(expression[0][0]) or expression[0].size() > 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if(expression.size() == 2) { //if expression is size two, only case is of form "2 x"
|
||||
for(unsigned int i = 0; i < expression[0].size(); i++) {
|
||||
if(expression[0][0] != '-') {
|
||||
if(!isdigit(expression[0][i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!isalpha(expression[1][0]) or expression[1].size() > 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if(expression.size() == 3) { //if expression is size three, only case is of form "x ^ 1"
|
||||
if(expression[0][0] == '-') {
|
||||
if(expression[0] == "-x")
|
||||
return true;
|
||||
if(!isalpha(expression[0][1]) or expression[0].size() > 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(!isalpha(expression[0][0]) or expression[0].size() > 1) {
|
||||
return false;
|
||||
}
|
||||
if(expression[1] != "^") {
|
||||
return false;
|
||||
}
|
||||
for(unsigned int i = 0; i < expression[2].size(); i++) {
|
||||
if(!isdigit(expression[2][i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if(expression.size() == 4) { //if expression is size four, only case is of form "1 x ^ 1"
|
||||
for(unsigned int i = 0; i < expression[0].size(); i++) {
|
||||
if(expression[0][0] != '-') {
|
||||
if(!isdigit(expression[0][i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!isalpha(expression[1][0]) or expression[1].size() > 1) {
|
||||
return false;
|
||||
}
|
||||
if(expression[2] != "^") {
|
||||
return false;
|
||||
}
|
||||
for(unsigned int i = 0; i < expression[3].size(); i++) {
|
||||
if(!isdigit(expression[3][i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
vector<string> parse_expression(string expression) { //parses expression with " " being the delimeter
|
||||
vector<string> results;
|
||||
string s;
|
||||
for(unsigned int i = 0; i < expression.length(); i++) {
|
||||
char c = expression[i];
|
||||
if(c != ' ') {
|
||||
s += c;
|
||||
}
|
||||
else {
|
||||
if(s != "") {
|
||||
results.push_back(s);
|
||||
s.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(s != "") {
|
||||
results.push_back(s);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//Derek McQuay 647465151 CS 235 Fall 2012 midterm 1
|
||||
#ifndef __POLYLIST_H__
|
||||
#define __POLYLIST_H__
|
||||
#include "PolynomialListInterface.h"
|
||||
#include "node.h"
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class polylist : public PolynomialListInterface {
|
||||
public:
|
||||
polylist();
|
||||
~polylist();
|
||||
node* head;
|
||||
void insert(string term);
|
||||
void clear();
|
||||
string at(int index);
|
||||
int size();
|
||||
string printList();
|
||||
void remove(int exponent);
|
||||
void insertAfter(int exponent, int coefficient, char value, int insertionNodeExponent);
|
||||
void insertTail(int exponent, int coefficient, char value);
|
||||
void insertHead(int exponent, int coefficient, char value);
|
||||
};
|
||||
vector<string> parse_expression(string expression); //these are included outside of the class because i used them in my test.cpp
|
||||
bool is_valid(vector<string> expression); //and wanted them not to be included in the class
|
||||
#endif
|
||||
@@ -0,0 +1,107 @@
|
||||
//Derek McQuay 647465151 CS 235 Fall 2012 midterm 1
|
||||
#include "polyman.h"
|
||||
|
||||
PolynomialListInterface * polyman::addLists() {
|
||||
node * node_ptr1 = l1.head;
|
||||
node * node_ptr2 = l2.head;
|
||||
polylist l3;
|
||||
stringstream exp;
|
||||
while(node_ptr1 != NULL) {
|
||||
if(node_ptr1->coefficient != 0) {
|
||||
exp << node_ptr1->coefficient;
|
||||
exp << " ";
|
||||
}
|
||||
exp << node_ptr1->variable;
|
||||
if(node_ptr1->exponent != 0) {
|
||||
exp << " ^ ";
|
||||
exp << node_ptr1->exponent;
|
||||
}
|
||||
l3.insert(exp.str());
|
||||
exp.str("");
|
||||
node_ptr1 = node_ptr1->next;
|
||||
}
|
||||
while(node_ptr2 != NULL) {
|
||||
if(node_ptr2->coefficient != 0) {
|
||||
exp << node_ptr2->coefficient;
|
||||
exp << " ";
|
||||
}
|
||||
exp << node_ptr2->variable;
|
||||
if(node_ptr2->exponent != 0) {
|
||||
exp << " ^ ";
|
||||
exp << node_ptr2->exponent;
|
||||
}
|
||||
l3.insert(exp.str());
|
||||
exp.str("");
|
||||
node_ptr2 = node_ptr2->next;
|
||||
}
|
||||
polylist * p = NULL;
|
||||
p = &l3;
|
||||
return p;
|
||||
}
|
||||
|
||||
PolynomialListInterface * polyman::subtractLists() {
|
||||
node * node_ptr1 = l1.head;
|
||||
node * node_ptr2 = l2.head;
|
||||
polylist l3;
|
||||
stringstream exp;
|
||||
while(node_ptr1 != NULL) {
|
||||
if(node_ptr1->coefficient != 0) {
|
||||
exp << node_ptr1->coefficient;
|
||||
exp << " ";
|
||||
}
|
||||
exp << node_ptr1->variable;
|
||||
if(node_ptr1->exponent != 0) {
|
||||
exp << " ^ ";
|
||||
exp << node_ptr1->exponent;
|
||||
}
|
||||
l3.insert(exp.str());
|
||||
exp.str("");
|
||||
node_ptr1 = node_ptr1->next;
|
||||
}
|
||||
while(node_ptr2 != NULL) {
|
||||
if(node_ptr2->coefficient != 0) {
|
||||
node_ptr2->coefficient = node_ptr2->coefficient * -1; // will cause it to be subtracting
|
||||
exp << node_ptr2->coefficient;
|
||||
exp << " ";
|
||||
}
|
||||
exp << node_ptr2->variable;
|
||||
if(node_ptr2->exponent != 0) {
|
||||
exp << " ^ ";
|
||||
exp << node_ptr2->exponent;
|
||||
}
|
||||
l3.insert(exp.str());
|
||||
exp.str("");
|
||||
node_ptr2 = node_ptr2->next;
|
||||
}
|
||||
polylist * p = NULL;
|
||||
p = &l3;
|
||||
return p;
|
||||
}
|
||||
|
||||
void polyman::fillListOne(string term) {
|
||||
l1.insert(term);
|
||||
}
|
||||
|
||||
void polyman::fillListTwo(string term) {
|
||||
l2.insert(term);
|
||||
}
|
||||
|
||||
void polyman::clearListOne() {
|
||||
l1.clear();
|
||||
}
|
||||
|
||||
void polyman::clearListTwo() {
|
||||
l2.clear();
|
||||
}
|
||||
|
||||
PolynomialListInterface * polyman::getListOne() {
|
||||
polylist * p = NULL;
|
||||
p = &l1;
|
||||
return p;
|
||||
}
|
||||
|
||||
PolynomialListInterface * polyman::getListTwo() {
|
||||
polylist * p = NULL;
|
||||
p = &l2;
|
||||
return p;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
//Derek McQuay 647465151 CS 235 Fall 2012 midterm 1
|
||||
#ifndef __POLYMAN_H__
|
||||
#define __POLYMAN_H__
|
||||
#include "PolynomialManagerInterface.h"
|
||||
#include "polylist.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class polyman : public PolynomialManagerInterface {
|
||||
public:
|
||||
polylist l1;
|
||||
polylist l2;
|
||||
PolynomialListInterface * addLists();
|
||||
PolynomialListInterface * subtractLists();
|
||||
void fillListOne(string term);
|
||||
void fillListTwo(string term);
|
||||
void clearListOne();
|
||||
void clearListTwo();
|
||||
PolynomialListInterface * getListOne();
|
||||
PolynomialListInterface * getListTwo();
|
||||
};
|
||||
#endif
|
||||
Reference in New Issue
Block a user