mrnutty 761 Senior Poster

Just go for C++. Learning C afterwards will be easy. And you will see
the real difference between the two.

mrnutty 761 Senior Poster

its used to indicate if the number is prime or not.

mrnutty 761 Senior Poster

I recommend using the devIL library. Let them handle loading images.

mrnutty 761 Senior Poster

Hint, initialize your variables.

mrnutty 761 Senior Poster

Remember a string is just bunch of characters. Thus

std::string stars(10,'*);

says the stars consists of 10 characters, where those
10 characters are all '*'; string.size() returns the number of characters
the string contains.

mrnutty 761 Senior Poster

i just dont know whats the function to detect the upper and the lower case letter in this kind of program...i've tried finding it on the internet but couldnt find it..so thats why i'm asking here..without it for sure i cannot even start to code this program....

Thiswill answer all your question of life and the universe.

mrnutty 761 Senior Poster

Your base case is wrong. When should your function return or Stop ?

mrnutty 761 Senior Poster

Assuming same things as Narue, you can also just peek the character
without reading it, just in case the file is not empty.

#include<iostream>
#include<fstream>

using namespace std;
 

int main()
{
	ifstream read("test.txt");

	if(!read) return 0;

	bool isEmpty = read.peek() == EOF;
	
	cout << boolalpha << "test is empty = " << isEmpty<<endl;

	return 0;
}

That way, if you read the file, and its not empty, you don't have to set
the cursor back to the beginning.

mrnutty 761 Senior Poster

Are you suggesting that ammonia-soaked beef by-product tastes good? Man, you gotta get out more often.

No he is suggesting looking like this is Sexy.

mrnutty 761 Senior Poster

>> can you use c++ libs such as GNU MP to prove it

Sure you can. Thats what its there for. Although you have shown you
do not need to.

mrnutty 761 Senior Poster

That sounds nasty. I tell you, greed makes people do bad things. I'm glad
I try to eat healthy as possible and usually stay away from commercialized
beef burgers.

mrnutty 761 Senior Poster

how to create a program using C++ pls tech me :P ;)

First download and IDE, I prefer, Microsoft visual C++ express edition 2008. Its the bottom left, with
the yellow colored box.

Second learn how to create a project, google it up.

Third, youtube , "hello world program in visual studio C++ 2008".

Follow those steps then your quest to C++ perfection will start.

mrnutty 761 Senior Poster

I think a good start would be to create a linked list. Since you don't
know templates yet, you don't have to create a template linked list.

Do you know what a linked list is?

mrnutty 761 Senior Poster

This code :

const int *const Method2(const int * &z) const
   {
      return ++z; // no error
   }

You are changing what z is pointing to. This is really not good now since
it points to something else than what it originally pointed to.

Thus this code :

const int *const Method3(const int *const &z) const
   {
      return ++z;  // error: increment of read-only reference `z'
   }

Means that you cannot change what z is pointing to.

mrnutty 761 Senior Poster

Yes thats correct. It can be verified by counting each digits of that term's
Fibonacci number :

115608376390706625089549190664369733786445970925010655166
760424614715043180401956023361531012589906666008701135384
680860337142323277348898955730083744453428944898199673173
761829391261593880719920995905364045172805753497005877888
514650261852890912169973122237548612799954472256765867117
867047052072620347857452768890075920944505663947098573306
067443128329755922910416797577152409111707857910556721245
114149359994333561948472285263874014549540972419995272722
099278285877638705250846282985450488999112911941540069976
650201369680356399802384539418446112110316703739228284280
802029274085741456469693423600837071383908955849313042325
078444156346635042914359618760243247795489993354216600326
813193670021764828892436210668356910520591495520508663387
228118180208097190703606124570225389914789857293652171061
704363954657235791896599414491784535604980852900699301359
266468462123848192696191957497850100755231826177948805306
300594889036784573527063810026389395043330147299855494490
6890148704114575048881546982213123677014816963987075777
mrnutty 761 Senior Poster

Doesn't anyone see a problem with this :

int * first()
{
	int f_lcl = 0xAAAA ;
	printf("  In First  : value of f_lcl ( %x ) \n", f_lcl);
	printf(" In First : addr of f_lcl is ( %p ) \n", (void*)&f_lcl); 
	return &f_lcl ;
}

He is returning the address of a temporary variable, i.e it gets
destroyed after it goes out of scope, which is at the end of the function,
so the behavior is undefined.

Salem commented: Exactly! +18
tux4life commented: Exactly! +6
mrnutty 761 Senior Poster

In this challenge there are 3 question, beginner, intermediate, and others.

Beginner:
1) Find the sum of all Natural numbers that are a multiple of 3 or 11, from 1 to 100,000.

Intermediate:

The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?


