hello, i have a double value=0;
and i want before starting the calulation to round this value
in the numbers that the user add, for example 2...any ideas??? I have despered...........
I don't understand that, can you give an example ?
hello, i have a double value=0;
and i want before starting the calulation to round this value
in the numbers that the user add, for example 2...any ideas??? I have despered...........
I don't understand that, can you give an example ?
>my problem is how to find step buy step all the numbers
If you mean finding all the numbers of pi, then you didn't pay enough attention in the lessons of maths: pi is an irrational number, which means you can't calculate all of it's digits because there are just infinite of them :)
If you automatically want to do 10000 iterations then you should simply change your for-loop to this:
for (long int n = 1; n <= [B]10000[/B]; n++) //for loop for SERIES 2
{//for loop start
serieValue+= pow(-1.0, n+1)/pow(n,2.0); // Calculating pi of SERIES 2
} // for loop end
pi=sqrt(12*serieValue);
By the way: are you using any high precision float/big number library?
just for your information you do not need to implicitly define the delimiter as a newline in getline() it is already set there and if you want to change it the you must specify what you want. at least that is according to the msdn for visual c++ 6.0 professional
Yup, that's true: http://www.cplusplus.com/reference/iostream/istream/getline/
:)
but he said he needs to convert the inputed number so wouldnt that imply that he needs to use cout to ask for the number and cin to get it?
Yes, but remember: we aren't writing the code for him, by the way: we already assumed that he knows how to do input/output, otherwise his question was something else (I mean, if he's asking about how to do conversion between a Fixed-Point Binary and a Decimal number, can't you assume then that he already knows at least the basics of C++ (including I/O)? YES) :)
using namespace std;
isn't required even if you're using things from the std namespace. It's only to make it less annoying so you don't have to typestd::cout
,std::cin
, etcetera.
That's true, I forgot about that (I only wouldn't say 'less annoying' as it can cause conflicts), but as he isn't doing any input/output #include <iostream>
isn't even needed or am I wrong?
#include <iostream> int bin_to_int(char *binary) { // ... } double bin_to_double(char *binary_fixed_point) { // ... } int main() { // ... }
Hope this helps.
You forgot to put the using namespace std;
instruction in your snippet :P
>This may help
Yeah, Alex, it will surely help him, but you don't explain him what you've changed to make his code work ...
To the OP:
It's because of the getline
function, so you'll have to flush the input stream each time to make your code work as expected, there's a thread about flushing the input stream, you can find it here :)
i put my whole program in the thread
I've nothing against the fact you're putting your whole program in this thread, as long as you use code tags !
From char to integer (without checking whether character c
is a real digit, you'll have to add that yourself if you want):
short chr2int(char c) {
return c-'0';
}
From digit to character it's nearly the same, but you'll have to do +'0'
instead of -'0'
:)
Avoid using system("pause");
(reason), try cin.get()
instead ...
I already wrote something like this for BigInteger addition (using C++ strings), maybe it might help you: http://www.daniweb.com/code/showsnippet.php?codeid=1154 :)
By the way, you haven't ask us a specific question, where are you having problems with in your code?
>PLS REPLY
You've two replies, are you happy now?
Don't just copy your homework assignment :(
void PhoneBookModel::sortByName( Glib::RefPtr<Gtk::TreeSelection> selection ){ /* Enter SortByName Function here */ }
>Enter SortByName Function here
I hope this wasn't a request to do your homework, you'll never get free code here, you've to get your grade by turning in your code, not by turning in the code we wrote for you :( ...
>but is the C++ way of handling exceptions the preferred way to handle this ?
It depends. Unless you have a good reason though, you should prefer the default throwing behavior.
Is converting C code to C++ code a good reason?
>>>Is this the right way to do it?
>No.
No. When you use nothrow, new returns a null pointer instead of throwing bad_alloc.Your catch is also malformed. ;)
So the information was correct?
nothrow is a (ad-hoc) way to control program flow.
As you may be clear, no throw does not throw exceptions.
So you get the old C type check rather than the great exception handling mechanism.
Good point :) but is the C++ way of handling exceptions the preferred way to handle this ?
Hi, Ancient Dragon, I read the link you posted, so it's actually not required to use nothrow
with a try-catch block or did I get that wrong?
Do I have to precede nothrow
with std::
?
Are there actually places on the internet where I can find exact 100% correct information about C++ ? (probably Narue's site)
Thanks for all your effort, you were absolutely right ...
I got this code from: http://www.cplusplus.com/doc/tutorial/dynamic/
int * bobby;
bobby = new (nothrow) int [5];
if (bobby == 0) {
// error assigning memory. Take measures.
};
Is this the right way to do it?
You misunderstood your book. Better read it again. Maybe the book is talking about smart pointers
Yeah, you were right, in the book they we're talking about dynamic memory allocation with the new
operator, and when allocation with new
fails it returns a special pointer value: NULL
, otherwise the pointer is pointing to the newly assigned memory :)
That is incorrect. The pointer is assigned whatever random value is at that memory location. For example
char *ptr;
the address of ptr is whatever is at that memory location on the stack (assuming its not a global variable). It is never auto set to NULL by the compiler in either C or C++ languages.
But my C++ Book says so, by the way, why are we otherwise checking whether an assignment has failed or not using if(ptr == NULL)
?
In that link you just posted.
I dun get what "this" is.
it says if(this==rhs
what's this?
It's just a check whether the object is being assigned to itself or not :)
hm, and how can i do this ?
Something like this should work (it's only for full seconds, not milliseconds)
time_t tb = time(0); // Begin time
/*
Call your algorithm here
*/
time_t ta = time(0); // End time
cout << "Execution time: " << static_cast<long>(ta-tb) << endl;
Did you actually read my post thoroughly? Did I say that you had to use the struct
keyword ?
Did you take a look at the example ? (If you don't understand something then just ask:))
No, take a look at this line: PointerA operator = ([B]const <datatype?>&[/B] PointerA * C, const& PointerA *D)
according to my C++ knowledge this won't compile, you also have to specify what type the constant is e.g. a constant integer is declared as const int
, not just as const
... C = D;
what is it actually? You've to return a reference to the object ...
Take a look at this example :)
Actually it's much easier to implement without a function:
time_before
(you can also choose something different if you want)time_after
Now just subtract both variables :)
PointerA operator = (const& PointerA * C, const& PointerA *D) { C = D; return C; }
I think I meant this.
orPointerA operator = (const& PointerA * C, const& PointerA *D) { PointerA* C; PointerA* D; C = D; return C; }
Also, do I need to put struct before PointerA?
Why are you making it so complicated? Just pass the struct by reference :)
I don't know what is a copy protection. Users may change specific file contents but only these...I need to aware anybody that I am the legitimate owner of the code and must treat it like these.I don't want to see,say any publication, which appears my code and another author
If you only want to give them away some certain code, then just compile the other code to a library and give them the library, in this way they can't change everything, but only the things which aren't in the library :)
So if I don't misunderstand you, you've to write a program which generates prime numbers and you've also to know what time it did take to do the whole operation?
I don't know what is a copy protection. Users may change specific file contents but only these...I need to aware anybody that I am the legitimate owner of the code and must treat it like these.I don't want to see,say any publication, which appears my code and another author
Just take a patent on it :P
Can you be more specific? It depends on what your function has to do :)
Can you give an explanation about what your function has to do (I'm talking about prim_MCST(adj_matrix,nv);
, what's the link between those two?)
?
yes but is not with the getexecutiontime()!.
Actually it's a better one :)
ya sure i'll give up programming and do some thing else.. thank you !
I hope it's not because of my post :P
None of them are helpful -><-
Google found about 1,860,000
results and none of them are helpful? LOL :P
Please be more specific in your question: Does anyone of you know how to protect this?
Do you want to add a copy protection to your program?
Actually there's already such a feature in the C-subset of C++:
http://www.cplusplus.com/reference/clibrary/ctime/clock/
:P
So you've posted your code and what now?
What is your question?
Ancient Draogn said the first one causes memory leak.
But the second one isn't bad.
Now you're saying it's bad?Doesn't the pointer, once declare it declares to some random memory?
The first one is definitely causing a memory leak (you declare a pointer, assign newly allocated memory to it and after that you're just setting the pointer to NULL, which means it doesn't point anymore to the previously assigned memory :))
The second one is syntactically not wrong, but after a pointer declaration the pointer is automatically set to NULL
, so there's no need for Head = NULL;
, it's just a line which causes overhead ...
Still Couldn't get the logic right :(
What logic can't you get right?
If you cannot understand a single one of the links I posted then you should definitely do something else than C++ :(
[img]http://www11.0zz0.com/2009/05/05/13/341324761.jpg[/img]
Can't you just copy the image as I think you've to be a registered user to view the image :)
are you understand me??
No :(
What? I have no idea what you are talking about.
He's talking about the C++ fstream
class(es)
Edit:: Sorry I misunderstood the OP's post (he was actually quoting but I didn't notice that) :(
The first is not good, and the second is also a bad one: Head = NULL;
Why should you set the pointer to NULL right after the declaration? It's automatically done (If you declare a pointer, it's automatically pointed to the first memory address: NULL) ...
>so please help me by giving me the correct code
We'll never give you free code on this forum, did you read the forum rules? Let me guess...NO!! :)
Some information about linked lists:
Maybe you should first read some professionally engineered information about linked lists: http://www.eternallyconfuzzled.com/tuts/datastructures/jsw_tut_linklist.aspx :)
Is "Press ENTER to continue" also good?
cout << "Press ENTER to continue ..." << endl;
cin.get();
No you're right, it's more usual that a matrix has always more than one dimension :P