mrnutty 761 Senior Poster

>> Who would design a page with a bright red background and white text

Obviously reptilians! Their visions can handle colors better than we can.

mrnutty 761 Senior Poster

when you say, "back in my day...".
--------------------------------------------------------
Just for curiosity, whats the age group here in Daniweb? Anyone want
to tell their age? I'm 19.

mrnutty 761 Senior Poster

>>// output: 4 (?!) Shouldn't this be an error?
It is. And its a bad one, which went undetected in a sense.

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

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

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

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

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
int n = 15;
cout << hex;
cout << n << endl;
Excizted commented: thank you. +1
mrnutty 761 Senior Poster

"&" is the bitwise operator when used in proper context.
"&" is reference operator when used in proper context.
"*" is a multiplication operator when used in proper context.
"*" is a de-referencing operator when used in proper context.
"&*" is a reference to a pointer type.

mrnutty 761 Senior Poster

Yes. The main use of glut is to create a window and handle events. Windows API can do the same, so you can use win32 with opengl. In fact
in NEHE tutorial, thats what they use.

mrnutty 761 Senior Poster

Actually, here is the code. Your teacher will be impressed! =)
<snipped>

I beg to differ. Please, if you are going to blatantly give the answer
out, at least give a good answer. Not trying to be rude, just telling
the truth.

mrnutty 761 Senior Poster

In my last class, we made a ALU. We worked with 4 bit adder. It accepts
2 4-bit number and returned the addition of those number, but you knew
that. One usefulness I used the cout was to detect an overflow. Since a
4 bit number has the max representation 2^4-1, adding 2 4-bit could
cause an overflow, thus when carry out is true, there is an overflow,
since the highest bit carried.

mrnutty 761 Senior Poster

>>I can't believe nobody gets me. I believe in pi just like you do but I found out the hard way.

Are you sure, because all this time I thought we were arguing
because we disagreed in what pi was ?

mrnutty 761 Senior Poster

How did we go from pi to evolution to religion ?

Just leave him and his theories alone; There is no point.

tux4life commented: Exactly :) +0
mrnutty 761 Senior Poster

OMG, this is so urgent. Let me help you quick before the world ends.

This part :

char *fileName = new char;

That makes fileName a char variable, not an array. What you meant to
do was this :

char *fileName = new char[100];

But thats dangerous at this stage. Since you are using strings, just
do this :

string fileName;
...
 cin >> fileName;

ifstream inFile( fileName.c_str() );
...
mrnutty 761 Senior Poster

This question is from code chef, named Odd. I believe this
is a good problem to play with for all levels. If I can solve it surely
anyone else can, cough * only if pi is fake* cough*.

Here is the question :

The captain of the ship TITANIC is a little .... off the track. He needs to select the crew for the ship. But everyone seems to be eligible. So to test their intelligence, he plays a game.  The contestants have to stand in a line. They are given the numbers  in the order in which they stand, starting from 1. The captain then removes all the contestants that are standing at an odd position.  Initially, standing people have numbers - 1,2,3,4,5... After first pass, people left are - 2,4,... 
After second pass - 4,....
And so on.
You want to board the ship as a crew member. Given the total number of applicants for a position, find the best place to stand in  the line so that you are selected.
[B]Input[/B]
First line contains the number of test cases t (t<=10^6). 
The next t lines contain integer n, the number of applicants for that case. (n<=10^9)

[B]Output[/B]
Display t lines, each containg a single integer, the place where you would stand to win a place at TITANIC.
Example

(Added) *Comments below not needed in the output;

Input:
2  //number of inputs 
5  //number of applicants
12  //number of applicants


Output:
4  //best position …
jonsca commented: Are you okay, heck of a cough there LOL +1
mrnutty 761 Senior Poster