Other( a little harder than intermediate):

The Fibonacci sequence is defined by the recurrence relation :
F_n = F_n-1 + F_n-2 where F_1 = 1 and F_2 = 1;

Here are some few terms :
F_1 = 1
F_2 = 1
F_3 = 2
F_4 = 3
F_5 = 5
F_6 = 8
F_7 = 13
...
...
F_12 = 144
As you see, F_7 is the 1st term to contain a fibonacci number with
2 digit. And F_12 is the 1st term to contain a fibonacci number with
3 digits. Find the 1st term in the Fibonacci to contain 1024 digits.

Credits due to project euler. Post solutions here. Make sure you
Comment where relevatent, indent and make code readable. Make
sure its C++ code since this is posted in C++ forumn.

Happe new year.

mrnutty 761 Senior Poster

I think there might be more support for SDL than SFML in the internet.
Maybe pick one based the support it has online. So you get more
documents and tutorials for your benefit.

mrnutty 761 Senior Poster

Which one is most likely , ++i or i++
:

//++i  OR i++ ?
{
    int temp = i;
    i = i+1;
    return temp;
}
//++i OR i++ ?
{  
    i = i + 1;
    return i;
}

Maybe the name will help you :

++i is called pre-increment
i++ is called post-increment

mrnutty 761 Senior Poster

>>Are you sure about your second one?

Maybe the wording was wrong. When I say "pointer can change what its pointing to " I am talking about the pointer itself. The pointer can point to different const data. Of course the const value of what its
pointing to can't change.

Here is the example for that one :

#include <iostream>
#include <string>
using namespace std;

template<typename Type>
void print(const Type& val, std::string endWith = "\n"){
    cout << val << endWith;
}
int main(int argc, char**argv)
{
    const size_t num = 12;
    const size_t *ptr = &num;

    print("value of ptr : "," ");
    print(*ptr);
    print("Pointing-Address of ptr : " , " ");
    print(ptr);

    const size_t num2 = 21;
    ptr = &num2;

    print("\nvalue of ptr : "," ");
    print(*ptr);

    print("Pointing-Address of ptr : ", " ");
    print(ptr);


    return 0;
}

This code :

const int* const ptr = 0;

Means that ptr can't change whats it pointing to nor can it change the data its pointing to.
It must be initialize when declared, just like a regular const int.

Here is an example for that one :

#include <iostream>
#include <string>
using namespace std;

int main(int argc, char**argv)
{
    const size_t num = 12;

    const size_t* const ptr = &num; //GOOD

    size_t temp = 0;
    //ptr = &temp; //BAD : can't change what its pointing to
    //ptr = 0;    //BAD : can't change what its pointing to

    const size_t forty = 40;
    //const size_t* …
mrnutty 761 Senior Poster

1) Do you know how to write to file ?
2) Do you know the difference between , int i = 1; and char j = '1' ?
3) Do you know how to make a for loop ?

mrnutty 761 Senior Poster

Maybe this will help :

//regular pointer
int *ptr = 0;

//pointer-to-const-data type
//pointer can change what its pointing to 
const int * ptr = 0;
//const-pointer
//pointer can't change what its pointing to
//pointer can only point to non-const object
int * const ptr = 0;

//Now combine them two to create :

//const pointer that cannot change what its pointing to
//could point to const variable or non-const variable
//once assigned( at deceleration)  it "stays put"
const int* const ptr = 0;
mrnutty 761 Senior Poster

This is wrong :

while (x!=0,y!=0,x>=y)

Use either the logical AND operator( "&&" ) or the logical OR operator( "||")

Same here :

if (a!=b,a<=b)

.

mrnutty 761 Senior Poster

>>Its complex since I have to compare a word for word then a word for sentence ... if I found that word1==word2 then I'll incremant a counter ... and I'll have another counter for all words then I'll devide those and multiply by 100 ..

Don't worry about it. You don't need to publish this do you?
So it doesn't matter, for now, if your program is simple. How about
randomly searching for a sequence of words from one file onto another?

mrnutty 761 Senior Poster

>>Citation please. Where are you getting the "billions" figure? I see nothing in the article you link that discusses the cost of this research or just as importantly, WHO is funding it? I seriously doubt that it's in the billions. Moreover, most of these trips are self-funded by University grants and stuff. I doubt the government is shelling much out for this research.

This project was started around 1994(google it). The billion dollers
was probably an rough over estimate. However, I assume that
there has been at least some million dollar invested in this project.
I tried to dig up some numbers but it turned out its a little bit harder
than I thought. Although I might search for it in future.

>>Again, citation please. Where do you get the $30 billion figure from? How exactly do they propose to spend this $30 billion? What's their plan? This is a reliable resource.


>> He says that if you're bored, it's your own fault.
No he actually tries to say that its the government and the schooling
system fault.

