Hello jtek679,
In addition to what
dutch has already said.
When you run the program from the command line you would type:
programName ecg.txt resp.txt
then Enter.
Breaking at the spaces "argv[0]" becomes the full path ending in the program name. "argv[1]" becomes "ecg.txt" and "argv[2]" becomes "resp.txt" and so on if there is more. At the same time "argc" gets the value of 3 because there are three items on the command and the space is the delimiter to separate them.
What that means is that a command line argument that has a space in it needs to be enclosed in double quotes to preserve the space and not use it as a delimiter.
What you need to do with "main" is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
using namespace std;
#include "ECG.hpp"
#include "RESP.hpp"
int main(int argc, char* argv[])
{
if (argc < 3)
{
cout << "\n Please enter ecg.txt file then resp.txt file into the arguments." << endl;
return 1;
}
ECG ecg;
RESP resp;
ecg.openFiles(argv[0]); // <--- Sends program name, with full path, to the open function. Should be "argv[1]".
ecg.FilterFunction();
ecg.HeartRateCalc();
ecg.AbnormalHeartRate();
resp.openFiles(argv[1]); // <--- Should be "argv[2]"
resp.filterFunction();
resp.startCalc();
resp.endCalc();
return 0;
}
|
I rearranged your includes. I find this to be a help when I miss a need file. The first group tends to be the include files used by any program. The second set is any include file(s) specific to the program and the third set would be any includes in double quotes.
In the first 2 groups is should not make any difference what order they are in as long as they are there. By putting your header files last everything that comes before it should cover anything in your header file.
Looking at the second group of header files not one of them is needed in "main" and could be left out, but would be needed in the other ".cpp" files. When I put a comment on them in "main" the program still compiled with out errors although you still have other problems that need addressed.
Just so you know the "ECG.hpp" file should be more like this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#ifndef ECG_hpp
#define ECG_hpp
//#include <stdio.h> // <--- C header file and not needed here. Not a replacement for "<iostream>".
//#include <vector>
//#include <string>
//
//using namespace std; // <--- http://www.lonecpluspluscoder.com/2012/09/22/i-dont-want-to-see-another-using-namespace-xxx-in-a-header-file-ever-again/
class ECG
{
vector<double> data;
vector<int> index;
vector<double> filterData;
int countlines;
double RR;
public:
int openFiles(string file);
void FilterFunction();
void peakValue();
void HeartRateCalc();
void AbnormalHeartRate();
};
#endif /* ECG_hpp */
|
My understand is the point of a class is to hide the variables from public access, so that only a member function of the class has access to them. By making them public as you did anything in the program has access and can change the variables. One of the points that
dutch is making. This becomes harder to track down when something goes wrong.
Note: A class is private by default where a struct is public by default. Im the above code the first section is considered private until you reach the "public:" line. Then anything after that is "public" until changes by "private" or "protected".
Another thing I found that gives me an error is
int distances[index.size() - 1];
. VLAs, (Variable Length Arrays), art not legal or allowed in C++. If your compiler allows this it is not doing you any favors. When you create an array,
int distances[]
what is between the []s needs to be a constant number, This could a variable defined as a constant or a number, but it is a value that must be known at compile time so the compiler can set aside enough space for the array on the stack. If you want to use an expression or a variable for the size then you will have to create dynamic memory on the heap. And do not forget to use "delete" to free the memory when finished.
In the "ECG::AbnormalHeartRate" function you have
for (i = 0; i < (index.size() - 1); i++)
."i" should be defined in the for loop and the ".size" function returns a "size_t", an alias for "unsigned int". you are better off writing for loops as
for (size_t i = 0; i < index.size() - 1; i++)
. I do not believe the () around "index.size() - 1" are needed, but it will not hurt if you leave them. In your code you are comparing an "int" to an "unsigned int". Not usually a problem, but a potential for one as an "unsigned int" can store a number larger than an "int" can.
One of the points that
dutch is saying is in the "RESP" header file
int i, k, j;
should not be there, but defined in the for loops that use them.
That is what I have found so far.
For the input files I realize that 8000 lines is a lot, but you only need say 100 lines so that everyone can be using the same information. I would guess that the input files were provided to you, so the numbers in those files do have a meaning to the program. Just creating a file of floating point numbers may not produce the correct results as the files you are using.
Even posting a partial file is helpful. Not only will everyone be using the same information they can also see how the file is laid out and my have some suggestion on how to better read the file.
Andy