mrnutty 761 Senior Poster

@OP or a more generic approach:

struct InvalidInputException : std::exception{
 InvalidInputException(): std::exception("Error: Invalid conversion") {}
};

//tries to get a data of type T, throws InvalidInputException if failed
template<typename T>
T prompt(const std::string msg){ 
  cout << msg ;
  T res = T();
  if( ! (cin >> res) ){ 
      cin.clear();
      while(cin.get() != '\n' ) continue;
      throw InvalidInputException();
  }
 else return res;
}

int main(){
 try{
   int age = prompt("What is your age? ");
   string name = prompt("What is your name? ");
  }catch(std::exception& e){ cout << "whyyyyyyy?\n"; }
}

@psuedorandom: I like that solution but some things,

1) The name int_type is misleading since the user can use that function to get a string for example.
2) I don't like the performance issue with writing just one input to a file everytime that function is called, I would rather do lazy write and write only when necessary.


and I guess whether the function should throw exception on failed input is a matter of choice.

mrnutty 761 Senior Poster

Forgot to mention you need to use fixed format:

double d = 5.0;
cout << fixed << setprecision(1) << d << endl;
mrnutty 761 Senior Poster

You can simply append 0 since it does nothing:

string toString(const double d, int nZero = 0){
 stringstream stream;
 stream << d;
 return stream.str() + string(nZero,'0');
}

If you use the double value to print out the value then you can set its precision like so :

double d = 5.0;
cout.precision(4);
cout << d << endl;

or using <iomanip>

double d = 5.0;
cout << setprecision(4) << d << endl;
mrnutty 761 Senior Poster

In my internship, they use the scrum method. It seems to be a good method. Google that.

mrnutty 761 Senior Poster

This thread needs to be closed now

mrnutty 761 Senior Poster

Why do you need to use C++? Use the right tool. I suggest you to use javascript.

mrnutty 761 Senior Poster

Yes, I know. And it's easily the most complex part of the standard C++ library. How many hundreds of pages do you expect for a complete description of everything that's going on?

just curious, why would you take the trouble to learn that? For fun?

mrnutty 761 Senior Poster

just look at what it gets and you'll see:

int x = 0;
while(cin >> x) { continue;}
cin.clear();
//discard junk and print out whats being discarded:
char ch = 0;
while(cin.get(ch) && ch != '\n') cout << "Discarding'" << ch << "'" << endl;
mrnutty 761 Senior Poster

A hint, read the definition of a binary tree, then see how it applies to the trees's children.

mrnutty 761 Senior Poster

whats this supposed to do:

while( cin.get() != '\n' );

there isn't a body for the while loop.

it reads the stream character by character but doesn't save the read character, it just does nothing with the read character, if we wanted to save the character, we could have done this :

char ch = 0;
while( cin.get(ch) && ch != '\n') { 
 //do something with ch variable, which contains the read junk character
}
mrnutty 761 Senior Poster

I'm not completely sure but you might be able to do this

std::wstring basePath(L"file:");
std::wstring subPath(L"src/main.cpp");
std::wstring fullPath( basePath + L"\n" + subPath );
MessageBox(0,(_T)fullPath.c_str(),0,0);
mrnutty 761 Senior Poster

It first reads 2, and stores it in x. It then reads 4 and stores it in x. Reading is done so now it executes the body. The 6 you entered also, does not get read into x or y just yet, because the stream already read 2 and 4, so the 6 stays in the stream for later, so when you entered 8, in the stream there will be 6 and 8 now, 6 gets read into x and 8 gets read into y, and the body executes.

mrnutty 761 Senior Poster

In the first while loop your exit condition is when cin fails. It will fail when it reads in something that its no supposed to. Its expecting a integer( a number ), and if you pass it a character, then cin fails and it sets the failure bits accordingly.

Now in your second loop, cin is still in a fail state because you haven't reset the cin stream, thus the failure bits are still set and thats why it doesn't execute. To solve your problem, you need to reset the input stream.

int x = 0 ;
while( cin >> x) { cout << "read : " << x << endl; }
//if we are here, then cin failed so we need to reset the stream
cin.clear(); //clear or reset the failure bits
while( cin.get() != '\n' ); // throw away any junk that is in the stream after failure
int y = 0;
//now cin is reseted so use it normally
while( cin >> y ){ cout << "read : " << y << endl; }
mrnutty 761 Senior Poster

