siddhant3s 1,429 Practically a Posting Shark

>An alternative is for you to simply add alias cls='clear' to your .bashrc file (assuming you use bash).
Ofcourse I know that on Linux the command is clear. I was telling him what does portability actually means. I was encouraging him to write codes that work on multiple platform rather than stick to one.
A general working rule is : Don't use shell command until it is important.
Another thing to add is system() is very well portable, but the command it takes are not.
Read a perfect article on why system() is bad :http://www.webinmind.net/bpc.html#six
It is non-portable, It is unsecured, It is slow.

siddhant3s 1,429 Practically a Posting Shark

Lets see what was the problem with the earlier approach. You were having one instance of TemplatedFoo.impl in your ultra.cpp and you were having another instance of TemplatedFoo.impl in the class1.cpp right? So, here is what the compiler did when you issued g++ ultra.cpp class1.o . He first already had compiled the the class1.cpp to make class1.o and as the TempletedFoo.impl was included in class1.cpp, all the definitions of

Foo<float>::Foo(const float value )  
Foo<std::string>::Foo(const std::string val)

got compiled within the class1.o. So now, all the definations are already in the class.o
Next what happened was, that the compiler now tried to compile ultra.cpp. Note that you indirectly had included the TemplatedFoo.impl also, right? But the compiler will compile this also, without consedering that you already have a compiled code for this. But now look what problem does the linker makes. Linker, while linking the two obj files class.o and ultra.o will find multiple definitions of all those function you defined in TemplatedFoo.impl

The later approach works because because you have not included the TemplatedFoo.h in your class.h hence the TemplatedFoo.impl does'nt get included in the ultra.cpp. Its not the "stl" aproach but it is something called, using-common-sense-while-including-files approach.
And don't worry, no one hits the jackpot at the first place.

Now, please summarize what all problem is left with your code.

siddhant3s 1,429 Practically a Posting Shark

And please use a loop to get beck to the menu();
Don't call menu() inside menu() it is bad.
Also, please read the posts that we wrote. It surely takes time to type all those stuff.
Moreover, you are again using system("cls") please do not use system() its also very bad. It makes your program unportable. For instance, the program that you gave will give a shell prompt error on my operating system (Linux). Got it?
So DONT USE SYSTEM("CLS")

siddhant3s 1,429 Practically a Posting Shark

Although Salem had clear it up all, but maybe for a reference you can read :http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.11

siddhant3s 1,429 Practically a Posting Shark

Please use a proper loop( a do-while should do in this case)
Please use switch case instead of if( it was made for situation like this)
Please do not use system() (it is unportable)
And as stilskin said: if(select = 1) and if(select == 1) has a hell lot of difference.
The former one is ALWAYS true but the latter one is true only if value of select is 1

siddhant3s 1,429 Practically a Posting Shark

Narue, I sent you PM,
I think you are kind of protected by some spam filter hence would not receve my PM. If you can't do tell me. and yes........... No more off topic posting.

siddhant3s 1,429 Practically a Posting Shark

You cannot do simply like that. Templates require speacial treatment.
Always remember that the template code is never compiled until the compiler sees the function call. I just solved a similar issue few days back. read the post :http://www.daniweb.com/forums/thread178735.html It will surly help you
PS: You can skip the initial crap what we were talking about read from 7th posts http://www.daniweb.com/forums/post814445-7.html

siddhant3s 1,429 Practically a Posting Shark

>p.s. You can't take back something once it's said. I've tried, and it doesn't work.
Hmm, you are right on this, I also just tried but it didn't work.

And here is why I thrashed him :http://www.daniweb.com/forums/thread178893.html << a same post with same remark.
And look what he said on this post : "pls give me a program on this, i cant seem to make the program work with regards to the location thing."

siddhant3s 1,429 Practically a Posting Shark

are you sure you have placed a #endif after the end of TemplatedFoo.h? if not, definately your code can provide you with trouble

siddhant3s 1,429 Practically a Posting Shark

>The operator part is what it already there which i couldn't change.
you mean its the part which is not written by you.
..........and can you show me the ensureSize()?
What about the capitalization of Class. It should not compile

siddhant3s 1,429 Practically a Posting Shark

I can't find a reason why not to thrash any one like that !!.

And also, I gave him a solution too........ Not one of those who just barks off for nothing!!

I can take back my "I mean please at least TRY." but I wont take back my "Read your text book!!"

