Disclaimer
Before reading this tutorial you, the reader, agree to the following. This tutorial and the code it contains are designed to be informational and educational tools only. They do not constitute investment advice. The author, Dave Topper, strongly recommends that you seek the advice of a financial services professional before making any type of investment. This model is provided as a rough approximation of future financial performance. The results presented are hypothetical and will likely not reflect the actual growth of your own investments. The author, Dave Topper, is not responsible for any human or mechanical errors or omissions. The author, Dave Topper, is not responsible for the consequences of any decisions or actions taken in reliance upon or as a direct or indirect result of the information provided by these tools.
In the next two sections we will be adding our model parameters class and an input argument parser to convert command line arguments. The latter is designed to work with the former
Add a new modelParameters class to your project the same way we added the mainCommandLine class in section 4. The Main Command Line Class.
Be sure to enforce the camel case convention for the source and header file names.
Your Project Section outline should now look like this.
Let’s build up the modelParameters class. Our model has three basic parameters: the data filename, the length for moving average 1 and the length for moving average 2.
Here is the header file modelParameters.h.
#ifndef MODELPARAMETERS_H
#define MODELPARAMETERS_H
#include <QString>
class modelParameters
{
public:
modelParameters();
void setDataFilename(QString);
QString getDataFilename();
void setMovingAvgLen1(unsigned);
unsigned getMovingAvgLen1();
void setMovingAvgLen2(unsigned);
unsigned getMovingAvgLen2();
void test();
private:
QString dataFilename_;
unsigned movingAvgLen1_;
unsigned movingAvgLen2_;
};
#endif // MODELPARAMETERS_H
Note the addition of one additional member function, test(). In the following examples we will use various class test() member functions to print out verification of a particular code segment.
Here is the modelParameters.cpp file.
#include <QStringList>
#include <iostream>
#include "modelParameters.h"
// Constructor
modelParameters::modelParameters()
{
}
// Data filename
QString modelParameters::getDataFilename()
{
return dataFilename_;
}
void modelParameters::setDataFilename(QString inFilename)
{
dataFilename_ = inFilename;
}
// Moving average length 1
unsigned modelParameters::getMovingAvgLen1()
{
return movingAvgLen1_;
}
void modelParameters::setMovingAvgLen1(unsigned inLen)
{
movingAvgLen1_ = inLen;
}
// Moving average length 2
unsigned modelParameters::getMovingAvgLen2()
{
return movingAvgLen2_;
}
void modelParameters::setMovingAvgLen2(unsigned inLen)
{
movingAvgLen2_ = inLen;
}
// For testing - printout
void modelParameters::test()
{
std::cout << "dataFilename = " << getDataFilename().toStdString() << std::endl;
std::cout << "movingAvgLen1 = " << getMovingAvgLen1() << std::endl;
std::cout << "movingAvgLen2 = " << getMovingAvgLen2() << std::endl;
}
There’s nothing particularly fancy going on here. Just a basic class containing three elements (a QString and two unsigned ints) along with accessor functions and a test function to print them all out.
Build your code to make sure it compiles correctly. We haven’t added anything new that will run yet.
In the next section we’ll create an input argument parser class to convert command line arguments into the model parameter class above.