It's rather hard to define "C++ experts". Is only knowing the language inside and out enough to be called "C++ experts". Knowing how language work sometimes does not guarantee that they are proficient with the language or they are using the language efficiently.

ex·pertA person who has a comprehensive and authoritative knowledge of or skill in a particular area.

Thus C++ expert roughly means to me, A person who has a comprehensive and authoritative and full knowledge about C++.

Note that I make no claim that they are expert programmer, but usually, if one is smart enough to master C++ then he is probably a good programmer at the very least.

mrnutty 761 Senior Poster

I just downloaded a document containing some pointers exercises. The statement of One of its questions is as follows:

Write a function that returns a pointer to the maximum value of an array of double's. If the array is empty, return NULL.
double* maximum(const double* a, int size);


It confused me a little. I am wondering what is meant by an empty array? Does it mean that all elements of the array are 0 or 0.0? Or if it means the number of elements in the array is zero? If the case is second then is it possible to declare such an array?
Or there is some third case??

Sorry for such an awkward question though ..... :icon_confused:

Thanks for your time!!!!!

When an array is empty, generally, it means if its size is 0, but under certain context, it could mean something else.

And your right when you say you can't declare a static array with size 0. As narue pointed out, it mean when size <= 0.

mrnutty 761 Senior Poster

I don't see anything wrong. I would suggest for good practice also setting your pointers to null when you deallocate them. I sometimes like to define delarr in a preprocessor macro:

#define delarr(X) (delete[](X));((X)=0)

Hope this helps. (Also I may be wrong so more people should check as well)

If good practice is what your after, then it would be a good practice to use standard containers.

mrnutty 761 Senior Poster

Now when you have the basics of programming, you can go for .NET platform? or may be C++ in another case. I have seen a lot of C++ experts out there in DW like Salem, Ancient Dragon. Great guys to learn something from, Cheers!

No offense to them, but I would say there are like 9 experts in C++ in the whole world, by experts, one who knows the language inside and out, so I wouldn't say they were experts, but rather, knowledgable.

mrnutty 761 Senior Poster

start coding, just because you know theory doesn't mean your good at applying them. So start coding, gitty-up

mrnutty 761 Senior Poster

idk too much about jQuery but it seems you can abstract:

<script>
function foo(name,id)
{
       var $j = jQuery.noConflict();
	$j(function() {
	    $j(name).click(function(evt) {
		$j(id).load("content.php?order=most&f=recent")
		evt.preventDefault();
	    })
	})

}

 foo("mostrec","#1");
 foo(".leastrec","#1");
 //...so on
</script>
Pinchanzee commented: Simple + effective +2
mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

Hint: Use your pivot algorithm to work from the bottom up instead of top down

mrnutty 761 Senior Poster

Just a quick thought on this topic...

If you're a confused Christian, then perhaps you're not a Christian (which is not a bad thing). In other words, it's almost like a left handed person is being forced to be a right handed person.

Perhaps I'm not or perhaps I am, but thats what I'm trying to find out, who I am and what I believe in. Been doing a lot of research lately, and its becoming more clearer to me, but still hazy. But in time...

Thanks everyone for your responses and criticism.

regards, D.Chhetri

Azmah commented: your welcome :D +0
mrnutty 761 Senior Poster

In your getCalc function, make cout and else and if statements lowercase

mrnutty 761 Senior Poster

it just seems wierd that if u truly want to read 4-bytes from memory address x00000007 you the processor must read starting from x00000004-x0000007 then make another read from x00000008-x0000000B then shift the unneeded bytes off! I was wondering why u cant say hey man lets read 4 bytes starting at address x00000007 ;) see what i mean :P?

Because mis-alignment isn't a regularly occurring event, thus computer are optimized against it, that is make each address a multiple of word size.

mrnutty 761 Senior Poster

First of all, I am a confused christian, and I am creating this thread to see if I can clear out some fog in my head. So lets start.

Claim: The bible is false in the sense that it was not written with the guidance of "god"

Reasons for my claim :

  1. Originally there was a lot of contradiction in the bible because it was written by humans
  • These contradictions were refractor-ed by a humans, specifically some committee of who's name I can't recall
  • No claims, if it wasn't for all of these refractor, more and more people will be aware of such contradiction and hence people will start to question and possible see the problems with the bible. Which could cause a tremendous loss in the business of selling bibles and spiritual objects