Besides,(of topic) your pictures just suits you :) and I like the way you speak :D (you cant always prove others wrong LOL)

siddhant3s 1,429 Practically a Posting Shark

Class String;
the "C" of class is capital.
Well, anyways, I really don't know what does ensureSize() do (please provide its defination)
I also don't know about >>

os << "S(" << temp.m_length << "," << temp.m_bufSize
<< ")[" << temp.m_buffer << "]";

Explain me why did you inserted "S( __ ,__) [___]"?

siddhant3s 1,429 Practically a Posting Shark

Read your text book!!

I mean please at least TRY.
skatamatic, said use a for loop. Go search what is a for loop etc.
I will elaborate a little.
Use a for loop to accept all number in a array.
Use another for loop to check weather each of those elements is equal to the searched value.

siddhant3s 1,429 Practically a Posting Shark

If you are a learner and still in basic stage, I prefer you write your own class about Date and overload the comparison operator, and then work with them.

siddhant3s 1,429 Practically a Posting Shark
siddhant3s 1,429 Practically a Posting Shark

>Help me!!!! about operator overloading
It doesn't work like this. You should be more specific about what you want to ask.

First of all read this link -> http://www.parashift.com/c++-faq-lite/operator-overloading.html and come back.

BTW a short answer to why we use operator overloading is so that our class have a intuitive interface.
Suppose you are writing a class called Date then you can overload the - operator to give you the difference in days between two dates like

Date d1("5/5/1991");
Date d2("30/5/1991");
cout<<d2-d1;
ddanbe commented: Very good answer to the question at hand. +4
siddhant3s 1,429 Practically a Posting Shark

Why the heck you are using cstrings. They are old, they are evil and they can lead you in trouble.
Use std::string and be happy in life.

siddhant3s 1,429 Practically a Posting Shark

Point 1:
n*(n+1)/2 is even valid for n=1, so you don't need a degenerate case of n=1.
Point 2:
as vmanes said, your base case is good, but look at your recursive case: return (n+sum(n+1)) Try to think what would happen if I call sum(2)?
it would return 2+sum(2+1) which inturns means 2+3+sum(3+1) which inturns means 2+3+4+sum(4+1)
So, sum(2)=2+sum(3)=2+3+sum(4)=2+3+4+sum(5) and so on.

Ask yourself: where will it end? to infinity!
So, you should know that there is some blunder in return (n+sum(n+1))
Correct it.

siddhant3s 1,429 Practically a Posting Shark

You have any idea what are you asking?
We don't know you, nor your ability, nor that how much time you have, not how much brains you have. We know nothing of you then how can we tell what is a "mini" project for you.
Mini can be a Hello World program or mini can be a writing a C compiler.

Salem commented: I agree +29
siddhant3s 1,429 Practically a Posting Shark

>>My program is suppose to find the sum of each line
sum of each line??
what does that means?
and yeah, plz post the complete code to help us work upon.

siddhant3s 1,429 Practically a Posting Shark

Create a static member in your class which is a bool type 2D array (call it say,current_pos) of 8X8 elements.
Each time you assign a Position to the object, be sure to mark the current_pos[x][y]=TRUE;
So, now you can keep track of what all postition are been ocupied.
Hence, as soon as your random() generates a new position, check whether that position is already occupied or not. If it is, tell him to generate another number and so on.

Since the array will be a static member, its value will be same for all the object of the class.

siddhant3s 1,429 Practically a Posting Shark

What is this >>> NodePointer nPtr = new Node(dataValue);
what is NodePointer? I didn't see it declared in any of your code!

siddhant3s 1,429 Practically a Posting Shark

if (gmOption == 1) change it to '1' not 1 since gmOption is a char not a int.

cin >> cheat;
if (cheat == 236)

I think the cheat is 236 right? So it should be a string. Define your cheat as char cheat[3 ] and not simply as a char and use the strcmp() in the if statement as: if(strcmp(chear,"236")!=0) While the best way remains to use std::string like this:

string cheat;
cin>>cheat
if (cheat == "236")
{
}

Learn that there is a hell lot of difference between 1 and '1' or between 236 and "236"

siddhant3s 1,429 Practically a Posting Shark

When a file is opened is in Text Mode, the operating system's new-line character is auto-magically converted to the standard '\n'.

