Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: dot product...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 43335 of 48020
Post > Topic >>

Re: dot product in c++

by Jerry Coffin <jcoffin@[EMAIL PROTECTED] > Feb 14, 2008 at 11:51 PM

In article <1203048264_1026@[EMAIL PROTECTED]
>, invalid@[EMAIL PROTECTED]
 
says...

[ ... ]

> #include <iostream.h>
> #include <vectors.h>

That would be:

#include <iostream>
#include <vector>

If your book includes '.h' on the names of the standard headers, it's 
very out of date.

> I don't need anything off the command line, so I think that
> int main (void) { return 0; }
> is right. ??

That's reasonable, yes.
 
> I'm given to understand that many of fortran's vector capabilities have
an 
> analog in c++.  How would I declare and print a single four_vector, with

> double-wide real entries.  For the purpose of illustration, let's make
the 
> ith entry the real square root of i:

That's fairly trivial. This doesn't really do anything to ensure that 
four_vector really remains a vector of four objects -- if you changed 
the limit in the loop to '100.0' (or whatever) it would happily build 
that size of vector. Of course, if you decide "whatever" includes 
something like 1E200, chances are you'll have a hard time finding a 
computer with enough memory (even drive space) to hold the results. Then 
again, you'll probably find the memory about as quickly as you find 
patience to wait for the results...

#include <vector>
#include <algorithm>
#include <iterator>
#include <iostream>
#include <math.h>

int main() { 
	std::vector<double> four_vector;

	for (double i=0.0; i<4.0; i++)
		four_vector.push_back(sqrt(i));

	std::copy(four_vector.begin(), four_vector.end(),
		std::ostream_iterator<double>(std::cout, "\n"));
	return 0;
}

-- 
    Later,
    Jerry.

The universe is a figment of its own imagination.
 




 2 Posts in Topic:
Re: dot product in c++
Jerry Coffin <jcoffin@  2008-02-14 23:51:07 
Re: dot product in c++
Jerry Coffin <jcoffin@  2008-02-16 17:01:03 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 8:45:46 CDT 2008.