>> Same here. Anyone who takes the time nowadays can become informed and aware, corrupt media or no corrupt media

That true, but in reality how many people do you think will take the time
to learn about their "true" country? Maybe less than 25% of the people
in U.S.

Anyways, I'am done arguing. …

mrnutty 761 Senior Poster

Before you write this program you need to think about the problem.

You said you want to " have the percentage of smilarity". You have the
right idea about using strcmp, but its not what you should use. For
this you should use std::string.

So lets talk about what you need to do in order to get the percentage of
similarity between two files. What do you think we need to do ( in
details) in order to get the percentage of similarity?

mrnutty 761 Senior Poster

It could be your text file. Towards the end, you might have empty lines
in your file. Check it.

mrnutty 761 Senior Poster

Control-D represents the end of file. So either read until the end of File,
or Make some special characters to represent the end of fie. As suggested
you can do something like this :

const std::string END = "EOF"
while file.isNotEmpty {
    std::string  content ;
    getline( file, content, END );
   if( content == END ) break;
}

Just make sure your files ends with "EOF" or whatever.

DarkC0de commented: thanks +1
mrnutty 761 Senior Poster

>>>>I have no idea why I would make a const object

1) For good programming habbits
2) When you create an object thats const, you could only use the const
corrected public interface. Take a look

#include<iostream>
#include<string>

using namespace std;


class A
{
private:
	int var;
public:
	A() : var(0){}
	A(int i) : var(i){}
	int getVar_noConst(){ return var; }
	int getVar_Const()const{ return var;}
};

int main()
{	 
	A nonConstObj(10);
	//nonConstObj could use all public interface
	int j = nonConstObj.getVar_Const();
	int k = nonConstObj.getVar_noConst();

	
	const A constObj(-10);
	//while constObj can only uses const corrected function
	int l = constObj.getVar_Const();
	//int m = constObj.getVar_noConst(); ERROR
	
	return 0;
}
mrnutty 761 Senior Poster

Also change this :

double getSidelength(int);//gets the values

to this :

int getSideLength(); //gets the values

There is no need for the int parameter, as well as the double return value, since you are returning your int member
variable.

This is completely wrong :

for (line=1;line<=s;line++)
{
	for (loop=1;loop<=s;loop++)
		cout<<" ";
	cin>>ch;
	cout<<endl;
}

It should be this :

for (int i = 0; i < sideLength; i++)
{
	for (int j = 0; j < sideLength; j++)
		cout << ch <<  " ";

	cout<<endl;
}
mrnutty 761 Senior Poster

Try this :

#include<iostream>

using namespace std;

int main(){
  cout << "Hello World\n";
  return 0;
}
mrnutty 761 Senior Poster

Just do something like this :

string num = "";
cin >> num;
while( !isNumber( num ) ){
   cout << "Only numbers allowed, Try again : " ;
   cin >> num;
}

isNumber is your own function that uses the isdigits() function from cctype.

mrnutty 761 Senior Poster

I assume you don't know how to write a code for this. So before any code
is written. Think about how one would compute x^y, where x is the base
and y is the exponent.

Why is 2^10 = 1024 ? Why is 2^3 = 8 ?

mrnutty 761 Senior Poster

>>Of all the stupid, inane things we waste time and money on that you could fill in the blank above which offer little positive value to humanity (unnecessary war, Jerry Springer, mindless, shallow celebrities, building bridges to nowhere, subsidizing tobacco...) and detract from important stuff we COULD be spending money on, I can't think of a less fitting example than trying to figure out what the missing link is.
It's an intellectual exercise that is the polar opposite of mindless, rote memorization of useless facts.

The reason is obvious. I picked this topic because of the billions of
dollars spent on this project. It is estimated by the United Nations' Food
and Agriculture Organization (FAO) that it takes about 30 billion dollars a
year to end world hunger. Some time ago we bailed out the Wall Street
with 23 times the amount needed to end world hunger. Its stuff like that
we need to avoid.


>>They're also the exact opposites of the types of teachers the guy who wrote the article you site hates, which are incurious, lazy teachers who just regurgitate the lesson plan.

Yes thats true. Generally those teachers have no idea of whats really
going on.

>>If you're lazy and incurious, you don't care about solving the missing link or any other problem.


Realize that I am not saying that we should stop this "curiosity" of ours
to obtain knowledge …

mrnutty 761 Senior Poster

>>due to the left-right associativity of the '+' operator, the leftmost '+' is evaluated first

Nope, its undefined. The '+' operator is not a sequence point. So its possible that in this code [ f()+g()+h() ] , anyone could evaluate first.

mrnutty 761 Senior Poster

