tux4life 2,072 Postaholic

> First: Please post using code tags, I'm not saying this a third time :) ...

> void mySquareRootFunction (double x) , you declared your function to return a value of type void , why did you do that? Your function has to return something from type double ...

> double z = sqrt(x); Before you take the square root from a number you should first check whether it's negative :) ...

tux4life 2,072 Postaholic

My question is how to do the assignment

> That's not a specific question, we aren't doing your homework, sure we can, but you don't have to pass with our work, we don't have to get your grade :P

> Please ask specific questions about what you don't understand ...

> You're already on the right way, your teacher gave you already a bunch of code you don't have to write yourself, just look up how to use the sqrt function and all what you have to do then is wrap a single function around it :) ...

edit> I hope this is not another please-do-my-homework request, if it is, you definitly didn't read the forum rules !

tux4life 2,072 Postaholic

> You just copied your homework assignment and pasted it into this thread, so what's your question ?

slore>If the number passed to the function is negative, the function will return the negative of the square root of the positive number.
>>>>>> Actually that's not true math :P

> Please post using code tags !

> You can take a look here, to see how the sqrt function works ...

tux4life 2,072 Postaholic

> I looked it up in two different books (*) about C++ programming and they're using exactly the same technique to write a structure/object to a file ...

(*): C++ Black Book by Steven Holzner, The Complete Reference: C++ by Herb Schildt

tux4life 2,072 Postaholic

> The Allegro Game Programming Library is definitely the way you should go !
agentx> hope u people will help me in getting those bonus marks!
>> We'd like to help you with this stuff but remember that we aren't doing the coding for you, you'll have to do that yourself :) ...

tux4life 2,072 Postaholic

If the character entered is not an alphabet (!@#$% 5 or any other non alphabet), i want display 0

> I already posted a piece of code which evaluates wheter the character is an alphabet character or not ...

can any one do that pllllz help meeeeee

> Sure we can do that for you, but it's your homework ...

you just need to add an if condition in the above program but u must need to know the ASCII range in which all those alphabets fall.

> What do you think the following does? #if(('a'<=c && c<= 'z') || ('A'<=c && c<= 'Z'))

tux4life 2,072 Postaholic

> First calculate the whole number where you want to take the square root from (calculate the sum of the first n elements of the series)

>> Formula for the first series: (1/9)+(1/25)+(1/49)+... => 1/((3+(n-1)*2)^2) (n represents the nth element of the series :) ...)

>> Formula for the second series: (1/4)+(1/16)+(1/36)+(1/64)+... => 1/((2+(n-1)*2)^2) Now you've the formulas to calculate the nth element of both series it will be a lot easier to implement it I think :P ...

tux4life 2,072 Postaholic

We're not making this homework assignment for you, show us what you've already done so far ...

tux4life 2,072 Postaholic

This code might help you:

char c;
c = 's';
if(('a'<=c && c<= 'z') || ('A'<=c && c<= 'Z'))
{
     /* The character is an alphabetic character */
}
tux4life 2,072 Postaholic

>>Nice explanation :) but I think it doesn't make sense if you're just writing/reading this struct to/from a file using the method I provided ...

tux4life 2,072 Postaholic

but i think i need strong knowledge in computer architecture,don't i?

That depends on how detailed you want to implement it, bu a basic knowledge is required of course :) ...

tux4life 2,072 Postaholic

>>> Now you create a data type* from your struct

I meant a variable of course :P

tux4life 2,072 Postaholic

> A computer is only able to generate pseudo-random numbers, if you want real random numbers: just let the user move the mouse across the screen (in a completely random way :))
> From the mouse movement you can generate a (real?) random number

tux4life 2,072 Postaholic

> Whether it's his homework or not, he'll first have to show us his code :) ...

tux4life 2,072 Postaholic

> If you also are writing the array from your program do as follows:
>>> Put the array into a struct e.g.:

struct sth
{
     int array[5];
};

>>> Now you create a data type from your struct e.g.: sth mydata; >>> Writing the struct to a file:

ofstream file;
file.open("file.dat", ios_base::binary);

// You've to write the code to check whether the file is open yourself

file.write(reinterpret_cast<char*> (mydata), sizeof(sth));

>>> Reading our data from the file:

ifstream file;
file.open("file.dat", ios_base::binary);

// You've to write the code to check whether the file is open yourself

sth read_data;
file.read(reinterpret_cast<char*> (read_data), sizeof(sth));

Hope this helps :) !

tux4life 2,072 Postaholic

> Just want to remove all the spaces from a string?
>> Use a function like this one:

string trim(const string &s) {
	string t;
	for(unsigned int i=0; i<s.length(); i++)
		if(s[i] != ' ') t+= s[i];
	return t;
}

>> Just put your read expression into a string and pass it to this trim-function and all the spaces will be removed :)