[*] There are things in the bible, still, that regular people find disturbing, such as the topic of homosexual, or parsing men more important than women.

  • Really, if it was written by god's disciples, and were the words of god, then such discrimination shouldn't exist, because god is suppose to love everyone of every type.
  • It also says that unless you follow him specifically, you will live eternity in hell? WTF!!! My family members are hindu, they are one of the best people that I know. My friend is not a believer in jesus, but possibly of a creator in general. He is one of the …
mrnutty 761 Senior Poster

Try increasing the speed to like 2000, is the ball position printing in different coordinates? If the if statements getting executed?

mrnutty 761 Senior Poster

Since you are reading the book, I assume you have some knowledge, so here is a basic start

class Quadratic_int{
private:
 int *coefficients;
public:
 Quadratic_int(); //default constructor 
 Quadratic_int(const Quadratic_int&) ; //copy constructor[ one of big 3 ]
 ~Quadratic_int(); //destructor[ two of big 3 ]
 Quadratic_int& operator=(const Quadratic_int&); // assignment operator[ three of big 3 ]
 //..possibly more function for quadratic class
};

Now you need to define the skeleton above. THink about it and start coding. If your stuck, then you aren't thinking, reading, and researching enough.

mrnutty 761 Senior Poster

Tell me about these and give me some negative and positive code examples.
>>Stack Unwinding
>>Constructors, Destructors and Exception Handling
>>Exceptions and Inheritance

thnx for information

Stack Unwinding - its when a stack unwinds
Constructors/Destructors/Exception Handling - its when you use constructors/destructors/exception handling
Exception and Inheritance - Its when you use exception and inheritance.

Hope that clears things up.

mrnutty 761 Senior Poster

Use that min/max values to setup a bounding box for your camera. Then it would be the same comparison as your other bounding box collision test.

mrnutty 761 Senior Poster

Sounds like your using the wrong language all together. Consider using java, where it has all that for you, or just use pure C++ with a GUI library support. The easiest route would be to use java, but that depends on if you know java and how well you know it.

mrnutty 761 Senior Poster

Simplify this:

bool isPalindrome(const std::string& s)
{
    std::string sReverse = s;
    std::reverse(sReverse.begin(), sReverse.end());
    return s == sReverse;  // return true if the reverse is the same as non-reverse
}

to this :

bool isPalindrome(const std::string& s){
    return s == string(s.rbegin(),s.rend());
}
mrnutty 761 Senior Poster

Thanks a lot. I'm reading it now:)