It depends on what "i" is. If its a class then there if no way of knowing
exactly what it does unless you see the code for it. If "i" is a primitive type data, then look at its assembly code and see which one is the fastest. It might vary with compilers.

mrnutty 761 Senior Poster

Hey Grim. Forgive for the late reply. Was taking on finals and forgot about this.

>>If, at some point, you wish to bring some thought and research into this discussion, please feel free to

>>Fact: YOU have been dumbed down by schools , media, and everyone else.

John Taylo Gatto is one of the leading researcher (or was, not sure now). He is describes it pretty well, although it might take multiple read, to get how each sentence he wrote has some meaning.

>>Fact: YOU are clueless.

I admit this is more of a opinion, but I would guess more than 75% of people do not know about how schools are "fixed" into making us "Automatons".

>>Fact: WE are killing ourselves.

This one is just obvious. Some things that people do is harmful to
us and the environment, those things could be unavoidable and
sometimes mandatory as well. For example take Global Warming, for
now it is unavoidable and our humans activities are the main reason
for this cause.

>>This is a logical fallacy known as Special Pleading, in which you hold yourself to a different standard than you wish to hold the scientific community and/or 'other people'.

No that is not what I am saying. I am not making my case special in
any way. What I am saying is that I cannot give everything that I
have, until I equate at …

mrnutty 761 Senior Poster

Just load it into paint, and use the resize feature.

mrnutty 761 Senior Poster

Come on kids... You read in some book that that you MUST use getters and setters and suddenly you all jump on the band wagon.

Hell I'd even argue against the need for object orientated design. The exact same model can be achieved via functional programming.

Lets not go off track. I would love to argue if you posted this in the
geek's forum, but OP's question has been answered, so lets not elongate this thread.

mrnutty 761 Senior Poster

Oh, you mean you want the number in hex inside the string? I don't see a good reason for that. Whenever you need to print in hex, just convert the string into a int or a float and set the stream to print out in hex.

mrnutty 761 Senior Poster

Not sure what you mean. Just put that code inside a loop?

mrnutty 761 Senior Poster

>> Well that's simple thanks, tho was more wondering how to convert it to a string?

You can use the stringstream.

#include<iostream>
#include<string>
#include<sstream>

using namespace std;

int main()
{
    const float PI = 3.14159265f;
    string  pie = "";
    stringstream convert;  //create stream object
    convert << PI;    //insert out value into our stream
    convert >> pie; //get the value in the stream as a string object

   return 0;
}

Or for practice, try to create a function that does that without the sstream.

mrnutty 761 Senior Poster

Thats called Initializer list

mrnutty 761 Senior Poster

If anyone is worried about which makes his code faster :

A) ++a;
B) a++;
C) a = a + 1;
d) a += 1;

Then I am more worried about his code.

mrnutty 761 Senior Poster

Just make everything public then you don't need to!

http://www.darronschall.com/weblog/2005/03/no-brain-getter-and-setters.cfm

What happens when those brainless getters and setter, need to serve some purpose later one the code, or when the maintainer needs to change some code, or if the programmer makes some mistakes?

mrnutty 761 Senior Poster

Before I say something, what do you think this statement is doing :

struct word_list * new = NULL;
mrnutty 761 Senior Poster
int n = 15;
cout << hex;
cout << n << endl;
Excizted commented: thank you. +1
mrnutty 761 Senior Poster

>>I'm wondering if I'm duplicating this class by doing the following.

Maybe. If inside the class definition contains some data members thats a pointer-to-someDataType. Then you need a deep copy. Otherwise, the pointer variable from the variable "point' with point to the same address as the pointer variable from the variable "sc", point = new SimpleClass(sc);

If inside your simpleclass, is all variables on stack, i.e does not use "new "to allocate memory from, then yes, it creates a "duplicate", i.e copies all values from the object"sc" to the object "point".

mrnutty 761 Senior Poster

A conditional expression with more than 2 statement is just the same
as two separate conditional expression.

For example :

while( gameIsRunning )
{
        if( keyPressed )
            if( keyPressedIsX){ .. }
}

Is the same as :

while(gameIsRunning)
{
    if(keyPressed && keyPressedIsX) { ... }
}

So you see, you can think of a conditional loop with more than
1 expression as 2 or more.

Here are more examples :

do{
}while( playerIsAlive && ScoreIsNotNegative);
int grade = 0;
grade = scanner.nextInt();
if( grade >= 90 ) System.print(" You got an A" );
else if( grade >= 80 ) System.print("You got an B");
else System.print("You didn't get a B or an A\n";
mrnutty 761 Senior Poster
b = c/d
b=(c)/(d++)

The parathesis does not change what happens. It still reads from left to right. The post-increment operator returns d and then increments d.

For example this is roughly what the post increment operator does:

temp = i;
i = i + 1;
return temp