tux4life 2,072 Postaholic

> So if I didn't understand you the wrong way each word may only appear one time ?
>>In this case the unique STL-algorithm might be helpful :)

tux4life 2,072 Postaholic

what a terribly fatal assumption! are you telling me a skript kiddie can't read a published algorithm and implement it on a $200 laptop?
"security through obscurity" is no security at all.
.

> If the hash is just used as a checksum I don't know anybody who would like to put his time and effort in this to (try to) break it :) ...

tux4life 2,072 Postaholic

so now there's no reason for you to continue promoting MD5 as an algorithm that produces unique hash values, yes?

And what about SHA1 ?

tux4life 2,072 Postaholic

> MD5 has been broken
>> OK, but it's just really difficult how to do it, a normal PC-user will never manage to break this algorithm, so if your MD5 is just used as a checksum it doesn't really matter whether it can be broken or not :) ...

tux4life 2,072 Postaholic

>>Isn't that because cout is overloaded for pointers ?
cout(strictly speaking, the operator << is overloaded, not cout) is overloaded for pointer to char and assume it to be a cstring i.e. character array which are null terminated.

> Yeah, you're right !! Actually it is the << operator which is overloaded, thanks for the clarification siddhantes :) I'm still learning :P ...

tux4life 2,072 Postaholic

I have a very hard programming challenge and i need help... I have nothing so far, so im hoping somebody could help me build it...

> Doesn't sound very difficult :)

> Sure we can help you as long as you can show us what you've already done and ask us specific questions about what you don't understand ...

tux4life 2,072 Postaholic

siddhantes>So cout<<p+2 will print the array...
tux>Isn't that because cout is overloaded for pointers ?

tux4life 2,072 Postaholic

Let's take a look at your code:

> You first do the following: p=places[0]; , which means that you're now pointing at the first letter of the word 'London', then somewhere further in your code you send this to cout: p[11] (but if you declare a char array like this: char places[3][11]; it can contain three elements of 10 characters long (the 11th is for the NULL-terminator: '\0' (the NULL-terminator of the string 'London' has index 10 in the array 'places')

> So what happens when you call cout << p[11] ?

>>> It's just displaying the first letter of the next element in the array of places (the 'B' of "Birmingham")

Hope this helps !

tux4life 2,072 Postaholic

Yeah, but you would still have to write aaaaaaalll thooooosseee liiineeeessss :)

Yeah, but you don't have to write the braces each time :)

tux4life 2,072 Postaholic

> Could you please post using code tags?
> Which lines are you referring to? (the third and the fourth line??)

> According of my knowledge of pointers this: &p[2] is just displaying a memory address (or am I wrong here?)

> This code is just the result of (very) bad programming :) ...

tux4life 2,072 Postaholic

>>I don't like Unix but I have to like it ...
Why?

tux4life 2,072 Postaholic

There's already a recent thread about this, you can find it here :)

tux4life 2,072 Postaholic

the file has numbers to but those should be read as a O. need help please help!

> You read a whole line from the file into a string variable and you loop through the string character by character and you evaluate if the character meets the following condition to be counted: the character is in between [a-z] and [A-Z] otherwise you've three possibilities:

-> The character indicates the beginning of a number
-> The character is a digit and should be counted as an 'O'
-> You don't have to count anything

tux4life 2,072 Postaholic

> Is the PC really shutting down (powering off) and then restarting (a cold boot up) :?:
>> If this is the case then it might be defined somewhere in your computer's BIOS, but probably this is just a Windows problem :) ...

tux4life 2,072 Postaholic

Man, isn't there an easier way than writing all those if statements?

> Sure there is: Just use a switch statement :) ...

tux4life 2,072 Postaholic

Here are listed some nice password recovery/reset programs :)

tux4life 2,072 Postaholic

Probably it's described in a further chapter of your book, but I still want to give you an example using vectors:

/* Declare the vector */
vector<int> v;
/* Put some values in it */
v.push_back(10);
v.push_back(3);
v.push_back(30);
v.push_back(12);
v.push_back(5);
v.push_back(23);
v.push_back(28);
/* Sort the vector from the lowest to the highest numbers */
sort(v.begin(),v.end()); /* now the vector contains the elements in the following order: 3, 5, 10, 12, 23, 28, 30 */

Now you just have to read out the first and the last element of the vector and you've the lowest and the highest number of a sequence :), but probably siddhantes' way is the easiest to understand for you ...

tux4life 2,072 Postaholic

Actually you can write an object oriented program for nearly (why am I using 'nearly' here:?:) everything you can simulate (inspiration enough now, I think :P) ...

tux4life 2,072 Postaholic

He perhaps, meant that he wants to customize the uranary * operator ( the dereferencing operator) for is custom class.

He mentions that he just started learning C++:

hey guys.. am learning c++
just started..

