wow... that is some messed up source code. I don't understand exactly what everything is supposed to do, so I will attempt to help you fix the syntax errors, but you will need to work on the logic a bit.
first off is the function prototypes. The basic syntax is:
return-type function_name(argument_type optional_name, argument_type optional_name);Although people like to leave out the optional name (the compiler does not require it so why put it there?) it is generally better to name the arguments since many development tools (like the IDE) will pick up any sort of in-context help from here.
so your prototypes should look something like:
CODE
// function prototypes
void EnterData(TheData& DataIn);
void EnterFilter(TheFilter& Filter);
int ApplyFilter(TheFilter& Filter, TheData& DataIn, TheData DataOut);
void DisplayData(TheFilter& Filter, TheData& DataIn, TheData& DataOut);
note that the ApplyFilter() returns a value, and takes in 2 new parameters. and that the order has been changed in DisplayData() -- these changes were based upon your useage in the main() function.
After this change your code will compile if the function definitions are commented out (main() is ofcourse not commented out). I don't know if the logic in main() is valid, but it does not seem to have any syntax errors, and seems to be ok.
so that gets us to here:
CODE
// Purpose
// A program to demonstrate the application of a simple digital filter
//
// Overview
// A sequence of data items and digital filter values need to be entered by the
// user. The application of the filter to the data involves a simple convolution
// operation. The filtered data are stored separately.
//
// Example
// before filtering:
// data_in = [0 1 3 6 3 1 0]
// filter = [-0.5 1 -0.5]
// after filtering:
// data_out = [-0.5 -0.5 3 -0.5 -0.5]
// where
// data_out[0]=data_in[0]*filter[0]+data_in[1]*filter[1]+data_in[2]*filter[2]
// data_out[1]=data_in[1]*filter[0]+data_in[2]*filter[1]+data_in[3]*filter[2]
// data_out[2]=data_in[2]*filter[0]+data_in[3]*filter[1]+data_in[4]*filter[2]
// data_out[3]=data_in[3]*filter[0]+data_in[4]*filter[1]+data_in[5]*filter[2]
// data_out[4]=data_in[4]*filter[0]+data_in[5]*filter[1]+data_in[6]*filter[2]
//
// The program checks the following
// 1.The data and filter values must have been entered before the filter is
// applied
// 2.The filter is not applied if the number of filter values is greater than
// the number of input data values
// 3.The data and filter values must have been entered and the filter applied
// before the filtered data can be displayed
#include <iostream>
using namespace std;
// the data values and the filter
struct TheFilter {
double* Values; // the filter values
unsigned long Length; // number of filter values
bool Valid; // true if the filter values have been Valid by the user
};
struct TheData {
double* Values; // holds the data to be filtered
unsigned long Length; // number of data values
bool Valid; // true if the data values have been Valid by the user
};
// function return values
enum {OK,FILTER_TOO_LONG};
// function prototypes
void EnterData(TheData& DataIn);
void EnterFilter(TheFilter& Filter);
int ApplyFilter(TheFilter& Filter, TheData& DataIn, TheData DataOut);
void DisplayData(TheFilter& Filter, TheData& DataIn, TheData& DataOut);
// Control the principal operations of the program
// Arguments: None
// Returns: 0 on completion
int main()
{
// define the filter and its initial values
TheFilter Filter = {0,0,false};
// define the original data and its initial values
TheData OriginalData = {0,0,false};
// define the filtered data and its initial values
TheData FilteredData = {0,0,false};
char UserInput;
// loop until the user wishes to exit
while (1) {
// show the menu of options
cout << endl;
cout << "Filter Menu" << endl;
cout << "-----------" << endl;
cout << "1. Enter data for filtering" << endl;
cout << "2. Enter filter values" << endl;
cout << "3. Apply filter" << endl;
cout << "4. Display filtered data" << endl;
cout << "5. Exit from the program" << endl << endl;
// get the user's choice
cout << "Enter your option: ";
cin >> UserInput;
cout << endl;
// act on the user's input
switch(UserInput) {
case '1':
EnterData(OriginalData);
FilteredData.Valid = false;
break;
case '2':
EnterFilter(Filter);
FilteredData.Valid = false;
break;
case '3':
if (Filter.Valid == true && OriginalData.Valid == true && FilteredData.Valid == false) {
if (ApplyFilter(Filter,OriginalData,FilteredData) == FILTER_TOO_LONG) {
cout << "The filter must not be longer than the data" << endl;
}
else {
FilteredData.Valid = true;
cout << "Filter applied" << endl;
}
}
break;
case '4':
if (Filter.Valid == true && OriginalData.Valid == true && FilteredData.Valid == true) {
DisplayData(Filter,OriginalData,FilteredData);
}
else {
cout << "Data have not yet been filtered" << endl;
}
break;
case '5':
delete [] Filter.Values;
delete [] OriginalData.Values;
delete [] FilteredData.Values;
return 0;
break;
default:
cout << "Invalid entry" << endl << endl;
break;
}
}
}
the function EnterData() seems to have a function defined within a function. I am just not sure what you were trying to do with that. You have this line:
unsigned int DataIn.Values; which tries to define a member of DataIn... which surely MUST be a syntax error. and you use an undeclared variable (pIntOriginalData) which is probably supposed to be the unused (but declared) variable (pIntDataIn).
Ok... seriously you need to find a C/C++ text book or read up on some beginner tutorials. This one function demonstrates a serious lack of understanding of the basics of the language.
lets see if we can't clean this function up... the idea (I take it) is to have the user tell you how much data they wish to enter, and then take in series of values and store them into an array:
CODE
//give the user 3 ties to get the input right
#define BAD_INPUT_CUTOFF 3
//Need to add the following two lines to the included:
//#include <limits>
//#include <ios>
void EnterData(TheData& DataIn)
{
int bad_count = 0; //lets us see how many time the user entered bad data
//Ask the user how many value she plans on entering:
do
{
cout << "Enter the number of data values to be filtered(1-100000): ";
cin >> DataIn.Length;
if (!cin.good() || DataIn.Length <= 0 || DataIn.Length > 100000) {
cout << "\nInvalid Input!" << endl;
cin.clear(); //resets the state flag
cin.ignore(numeric_limits<streamsize>::max(),'\n'); //clears out the buffer
bad_count++;
DataIn.Length = 0; // user did not enter a valid number
}
//See if this is a valid number (users are mean/stupid sometimes)
//Note that we don't display any error message
} while (DataIn.Length == 0 && bad_count < BAD_INPUT_CUTOFF);
// make an array to hold the data:
DataIn.Values = new double[DataIn.Length];
//Note that even if we allocated a length of 0 we will still be calling delete[]
if (bad_count < BAD_INPUT_CUTOFF)
{
cout << "Enter in the data:" << endl;
int i = 0; //our index into the Values array
int input; //the user's input
while (i < DataIn.Length && bad_count < BAD_INPUT_CUTOFF)
{
cout << "element " << i << ": ";
cin >> input;
if (!cin.good()) {
cout << "\nInvalid input!\nPlease input a valid floating point number!" <<endl;
//the user did not input a number, so we need to clear out the input buffer
cin.clear(); //resets the state flag
cin.ignore(numeric_limits<streamsize>::max(),'\n'); //clears out the buffer
bad_count++;
} else {
DataIn.Values[i]=input;
i++; //user entered data move to the next element
bad_count = 0; //reset the bad input counter
}
}
}
//check to make sure the input was valid...
if (bad_count >= BAD_INPUT_CUTOFF) {
cout << "\nSorry, invalid input, input loop terminated!" << endl;
DataIn.Valid = false;
} else {
DataIn.Valid = true;
}
}
that should work as your EnterData() function and server as a model for your EnterFilter() function.