# 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 #include #include #include using namespace std;int i,n;vector v(n);string onenorm, twonorm, infinitynorm;//Calculating The 1 Normint main (){cout<<"Input size of vector"<>n;//cout<< "Input the values of the vector you wish to have";double sum [i];sum[0]=0;for (int i=0; i<=n-1; i++){ sum[i+1]= sum[i] + abs(v[i]);}onenorm=sum[n-1];int p;double pow (double& Variable,double& p)//Calculating the 2 Normdouble sumtwonorm[i];sumtwonorm[0]=0;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 Normfor (i=0; i<=n-1; i++){ infinitynorm=0; if ( V[i]>infinitynorm infinitynorm=V[i]);}/* 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

#1
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