From my understanding of what I have been taught you cannot move diagonally on the grid so say you were on point 0,0,0 (x y z) and wanted to get to point 1,1,1 (x y z) then you would need to first move up then move across x then move across y as the corners of where the lines meet on the grid are like barriers. And that is where the cube effect comes in which makes me wonder if there are by far more than 3 dimensions.

You just disregarded my main point :
"So realize that, Cartesian coordinate, polar coordinate, cylindrical coordinate, or any other coordinate one uses, is only a model. Its just a way to represents something. Its NOT REAL "

mrnutty 761 Senior Poster

But for the object to move diagonally that would require moving along multiple axis making things ultimately move like cubes. This would also mean gravity and other forces would have a cube effect in their direction. So it would be impossible to just use 3 axis as 3 axis only allows the positioning of objects and not the diagonal movement of objects.

Also I read your link and is basically a bunch of formulas.

Wow. I tried so hard not to post.

Ok now listen to my argument :

Imagine you lye on a Cartesian grid, at the origin. OK ?

Now you say that to get at point, (1,1), we need to first move
1 unit in the x axis, then 1 in the Y axis. Correct ?
Thus the "cube effect" ? And that was your reasoning, correct?


Ok, now let me give you my rebuttal. So imagine you are again
located at point (0,0), in a Cartesian coordinate. And your
target is to get to point (1,1).

Now here is the question : Would, you first move right one, and then up one unit thus ending up at point, (1,1)
or would you simply take a diagonal step towards the point(1,1) ? Obviously, a sane person, would move diagonally. And the reason why one would take the diagonal step, is simple; because we can.

Now here is the more important part, Notice that you …

mrnutty 761 Senior Poster

There is also http://www.gamedev.net/community/forums/ which has really a lot of smart developers that has been programming for a while, and also developing games for a while in the industries. Although its not necessarily c++, post in the beginners section, then there is a 99.99% guarantee, that your problem will be solved, specially, if its related to game programming, but not necessarily.

mrnutty 761 Senior Poster

Thanks for the replies,is this because *p1 is derefrenced here so contents can be added?

Yep, just think about it like this, if ptr is a pointer-to-int, then *ptr,
is the value that it points to , so if it points to an address, which
has the value 4, then *ptr == 4 is true.

int a = 4;
int * p = &a;

int t = *p; // same effect  as int t = 4;
mrnutty 761 Senior Poster

My perception of you. serra01 is a spammer.

mrnutty 761 Senior Poster

get rid of all the unneeded " //----// " it makes the code unreadable.

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<cctype>
#include<string>
using namespace std;

 