>Not sure what MAC uses.
BTW Mac uses "\r".
"On unix systems, the standard end of line character is line feed ('\n')."
source: https://developer.mozilla.org/En/C___Portability_Guide

siddhant3s 1,429 Practically a Posting Shark

Mark the thread as solved

siddhant3s 1,429 Practically a Posting Shark

Are you done? I still am seeing the thread as unsolved.
Solved link is near the bottom of the page

00Vic commented: I found his posts helpful for learning new concepts +1
siddhant3s 1,429 Practically a Posting Shark

Mark the Thread as solved.
Phew! I never thought this would take 29 posts to finish.
I am glad that you're done!

siddhant3s 1,429 Practically a Posting Shark

We only give homework help to those who show effort http://www.daniweb.com/forums/announcement8-2.html
Show efforts=get help

siddhant3s 1,429 Practically a Posting Shark

Yes, the last code you posted rocks! but again a few problems are there.
1. The catch{} should cout the error instread of setting a bool and again checking for a if (remember, the whole moto was to eradicate if's)
2. Remember, that you can always embed the cout<<pf_eq<<" = "<<answer<<".\n"; in the try{} block after the call to postfix()
In this way, you will automatically get the answer if no exceptions are thrown or you will get a error in case of exception(note that the cout<<pf_eq<<" = "<<answer<<".\n"; wont be executed once the exception is thrown)

siddhant3s 1,429 Practically a Posting Shark

and main should look like this...

The answer = eval.postfix(pf_eq); has been duplicated, once outside try and one inside. Use the inside one and remove the outside one like this:

cin>>pf_eq;
try{
    answer = eval.postfix(pf_eq);

DO the modification and tell me.

PS: use "(code=c++)(/code)" instead of "(CODE)(/CODE)"

siddhant3s 1,429 Practically a Posting Shark

Better, but Still not got it!
No problem. I will try to explain again:
See, the whole story of exception is to eradicate the need for checking anything in main() as you are doing

try{
		if (eval.get_bad_divisor()){ //<<<to eradicate this
			throw 1;
		} else {
			cout<<pf_eq<<" = "<<answer<<".\n";
		}

So now, you have already thrown a exception while dealing with postfix(), right?
I mean, you have already thrown the exception in the postfix() function, so you don't need to throw it again in main()[and neither there is need to check if (eval.get_bad_divisor()) ]
First of all, try{} block should contain all those function call which can potentially throw an exception. In your case it is postfix(). So you should include the postfix() in the try block. Now the code should appear like this:

case 1: // evaluate a postfix eq
	cout<<"Enter postfix expression: ";
	cin.clear();
	cin>>pf_eq;
             try{
		answer = eval.postfix(pf_eq);
		}
              catch (int q){
		if (q == 1){
			cout<<"Invalid division by !\n";
		         }
		}
             break;
//rest of your code..........

		}

Lets see what will happen in the above code:
You are calling postfix() in a try block, right? So, either two things can happen:
1.The postfix() don't encounter any div-zero error: In this case, no exception will be thrown by postfix() hence the try block will be executed fully and the control will return directly to Line13 (overlooking the catch{})
2.If postfix() emits a exception, the control will be (no matter …

siddhant3s 1,429 Practically a Posting Shark

>That makes some sense but I thought the catch needed to be placed just after the >try in the code.
Yes you are right. So that what I said:

.
.
.
{//in post fix
    if (somecondition)
        throw 0;//look, i hv not used any try{}
    .
    .
    .
}//end of postfix


int main()
{
    while (1)
    {
        try//here i use try
        {
//somecode
            postfix();
            break;
        }
        catch (int i)//and catch just after try{}
        {
            if (i==0)
                cout<<"Erorror";
        }
    }
}
siddhant3s 1,429 Practically a Posting Shark

>>I don't understand your complaint about using it inside the function
Ok, I am rather guilty, fine?
So, I think I would need to explain it further.
Look, You should throw an exception whenever you encounter a error in any piece of your code by using throw anumber whenever you encounter a error. But, use the try-catch block in the calling code of the function. Not when throwing exception. Getting it?
In short, you should write the try-catch block in main() and not in postfix(). Got it?
You should issue a throw 0 in postfix but catch it in main()
Phew!

siddhant3s 1,429 Practically a Posting Shark

Wow, a zig-zag flow of control.
But is definitely not a wow. Sit down with a pencil-paper and design a flow chart of your program.
The flow of program is not efficient.
main calls read/write which calls haha which can in turn call read/write and so on.
This is definitely not feasible.
Construct a loop as vmanes told you and remove the haha function.
Don't use system(). file.open(thing,ios::in|ios::out|ios::binary); Why did you opened in binary mode?

siddhant3s 1,429 Practically a Posting Shark

>It does use an exception though.
But it is not using the way it should. I guess my last post was of no use.
Do you know why exceptions were invented? To avoid checking the return value of each function for errors. And look what you are doing. You are still checking if(eval.get_bad_divisor()) in you main().So what is the point in using exceptions. And moreover, you are using the try-catch block inside the definition of a function that throws the exception.
I think you should read my last post again.
Well, I don't mind if you use the old return-value check approach, but then, please don't use (flawed) exception handling mechanism for just the sake of using it.

Another point: dont use #define MAX_SIZE 50
use const int MAX_SIZE=50; instead. Here is why:http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.7

I hope you understand my point about exceptions. Here is a good tut for you:http://www.ozzu.com/cpp-tutorials/tutorial-exceptions-t86515.html

siddhant3s 1,429 Practically a Posting Shark

Hmm,
>For example in my function the part of my switch that handles division would look like.......
Well, it is not looking good!.
The try block should be in the code which runs your function i.e. the main()
The general layout should be like this

{
//inside your evaluative function
case '/':
    if (b == 0)
    {
        throw 0;
        exit(0);//in case someone don't catch your exception
    }
    return a / b;
    ....
    ...
    ....
    ....
//end of your evaluative function
}


int main()
{

    while (1)
    {
        try
        {
             //do all the input output code here,
             //
             //
            break;//this will get you out of the loop if no exception is thrown
        }
     catch (int i)
    {
        if (i==0)
            cout<<"Error! div by zero";
    }
//flow returns here when a exception is thrown
//thus get back to the start of the loop again
 }//ending while(1)

}

>Does catch need to be a member of my class or would this be a global thing. (I don't exactly know where to put this in my code.)
catch{} is a global thing, should be put just after the try{} block

>Do I still need exit(1) somewhere? Ideally I would like it to deliver my error message then return to the menu instead of exiting the program if possible.
Use exit(1) just after you throw the exception. This will ensure that your program at least terminates(rather than screwing your machine resources) if the exception has not been handled. …

siddhant3s 1,429 Practically a Posting Shark

Returning by string means that you will again have to convert each value you get to integers(although, you can always define a inline function for that like I did). But this was the best method provided exceptions were not invented. Returning by void will be a crime.
Doing things without exception handling will be like following the I-dont-want-to-learn-new-things-but-screw-the-old-one way.
But a slight caution: exceptions are also a good way to make your code unportable in a sense that not most of people(who will study your code) will not catch your exceptions; That bothers you if you were designing a library.
So be sure to issue a exit(1) just after you throw an exception. These thing would make sense when you read about exception handling

Wish you luck!!

siddhant3s 1,429 Practically a Posting Shark

n^3 + (3n^2+2^n+1)^3 + (3n^3+3n^2+2^n)^3 = (3n^3+3n^2+2^n+1)^3
In the above equation, put different value of n=1,2,3,4,...... and you get the quadruplets.
BUT remember that this was a short-cut which I gave you. You should know how this was derived. Currently I don't have enough time to explain it. Read:http://www.geocities.com/titus_piezas/RamCube.htm for a explanation.
Also, you should also Brute Force it, and check if it is feasible (It will be ;) )
Probably your teacher wants you to use Brute Force.

siddhant3s 1,429 Practically a Posting Shark

What a crap this code is...........?
And you say you just want it to compile.!! Read your text book first.

siddhant3s 1,429 Practically a Posting Shark

Well well, I guess the "My fav IDE/Compiler war" stared again!!
>Code::Blocks is too heavy I meant that it has too much options I don't use
I have a simple reply.....Don't use the "much options".
Code::Block appears great to me. On both Linux and Windows.
I have heard very (surprisingly) good response about MS VS 2008 Express.
Or, you can always give a :P to IDE's and use command-line compiling which works best.

siddhant3s 1,429 Practically a Posting Shark

Please search the thread's before:
http://www.daniweb.com/forums/post814395.html <<here you may find something useful.

siddhant3s 1,429 Practically a Posting Shark

>I do not understand some of the things you guys are talking about
I was talking about stack, which is in a way, exactly what you have done.
Stacks can be thought of as an array in which the last item which goes in will be the last item which comes out. It is more or less the same thing which you have done.

Mind you, I have not read your code.

Regarding your error handling mechanism you have various method:
1.The very best is to use exeptions, They are error handling mechanism of C++. Research about them. Its good to start using them.
2. cout a error and quite the program by using exit(1)[defined under <cstdlib>]. This will cause termination of the program.

I prefer you opt choice 1. and learn about exceptions. After you know about exceptions, you can read the following article about Detecting and responding to division by zero http://www.deitel.com/articles/cplusplus_tutorials/20060325/

siddhant3s 1,429 Practically a Posting Shark

Do something with arrays.
Create a array and input the 5 location in it. Then run a loop and check for the given value.
I mean, do SOMETHING man.
We don't give free candies!

siddhant3s 1,429 Practically a Posting Shark

Look at your for loop. Mathematics says that you just need to check it till i<=sqrt(n) i.e. the square root of n. That is, it your input number is 33, then just check that if should not be divisible by any number from 2 to sqrt(33) which is 5. So you see, that is just 3 iteration rather than 31 iterations what you were doing.
Learn about break; statement.
Don't announce just yet that the number is prime repeatedly. Use concept of flags. That is to say, define a variable flag and initialize it to 1. Now run your loop and test the condition (n%i==0) . If you find this condition to be true, just say flag=0; and issue a break; Now, when you are out of loop, flag will have value 1 if the number is prime, else it will be set to zero.
This method thus will be more efficient.

siddhant3s 1,429 Practically a Posting Shark

In case you need more explanation/reference/solutions regarding your problem, the famous C++ FAQ by Marshal Cline have a section covered on it.
I suggest you should definitely read it :http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12

siddhant3s 1,429 Practically a Posting Shark

Ok, I have seen your project and have come to the following conclusion:
You are using template function right? Which is making trouble here. How? Well here is a brief explanation:
The compiler does not generate the template code just as soon as it sees the definition. It will only generate the code when it sees a function call. Now what happens is, when your Printer.cpp get compile, no code regarding the templated function gets generated. So now, when you link your executable(after compiling all the source file to object file), the linker complaints that it do not have the definition of the function. And hence you get errors.
What is the solution?
The simplest solution in your case is to define all the templated function in the header file(Printer.h) itself.
Other solution exists, but they are complex and non-portable.

So, just define all your templated function in the header file so that the calling code and the definition lies in the same object file.

Thats all !!:yawn:

siddhant3s 1,429 Practically a Posting Shark

But you must have added cout anyways.
without cout, you cannot output it to console.
Anyways, happy that it is working for you.

siddhant3s 1,429 Practically a Posting Shark

>What is wrong with my use of MACRO?
Read this(Marshal Cline FAQs) http://www.parashift.com/c++-faq-lite/inline-functions.html#faq-9.5 about why macros are evil.
>I changed the "System" function. When I look at the name, I guess it is a matter a >compatibility or rather protability to other systems right?
Yes.
>Is there any way to use a function coming from another class >(variable_toString) without instantiating this class? I feel bad about creating an >instance of Printer in RandomGenerator...
Yes, Declare the function as static to the class. And then you can call it as Printer::variable_toString(Variable _variable) Now regarding your project, I would suggest you should zip it up and upload it here as I cannot likely say from where the problem is coming without seeing the code.

siddhant3s 1,429 Practically a Posting Shark

on jeevsmyd
See jeevs, I didn't wanted to touch you on that. Just mark my words, you would definitely succeed as you have the hunger to do.
And for sure, I would help you. The book you are reading may be one of the best which is available nearby but it really crap. I would suggest a free online book, it is called Thinking In C++ by Bruce Eckel's http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html#DownloadingTheBook You should start reading the book from start. It will be very beneficial to you. Next is that, your curriculum, would require you to write the old c++ in your exams, do it. But always remember the Standard C++.
So, I hope you are getting me, and do start reading the book.

siddhant3s 1,429 Practically a Posting Shark

Yes, of course.
But I cannot help it. My job was to modify his code, not write it.
This catch is even in his original code so I cannot help. If he shows some efforts regarding multi-digits evaluation, I will surely help.
Using stack was a good idea to target such issue but then, he want it do recursively.:icon_smile: