Computing.Net > Forums > Programming > Classes and Norms

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Classes and Norms

Reply to Message Icon

Name: DoubleplusUngood
Date: October 26, 2009 at 10:27:03 Pacific
OS: Windows XP
Subcategory: C/C++
Comment:

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;
cin>>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 Norm

double 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 Norm

for (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?



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: October 29, 2009 at 07:04:41 Pacific
Reply:

So you're trying to do what, take what you have and turn it into a class?


0
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Classes and Norms

Classes and containers c++ buiilder www.computing.net/answers/programming/classes-and-containers-c-buiilder/11110.html

Arrays and classes help www.computing.net/answers/programming/arrays-and-classes-help/9454.html

Structures and Classes www.computing.net/answers/programming/structures-and-classes/10893.html