EDIT:
It is nut :(, are you kidding?

I'm at my internship right now, so when I'm home I'll try to explain it to you. Yes it helps if you know linear algebra already, so read up on that first, specifically about matrices and vectors. Then re-read that link. I'm sure in the time being, someone else will help you. Good Luck.

mrnutty 761 Senior Poster

Read this. It has very good explanation.

mrnutty 761 Senior Poster

>It sounds absurd that google can keep by gmail in their database and sell it to whomever

You'd think wouldn't you. But the 'google-sphere' is probably more sinister than we realize, or at least has the potential to be. They probably even keep tabs on what users search for.

Building these type of profiles can clearly bolster their dominance over would be competitors, yahoo pffft. Anyway, I digress.

Your making google sound like the government lol.

Azmah commented: very creative thought firstPerson XD +0
mrnutty 761 Senior Poster

Sucks at it happens. Thats why once a while you should hit cntrl-s( save shortcut ). This happened to me many times, and I learnt my lesson.

mrnutty 761 Senior Poster

Your code is not easy to look at and your description is rather vague. To solve your problem all you have to do is use one stack for original input and use the other stack for reversal input like so :

#include <iostream>
#include <stack>
#include <algorithm>

using namespace std;

void printStackReversed(const std::stack<int>& data);

int main(){
 std::stack<int> inputStack
 int tmp = 0;
 //get user input and save it in our input stakc
 while(cin >> tmp){ inputStack.push(tmp); }
 printStackReversed(inputStack);
}

void printStackReversed(const std::stack<int>& data){
 std::stack<int> cpy(data);
 std::stack<int> rev; //will hold our reversed stack
 //while our copied stack is not empty
 while( !cpy.empty()){
  //add it to our reversed stack, placing the top element in the bottom
  rev.push( cpy.top()); 
  //remove it so we can do the same for the next element if any
  cpy.pop(); 
 }
 while(!rev.empty()){
  //print out the reversed stack
  cout << rev.top() << " ";
  rev.pop();
 }
}

I haven't tested the code but it should give you an idea, which is to utilize the LIFO property of stack

mrnutty 761 Senior Poster

Try calc_av(total,n)

mrnutty 761 Senior Poster

Because 4 + 5 + 6 + 7 = 22

mrnutty 761 Senior Poster

Formula is:

s_n = n/2 * (a0 + an)

for example,

sum from 10 to 15 is:
s_6 = 6/2 * (10 + 15 )= 75

where we note that 10 is the first term and 15 is the sixth term

More details here

mrnutty 761 Senior Poster

>>@firstPerson: >> because reference needs to be pointing to a valid object
That is not strictly true. References can point to invalid objects (or deleted objects). But it is true that it is much harder to make that bug happen with references, while it is a lot easier to make that error with a pointer.

Yea yea yea, I glanced over that topic in my head but didn't write it down because I didn't think it was noteworthy for this thread, but thanks for mentioning it.

mrnutty 761 Senior Poster

Thank you for your reply..that's what i thought from the beginning, that i would definitely have a memory leakage..But my example works perfectly when i try to use my table's data, even if i didn't deallocate it correctly..Why is this happening?

Just because you have a memory leak doesn't mean your program will not work,it just mean that you are leaking memory.

mrnutty 761 Senior Poster

>>So I found that there was a difference between passing by pointer and by reference with by reference being safer. I'd like to understand why so that I can learn what is best to use when

Yes reference can be safer and most likely will be, simply because reference needs to be pointing to a valid object, where a pointer can point to an invalid object( i.e null object type )

mrnutty 761 Senior Poster

Yes in that for-loop example there would be a memory leakage if you don't deallocate the tab before reallocating memory for it again.

&tab means take the address of tab, in which if tab is an array, then when you pass it into a function, it decays into a pointer, so you will effectively be taking an address to a pointer, in which the pointer points to an array of elements.

mrnutty 761 Senior Poster

Both example are similar, no you do not have a memory leak although there might be subtle problems with your first example. In general, use reference when possible instead of pointers. I'm sure mike below me will give you a more elaborate answer soon.

mrnutty 761 Senior Poster

My post was intended to be sarcastic apperently some people misinterpreted my text and I appologize. I was trying to convey the same point as you firstPerson. And by google I mean he can gain the tools he needs to do the coding through google searches. The reason for my response as it was is he is simply asking for an answer without giving any effort first.

NP, I didn't interpret your post incorrectly, I was just accentuating your point without the sarcasm. Note, OP, you should google a little bit, but not to find answers to your main problem( like reversing a string ), but to find reference for C++ and its capabilities. Later down the road, when you believe you are a competent programmer, then using solutions that someone already wrote is a good idea because it assumably should be tested and debugged and benchmarked for performance. But don't worry about that, right now you are in your developing stage, and should try to solve the problem on your own while using google and others as guidance

mrnutty 761 Senior Poster

meh

mrnutty 761 Senior Poster

On the contrary to whats being said, I advice you to not google it, not use std::reverse and not use std::string.rbegin() in conjunction with std::string.rend().

Your purpose should be to get better at programming, so one day you can solve problems by rational thinking, instead of googling everything. Then you will be more valuable. So first think of what you need, write ideas on notepad. Then try to implement it. We will be here waiting to help you in any way possible.

mrnutty 761 Senior Poster

I seriously doubt they ever delete the data, it's far too valuable for their marketing departments (and too much links to it, like "friends" networks).

Orkut, being owned by Google, of course (like Google) never deletes anything at all. Same is true with GMail. If you delete a message there it's just made invisible to you, but still used by Google themselves for their purposes (thus can be sold to 3rd parties if they pay enough).

That's where the income from those sites comes from. If you don't like your private data being sold to the highest bidder, don't use them.

Where are you getting this information? It sounds absurd that google can keep by gmail in their database and sell it to whomever, I was thinking more like they make their money from advertisements and such.

mrnutty 761 Senior Poster

Create a recursive solution where it creates N/M by N/M subchunks where N > M and N % M == 0, and creates a separate thread to calculate the product of the two matrix using LU decomposition, and and uses that result for the parent subchunk.

Other than that, use a external library that has the calculation features that you need already and that could potentially take into account the architecture for optimization.

mrnutty 761 Senior Poster

Your camera has some position associated with it, check that position for potential collision and if collision moving up should mean a slight sliding to the right or left depending on the view vector