I think that's usually not one of the first topics you'll learn (if you're learning C++), but it could be he meant that though I find it strange he would :) ...

tux4life 2,072 Postaholic

> In case you need to use 2D Vectors (this is an alternative to your vector of 'five'-structs) :

1) vector<vector<float> > myVector(5,vector<float>(5)); (this will create a 5x5 vector)

2) You can store data like this: myVector[2][1] = 3; (store the number 3 in the vector)

3) Printing using cout is also possible: cout << myVector[2][1] << endl;

tux4life 2,072 Postaholic

i use Visual Studio C++ 2008 , on Build Menu , it says Batch Build .. , i clicked Release and it compiled some stuff into release folder , but i dont see any exe in the folder .. what should i give him?

> Check out this page :) ...

tux4life 2,072 Postaholic

I wouldn't recommend it but if you really want to disable it you should have to take a look at this website
(you can download a little utility here which provides you with some easy choices) :) ...

tux4life 2,072 Postaholic

> What IDE are you using, Code::Blocks ?
> In Code::Blocks it's easy: Somewhere on the toolbar there's a listbox called Build Target , here you can specify your build configuration :) ...

tux4life 2,072 Postaholic

If you're using XP Home it might be probable that there's an administrator account without a password (called 'Administrator')
Normally the password of this account is blank and you can access it by starting your computer into safe mode (press F8 just before the Windows Loading screen shows up), if the password of this Administrator account is blank, you can just login on it and change your other account's password :) ...

tux4life 2,072 Postaholic

> I never knew music files could generate random numbers :icon_eek:

> Lol :P, I thought he wanted to generate a random number for the filename of a music file ...

> Anyways: kelechi, could you please reformulate your question in a way we can understand it ?

tux4life 2,072 Postaholic

You'll have to use the rand function, look here for some information about it ...

Edit:: A remark on the title of this thread: A computer will never be able to generate real random numbers :)

tux4life 2,072 Postaholic

Actually this is not very C++ related I think, but OK, can you tell me what error he's having and can you provide me a link to or attach the source of your game to this thread ?

tux4life 2,072 Postaholic
#include <stdio.h>

int main() {
  printf("%08s\n", "18");
  printf("%08s\n", "3048");
  printf("%08s\n", "ffff8007");

  return 0;
}

> Just a little remark on the int main() line of your code: If a function doesn't require any arguments in C you have to put the void keyword between the function's '(' and ')' brackets (if you really want to be correct :P), like this: int main(void) :)

> This is a difference between C and C++, as in C++ this means that the function doesn't require any arguments
(if you don't type something between the brackets), in C this only means that the function can have unlimited arguments of any type ...

tux4life 2,072 Postaholic

I bought that book before the age of 13, and was my first step to becoming the totally awesome programmer you see today :P

That's the evidence that it's a very good book :P !!

tux4life 2,072 Postaholic

Although itoa function seems very useful, I couldn't use it, I use Ubuntu and gcc compiler. And when I try to compile I get this error:


What is the problem you think?
Thanks

Did you add the following include directive at the top of your code? #include <stdlib.h>

tux4life 2,072 Postaholic

I have created this code, the code that i find on web is stupid ,naturally it can be also mine stupid :P so maybe iam stupid :P:P

my question is if you can't to check this code and tell me if it's correct..........

Thank you very much!!!!!!!!!!

If your code compiled correctly it's correct code for the computer, but you could always have made a 'logical mistake' in your calculation algorithm of PI, that's why I was asking you where you got the algorithm from :) ...

tux4life 2,072 Postaholic

> You could write an Object Oriented Program (of course :P) that represents a 'virtual computer', you'll have to make classes for the processor, the motherboard, the graphical card, the ports (USB, FireWire, Serial, PS/2, etc.), the CD-Drive(s), and much much more :P ...

>>You can make this project as big or as small as 'you' want ...

tux4life 2,072 Postaholic

> Use the itoa function / sprintf function if you want to convert decimal to hexadecimal (I'm not sure about the fact that the sprintf function will convert a string containing a decimal number to a hexadecimal number, you can simply test it if you want to know it:)) ...

> If you don't care about the fact the code is in C/C++ you can also check out this code snippet :)

tux4life 2,072 Postaholic

tux4life

you don't undersand my question, i have install apfloat on my pc....
my big problem is other....

i don't know if my logical and mathematics calculation is correct....
in this case is my problem.....

i want someone to tell me if my code is ok or not.......

Thank you very much for your help...........

> I actually did understand your question, but in my previous post I was talking to ArkM :) ...

> Maybe useful: http://www.pisymbol.com/apps/picalc/ (a pi calculator with C++ source)

> BTW, where did you get the mathematics to calculate pi? I'll check that out :) ...

> Edit:: This link may also be an interesting one ...

> Edit:: Also Google on: "Chudnovsky algorithm" and "Gauss-Legendre"