Classes and Norms

October 26, 2009 at 10:27:03
Specs: Windows XP
Hey guys, I'm having a little trouble with writing norms and then putting them into classes, I'm doing a masters at university and we've got a programming course, and so far my life experience of C++ is four hours of lectures so what I'm going to write is probably quite off the mark, anyway I'm trying to calculate the 1, 2 and sup (infinity) norms of vectors in C++ and then put these functions into "a class with hidden i.e. private data structures of vectors". Here is what I've done for the vectors, I appreciate it probably reads similar to how a child trying to play a concerto on a violin after four hours practice would sound, but here goes:

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
int i,n;
vector<double> v(n);

string onenorm, twonorm, infinitynorm;

//Calculating The 1 Norm
int main ()
cout<<"Input size of vector"<<endl;
//cout<< "Input the values of the vector you wish to have";

double sum [i];
for (int i=0; i<=n-1; i++)
sum[i+1]= sum[i] + abs(v[i]);


int p;
double pow (double& Variable,double& p)

//Calculating the 2 Norm

double sumtwonorm[i];
for (i=0; i<=n-1; i++)
sumtwonorm[i+1]= sum [i] + pow (double V[i],int 2);
twonorm = pow (double sumtwonorm[n-1], double 1/2);

//Calculating the Infinity Norm

for (i=0; i<=n-1; i++)

if ( V[i]>infinitynorm


/* infinity norm should hopefully now be given by typing e.g cout<< infinitynorm; */


Could anyone give me any pointers as to what to do?

See More: Classes and Norms

Report •

October 29, 2009 at 07:04:41
So you're trying to do what, take what you have and turn it into a class?

Report •
Related Solutions

Ask Question