int main()
{
	//Filestream Object Declaration
	ofstream alphabet( "C:\\alphabet.txt" ) ;
	//Variable Declarations
	string sentence ;
	//User Input Prompt
	cout << "Please type a compilation of alphabet characters in no particular format below, press 'Enter' to count alphabet characters.\n" << endl;
	//Capture User Input Store In string 'sentence'
	getline( cin, sentence );
	//Error occurrence of file write to user
	if( ! alphabet )
	{
		cout << "Error occurred while attempting to open 'C:\\alphabet.txt'." << endl ;
		return -1 ; // Error signal occurrence
	}
	//Successful occurrence of file write to user
	else
	{
		cout << endl;
		cout << "Character compilation saved successfully to 'C:\\alphabet.txt'!" << endl ;

	}
// Write User Input To File 'C:\\alphabet.txt'
	alphabet << sentence << endl;
	// Close Filestream
	alphabet.close();
	

	//Variable Declarations
	int count[26] = {0} ;
	char c ;
	int nonletter = 0 ;


	//Input Filestream Object
	ifstream readAlphabet( "C:\\alphabet.txt" ) ;

	//Error occurrence of file input to user
	if( ! readAlphabet )
	{
		cout << "Error occurred while attempting to open 'C:\\alphabet.txt'." << endl ;
		return -1 ; // Error signal occurrence
	}

	//Successful occurrence of file input to user
	else
	{
		cout << endl;
		cout << "'C:\\alphabet.txt' successfully input to program!" << endl ;

	}

	//PROCESS THE FILE
	readAlphabet.get(c);

	//WHILE LOOP
	while ( ! readAlphabet.eof() ) 
	{
		c = tolower(c) ; // Make all characters lower case

		if (c >=
mrnutty 761 Senior Poster

There is no through getting to him. Just let him be.

mrnutty 761 Senior Poster

Pretty cool. Looks something someone will see if they were high of drugs.

mrnutty 761 Senior Poster

>>output("1", "k"); // ?

should be a string :

output(string("1"), string("k")); // ?

Whats happening is that "1" and "k" is being interpreted as a const char*

mrnutty 761 Senior Poster
cout<<"*"<<endl;
cout<<"   *"<<endl;
cout<<"    *"<<endl;
cout<<"  *"<<endl;
cout<<"*"<<endl;
mrnutty 761 Senior Poster

Well it will ask you questions of what you have covered.

Salem commented: Aparently, this wasn't obvious to the OP - it does not bode well for the exams... ;) +17
mrnutty 761 Senior Poster

But if you print it out with a huge dpi (dots per inch) then it is a perfect circle. This is because the ink is 3d.

No false, no matter how precise you get, its never a perfect circle.

mrnutty 761 Senior Poster

If you believe Paint or any other circle drawing program isn't accurate then let me demonstrate in a 3d model using 3d blender. I have drawn a perfect circle using 12 cyphers and if you connect them it will make your circle. However, in real life they are bunched together like in the MS Paint model. This is because each atom is so tiny that each atom does not have enough sides to form the perfect circle. Basically in the 3d model because there are 32 sides for the cylinder that means it can attach on whatever angle. However if they can only attach on the sides or direct diagonal that is where the MS Paint model is by far more accurate. This is really going into atomic physics now. You will find that atoms cannot attach on any angle that we can write down (example 98.35869049696 degrees). However they can attach on a certain number of degrees. It is due to this limitation that pi will never be true. Why? Take a look at my diagram, all the circles are at different angles to each other. what if you had 4,000,000,000,000,000,000 points in that circle. In reality that is only a few cm's. Then you would have to have some atoms beside each other and above each other to be able to make the perfect circle. And remember that atoms need to all be attached. That forces another limitation. If they need to all be attached and they have …

jonsca commented: Yes +0
mrnutty 761 Senior Poster

Virtual functions and polymorphism are closely related.

A virtual function means that a some class with a virtual function will be derived from, and that virtual function will be overridden by the derived class.

To declare a virtual function the syntax is :

class VirtualBase{
public :
virtual void draw(){ cout << "drawing in virtualBase\n"; }
};

Notice that the virtual function is inside of a class, thats because it only makes sense for it to be in a class.

Take a look at this example :

class Based{
public : 
virtual void speak(){ cout <<"based\n"; }
};
class Derived : public Based{
public:
void speak(){ cout<<"derived\n" }
};

Notice that Dervied inherits from the Based class, and overrides the speak function. Now here is where the polymorphism comes in. When you have objects from base or derived, a base class object pointer can
point to either the derived class or the base class, and when you call the function speak with the base class pointer, the compiler will call
the speak function of either the base class or the derived class, depending on which it points to. Take a look :

#include <iostream>

using namespace std;

class BaseClass{
public:
	virtual void speak(){
		cout<<"Base Class says : Rough...Rough\n";
	}
};

class DerivedClass : public BaseClass{
public:
	void speak(){
		cout<<"Derived Class says : Meow...Meow\n";
	}
};

//Remember that a BaseClass pointer object can point to 
//a BaseClass object, or a DerivedClass object.
//and …
Clinton Portis commented: droppin' some mad knowlege on a complex topic +5
mrnutty 761 Senior Poster

I also have a theory and am still working on a formula to prove that pi is not infinite in length. If pi were infinite in length then the circle would have have an infinite circumference. And using MS Paint I have found that pi is not always 3.1415. It can vary depending on the size of the circle. For example, a circle about 6 atoms in diameter will produce pi of 3 instead of 3.1415... This can be proven with 2d cg models so try to draw a perfect circle in MS Paint. Then count how many dots in the circumference and divide it by the number of dots in the diameter and you will rarely get pi to more than 1 digit for a small circle.

Sorry man, but this I find stupid. First This statement is wrong :
<quote> If pi were infinite in length then the circle would have have an infinite circumference.</EOQ>

Just because the sequence is infinite length does not mean that
its value is infinity, and therefore the circumference of the circle is
not infinite.

And you can't use any software to draw a circle and prove that pi
is not 3.14159... because the circles are actually pixels, which are
rectangles. What you are trying to disprove is math. And if anything in this world,
I know that math is purely deductive.

mrnutty 761 Senior Poster

How about using strings to represents float, char, double, int, and so on.

string Types[4] = { "124","1.234","aString","c" };

Then you can convert it accordingly with sstream.

mrnutty 761 Senior Poster

plzzzzzzzzz tel me basics thing of programing

yaaa gotta make variables, then use ifs and loops is ther anythn else ya gotta know?

Ya gotta learn english 1st.

zobadof commented: This is very funny!! :) +1
mrnutty 761 Senior Poster

>>I think do you have the idea and please help me sir with my project...

Not really, care to explain a bit more?

mrnutty 761 Senior Poster

From :

while ((cin >> ar[i]) && (i < arSize))

To :

while ((i < arSize) && (cin >> ar[i]) )
mrnutty 761 Senior Poster

So I was thinking, we should have a challenge of the day or week,
for a specific language, that poses a unique problem. This way people can practice, and others can learn maybe something new from someone else's idea. What do you guys think ? For example in our
C++ section, we can have a C++ challenge question. And people can participate in it. I know I would like to know other people solutions
to a problem. That way it will help me think in different ways.

mrnutty 761 Senior Poster
lastElem =remove_if(v1.begin(), v1.end(), islowerCase);//line1

Line 1 : remove_if(...), if the containers contains a lower case character
the function removes it. It does this, and returns the a pointer that
points to the new end since some elements has been deleted.

ostream_iterator<char> screen(cout, "");//line2

Line 2 : creates an iterator. Just like the vector::iterator, ostream_iterator is an iterator. It can insert elements into the
ostream object, cout. When you do :

cout << 'a';

Its almost the same as if you do :

screen = 'a';

Its just doing it in a different way.

copy(v1.begin(), lastElem, screen);//line3

Remember what I said, if you do screen = 'a'; It will print out a into the
console. So the above code roughly does screen = vec[0] ... vec[lastElement]. That means everything inside the vector is getting
printed to the screen.


Also check this out for some reference : remove_if , istream_iterator using std::copy

mrnutty 761 Senior Poster

Put the definition in the same file as the templete header, unless your
compiler supports the keyword export.

mrnutty 761 Senior Poster

is there any way to prevent this???

Yes there is, probably.

mrnutty 761 Senior Poster

>If you want to do it that way, you will need to make that function a friend function.
Yes, thank you for the correction. I'll blame a disconnect between my brain thinking friend and my fingers thinking member. ;)

No problem. Its good to see that you are a human as well
and not an all knowing android.

mrnutty 761 Senior Poster

>which one is necessary to overload if i would like to make -x understanable for the compiler?
The negation operator is a single argument member function:

class foo {
public:
  // Overload negation
  foo operator- ( const foo& obj );
};

That is not overloading the negation operator. Thats overloading
the subtraction operator. A negation has no arguments and
deals with the this pointer. If you want to do it that way, you will need to make that
function a friend function.

mrnutty 761 Senior Poster

By the example you gave us, this : "mcDonalds car 456 burgerKing 8
clowns are scary money leeking from 56 my pockets I like turtles 1".

I would suggest that you should extract the sentence word by word.
Then when you extract a word, you need to check if its a numeric by
using the isdigit function in cctype header file. If it is numeric, then
you can extract the data into a int variable and add it to the total sum.
Here is an example :

#include<iostream> //i.o
#include<cctype> //for isdigit
#include<sstream> //to phrase string
#include<string>

using namespace std;

//checks if a string is full of digits
bool isDigits(string word){
	for(unsigned int i = 0; i < word.size(); ++i){
		if(!isdigit(word[i])) return false;
	}	
	return true;
}
int main()
{
	string sentence = "what does 10 + 4 + 1 = ";
	stringstream extract; // extract words by words;

	extract << sentence; //enter the sentence that we want to extract word by word

	string word = "";

	int totalSum = 0;

	//while there are words to extract
	while(!extract.fail())
	{
		extract >> word; //extract the word

		if(isDigits(word)){//if the string is full of digits
			
			stringstream convert; //converts strings to ints
			convert << word; //insert the digits into our converter
			int theNumber = 0; //will hold the number inside the string
			
			//convert the string number into a int number and place it inside of theNumber variable
			convert >> theNumber; 

			//add the number to the total sum …
timlo commented: to the point, carefuly going through the steps in the code so even the most novice can understand +0
mrnutty 761 Senior Poster

But on the other hand the efficiency of these are completely different :

//with pointers
void DivideBigNumbers(BigNumberClass * num, BigNumberClass * num);
//without pointers, just object
void DivideBigNumbers(BigNumberClass  num, BigNumberClass  num);
//and there is reference
void DivideBigNumbers(BigNumberClass&  num, BigNumberClass&  num);
jasonline commented: I agree. It really depends on the situation. Passing parameters by reference/pointer is recommended to passing by value. +1
mrnutty 761 Senior Poster

Modulo 10?

eg:
54%10 = 4

TO expand x % 100 will give you the last 2 digits, and x % 1000 will
give you last 3 digits, and in general :

x % 10^n will give you the last n digits. IN the special case
where n = 0, the result will always be 0, since you ask to get the last "0" digits, which does not make sense.

mrnutty 761 Senior Poster

Can you give me an example, as to how to use this, because I want to set the range of numbers.

int main()
{
   srand( time( 0 ) );

   cout << rand() % 2 << endl;
}
mrnutty 761 Senior Poster

Hi i want to friendship with a cut girl if there is anyone intrested reply me plz:*

This is too funny. One of the few post that made me laugh. You made
my day thinkersgroup, anyone see the irony with his name?

mrnutty 761 Senior Poster

This is a good read. Read it and learn from it.

mrnutty 761 Senior Poster

>I have no clue on how to do this please help thank you
You'd better learn quickly how to deal with this situation without running to someone else for hand holding. The majority of the time, a programmer has no clue how to do something. That's why it's such a difficult field: we actually have to think and figure things out. :icon_rolleyes:

But seriously, "I have no clue how to start" is synonymous with "I'm too stupid to be a programmer". It's like you're telling us not to waste our time helping you because it's a lost cause.

Yea, what he said.

gastonci commented: Best coment ever!!! I pist myself laughing +1
mrnutty 761 Senior Poster

Ok then, some comments.

Where is ch declared in : ch == lower

Why are you returning in a void function?


Make a toUpper fuction, that takes in a char and returns the upper cased of it.

So for example :

cout << toUpper('a') << endl; //displays 'A';
cout << toUpper('A') << endl; //displays 'a';

Then you can just use a loop for a string to upper it.

string str = "upperThis";
for(int i = 0; i < str.size(); i++)
     str[i] = toUpper(str[i]);
vickietende commented: i think this code is more appropriate but could you care to put the whole code snippet and i could test how it runs +0