I'm currently trying to display the dot product by calling a dotProduct function however I am confused as to how to do this. I've tried calling the function but commented it out since this did not work. What would be the proper way to display the dot product? Any help would be much appreciated!
#include <iostream>
#include <vector>
#include <ctime>
#include <iomanip>
using namespace std;
class list
{
public:
list();
void input(int s);
void output();
double dotProduct(vector <double> a, vector <double> b);
private:
vector <int> v;
};
list :: list() : v()
{
}
void list :: input(int s)
{
int t;
for(int i = 1; i <= s; i++)
{
t = rand() % 10;
v.push_back(t);
}
}
void list :: output()
{
for(unsigned int i = 0; i < v.size(); i++)
cout << v[i] << " ";
cout << endl;
}
double list :: dotProduct(vector <double> a, vector <double> b)
{
double product = 0;
if(a.size() != b.size())
{
cout << "Vectors are not the same size\n";
}
for (unsigned int i = 0; i < a.size(); i++)
{
product = product + a[i] * b[i];
}
return product;
}
int main()
{
list L1, L2,ob1;
int s;
cout << "Enter the size of list 1: \n";
cin >> s;
L1.input(s);
cout << "\nEnter the size of list 2: \n";
cin >> s;
L2.input(s);
cout << "\nVector 1: ";
L1.output();
cout << endl;
cout << "Vector 2: ";
L2.output();
cout << endl;
cout << "The dot product is: ";
//ob1.dotProduct(L1.output(),L2.output());
cout << endl;
return 0;
}