A function to return a vector N program

My function has the following prototype:

std::vector<double> calculate_mag_response(double start_freq, double end_freq,
int N, std::vector<double> num, std::vector<double> den

The function should return a vector size N of magnitude responses in decibels of the transfer function defined by numerator and denominator vectors num and den.
To adequately test, you should drive this with more transfer functions.

#include <vector>
#include <iostream>
#include <cstdlib>
#include <ifstream>
using namespace std;
int main(int argc,char *argv[])
{
vector<double> myNum, myDen, results;
ifstream outfile;
int N;
outfile.open("datafile.txt");
myNum.push_back(1.0);
myNum.push_back(1.0); //create a smple zero at s=-1
myDen.push_back(1.0);
myDen.push_back(3.0);
myDen.push_back(2.0); //create two poles at s=-1,-2
results=calculate_mag_response(.1,1000,100,myNum,myDen); //Call the student function
if (N=results.size()!= 100)
{
cout << "Your function did not provide correct number of data points. Please fix" << endl;
exit(0);
}
for (int i=0;i<N;i++)
outfile << i << "\t" << results[i] << endl; //Write this garbage to a file
return(0);
}

I am lost in how to complete this.
closed account (28poGNh0)
Try to figure out the changes ,develop your code and update

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
41
42
43
# include <vector>
# include <iostream>
# include <cstdlib>
# include <fstream>
using namespace std;

std::vector<double> calculate_mag_response(double start_freq, double end_freq,
int N, std::vector<double> num, std::vector<double> den)
{
    vector<double> tmpVect;

    tmpVect.push_back(5.0);
    tmpVect.push_back(1.3);
    tmpVect.push_back(2.9);
    tmpVect.push_back(3.0);

    return tmpVect;
}

int main(int argc,char *argv[])
{
    vector<double> myNum, myDen, results;
    ofstream outfile;
    int N;
    outfile.open("datafile.txt");
    myNum.push_back(1.0);
    myNum.push_back(1.0); //create a smple zero at s=-1
    myDen.push_back(1.0);
    myDen.push_back(3.0);
    myDen.push_back(2.0); //create two poles at s=-1,-2

    results = calculate_mag_response(.1,1000,100,myNum,myDen); //Call the student function

    if((N=results.size())!= 100)
    {
        cout << "Your function did not provide correct number of data points. Please fix" << endl;
        exit(0);
    }
    for (int i=0;i<N;i++)
        outfile << i << "\t" << results[i] << endl; //Write this garbage to a file

    return(0);
}
I see you place a variable in here but put values in here that won't change. Is this correct? Also, Line 25 "datafile.txt", I dont know what to do with this because I don't have any files to open. Is this something I have to create? What would I but in it if that is the case?
Topic archived. No new replies allowed.