main.cpp:
#include <iostream>
#include "polynomials.h"
using namespace std;
int main()
{
for (;;)
{
Wx w;
Px p;
Result r;
Polynomial *pointerWx;
Polynomial *pointerPx;
pointerWx=&w;
pointerPx=&p;
pointerWx->gather();
pointerWx->show();
pointerPx->gather();
pointerPx->show();
r.menu(w, p);
r.showResult(w, p);
}
}
polynomials.h:
#include <iostream>
#include <stdio.h>
#include <cstdlib>
using namespace std;
class Polynomial
{
public:
virtual void gather()=0;
virtual void show()=0;
};
class Px;
class Wx;
class Result
{
protected:
string choiceStringNum;
int resultDegree;
int resultHelper;
int choice;
float *resultCoefficients;
public:
void menu(Wx w, Px p);
void addition(Wx w, Px p);
void subtraction(Wx w, Px p);
void showResult(Wx w, Px p);
void isInteger(string &s, int &i);
Result(string="0", int=0, int=0, int=0);
~Result();
};
class Wx :public Polynomial
{
protected:
string degreeStringNum;
int degree;
int helper;
float *coefficients;
public:
virtual void gather();
virtual void show();
void isInteger(string &s, int &i);
friend class Result;
Wx(string="0", int=0, int=0);
~Wx();
};
class Px :public Wx
{
public:
virtual void gather();
virtual void show();
friend class Result;
Px(string="0", int=0, int=0);
~Px();
};
structors.cpp:
#include <iostream>
#include "polynomials.h"
using namespace std;
Wx::Wx(string dNS, int d, int h)
{
degreeStringNum=dNS;
degree=d;
helper=h;
coefficients=new float[d+1];
//cout<<"Wx constructor called"<<endl;
}
Wx::~Wx()
{
delete [] coefficients;
//cout<<"Wx destructor called"<<endl;
}
Px::Px(string dNS, int d, int h)
:Wx(dNS, d, h)
{
coefficients=new float[d+1];
//cout<<"Px constructor called"<<endl;
}
Px::~Px()
{
delete [] coefficients;
//cout<<"Px destructor called"<<endl;
}
Result::Result(string chSN, int rD, int rH, int ch)
{
choiceStringNum=chSN;
resultDegree=rD;
resultHelper=rH;
choice=ch;
resultCoefficients=new float[rD+1];
//cout<<"Result constructor called"<<endl;
}
Result::~Result()
{
delete [] resultCoefficients;
//cout<<"Result destructor called"<<endl;
}
isInteger.cpp:
#include <iostream>
#include "polynomials.h"
#include <ctype.h> // isdigit()
#include <sstream> // stringstream
using namespace std;
void Wx::isInteger(string &s, int &i)
{
int isInt=0;
int decimalCount=0;
bool isIntBool=false;
bool containsSpaces = false;
do
{
getline(cin >> ws, s);
for (int i=0; i<s.size(); i++)
{
if (isspace(s[i]))
containsSpaces=true;
}
if (s[0] == '-')
{
isInt++;
if (s[1]=='0')
isInt=0;
}
if ((s[0]=='0' && isdigit(s[1])))
isInt = 0;
else
{
for (int i=0; i<s.size(); i++)
{
if (isdigit(s[i]))
isInt++;
if (s[i]=='.')
decimalCount++;
}
}
if (decimalCount==1)
isInt=0;
if (isInt==s.size() && containsSpaces==false)
{
stringstream str_stream_object(s);
str_stream_object>>i;
isIntBool=1;
}
else
{
cout<<endl;
if (s==degreeStringNum && i==degree)
cout<<"Degree of polynomial has to be an integer greater than 0, try again: ";
else if (s==choiceStringNum && i==choice)
cout<<"There is no such option, try again: ";
isIntBool=0;
isInt=0;
decimalCount=0;
containsSpaces=false;
}
}
while (isIntBool==0);
}
menu.cpp:
#include <iostream>
#include "polynomials.h"
using namespace std;
void Result::menu(Wx w, Px p)
{
cout<<"Main menu"<<endl;
cout<<"---------------------"<<endl;
cout<<"1.Addition"<<endl;
cout<<"2.Subtraction"<<endl;
cout<<"3.Multiplication"<<endl;
cout<<"4.Division"<<endl;
cout<<"5.Exit"<<endl;
cout<<endl;
cout<<"Choose an operation: ";
isInteger(choiceStringNum, choice);
switch(choice)
{
case 1:
{
cout<<"W(x)+P(x) = ";
addition(w, p);
}
break;
case 2:
{
cout<<"W(x)-P(x) = ";
subtraction(w, p);
}
break;
case 3:
{
}
break;
case 4:
{
}
break;
case 5:
{
cout<<"Goodbye";
exit(0);
}
break;
default:
{
cout<<"There is no such option";
}
}
}
error:
kopia\isInteger.cpp|61|error: 'choiceStringNum' was not declared in this scope|
kopia\isInteger.cpp|61|error: 'choice' was not declared in this scope|
jak moglbym zrobic tak abym mogl wysylac z klasy Result argumenty do funkcji isInteger?