Permalink
Browse files

updated TransferFunction::NicePrintFactors, now it really does its jo…

…b, the ouput is finaly perfectly readable
  • Loading branch information...
1 parent 699ad1d commit 2a3a76f918e26e0215d292fe87253069ca58ec4e @eagle2com committed Feb 23, 2012
View
Binary file not shown.
@@ -0,0 +1 @@
+/*.ods#
@@ -66,8 +66,13 @@ void LiteralElement::Print(void)
char sign_buffer[2];
cout << "(";
- for(LiteralMapIt it = elements.begin(); it != elements.end();it++)
+ for( int i = GetMaxPower();i >= 0;i--)
{
+ LiteralMapIt it = elements.find(i);
+ if(it == elements.end())
+ continue;
+ //for(LiteralMapIt it = elements.begin(); it != elements.end();it++)
+ //{
if(it->first == 0) //power == 0
{
sprintf(var_buffer,"");
@@ -3,6 +3,7 @@
#include <ios>
#include <iostream>
#include <cstdlib>
+#include <cstdio>
#include "LinearSystem.h"
using namespace std;
@@ -42,7 +43,7 @@ void TransferFunction::LoadFromFile(string filename)
exit(1) ;
}
cout << "Opened "<<filename<<endl;
- int n_num, n_denom,max_power;
+ int n_num,max_power;
long double coef;
in_stream >> n_num;
cout << "Found "<<n_num<<" numerator factors"<<endl;
@@ -101,7 +102,6 @@ void TransferFunction::AddDenom(void)
cout<<endl;
}
-
void TransferFunction::PrintFactors(void)
{
cout << "[ ";
@@ -118,16 +118,35 @@ void TransferFunction::NicePrintFactors(void)
cout << endl;
for(int i = 0; i < denominator.size(); i++)
{
- LiteralElement e;
- int index = denominator.size() - i;
- e.Add(new Literal(factors[index*2 - 1],0));
- e.Add(new Literal(factors[index*2 - 2],1));
- e.Print();cout<<"/";denominator[i]->Print();cout <<" + ";
+ cout << "( ";
+ if(factors[i] != 0)
+ {
+ cout << "A"<<i<<".s";
+ }
+ if(factors[i] != 0 && factors[i+1]!= 0)
+ {
+ cout << "+B"<<i;
+ }
+ else if(factors[i] == 0 && factors[i+1]!= 0)
+ {
+ cout << "B"<<i;
+ }
+ cout << " )";
+ cout<<"/";denominator[i]->Print();
+ if(i != denominator.size() -1)
+ cout <<" + ";
+ }
+ cout <<endl;
+ for(int i = 0; i < denominator.size(); i++)
+ {
+ if(factors[i*2] != 0)
+ cout << "A"<<i<<" = "<<factors[i*2]<<endl;
+ if(factors[i*2+1] != 0)
+ cout << "B"<<i<<" = "<<factors[i*2+1]<<endl;
}
cout << endl;
}
-
TransferFunction::~TransferFunction(void)
{
Clean();
@@ -228,3 +247,14 @@ void TransferFunction::FindFactors(void)
}
}
+
+void TransferFunction::TextInput(void)
+{
+ char line[1024]="";
+ cout << "Write the numerator: ";
+
+ fgets(line,1024,stdin);
+ cout << "you entered: "<<line<<endl;
+
+ cout << "Please use another method; not yet usable"<<endl;
+}
@@ -16,9 +16,10 @@ class TransferFunction
void FindFactors(void);
void PrintFactors(void);
void NicePrintFactors(void);
- void LoadFromFile(std::string filename);
+ void LoadFromFile(std::string filename); // loads coefs and powers from a file
void Clean(void);
- void Interactive(void);
+ void Interactive(void); //asks for coefficients and powers
+ void TextInput(void); //normal text interpretation
private:
ElementVec numerator;
@@ -14,8 +14,10 @@ TransferMap functions;
int main(int argc, char **argv)
{
cout << "Your system supports "<<sizeof(long double)*8<<"bit precision"<<endl;
+
int choice;
TransferFunction f1;
+ //f1.TextInput();
cout << "Interactive or from file(0,1): ";
cin >> choice;
@@ -37,5 +39,7 @@ int main(int argc, char **argv)
f1.FindFactors();
cout << "Factors: "; f1.PrintFactors(); cout << endl;
+ f1.NicePrintFactors();
+
return 0;
}

0 comments on commit 2a3a76f

Please sign in to comment.