siddhant3s 1,429 Practically a Posting Shark

Bots often require high level language interface. If you have choices about programming language, use python; It will keep you away from tangling the syntax and concentration on the core of logic.

siddhant3s 1,429 Practically a Posting Shark

Simple: Take the input as a string. Then parse it to perform the desire operation.

siddhant3s 1,429 Practically a Posting Shark

Use the functions qualified name i.e. class_name::function_name(parameteres)

In your case, call it as: Point::DisplayName() This will make clear that DisplayName is either a static function from a class Point or it is a Simple function in the Point namespace.
If the code reader knows that Point is a class, he will surly understand that DisplayName is a static member.

siddhant3s 1,429 Practically a Posting Shark

You are defining the class twice. Surely it cannot link.


>>(Why the daniweb editor is not rich text?! I remember it was before)
So as to make it tough for you to use color on every alternate word. Phew man! reading you post needed courage.

siddhant3s 1,429 Practically a Posting Shark

If vectors are in your toolbox, you better use them:

int main(){
std::vector<std::string> vec1;
vec1.push_back("Hello");
vec1.push_back("How");
vec1.push_back("are");
vec1.push_back("you");
f1(vec1);//see definition below
}
void f1(const std::vector<std::string> & vec) //a function taking vector as argument
{
    for(int i=0; i!=vec.size();++i)
        { std::cout<<vec[i];  }//print the vector
}
siddhant3s 1,429 Practically a Posting Shark

I agree with Ancient Dragon.
Check the sizes of the arrays (if they aren't equal then you can bail right there)
If they are equal then sort them.
Then a basic loop:

bool is_equal=false;
for( int i=0; i<array_size; ++i )
{
is_equal=(a[i]==b[i]);
}

Your code will check if the corresponding elements of the two arrays are same or not. This is not what OP wants. OP doesn't care about the order of the elements in array.

To OP: as the data is small, use ArkM's solution-
For each i from 0 to n-1
{
for each j from 0 to n-1
{
check if a==b[j]
}
}
where n is the size of array a and b.

siddhant3s 1,429 Practically a Posting Shark

>>I just mean, in my case, v1, v2 should be initialized in the constructor function or
>>no
Do don't need to construct vectors explicitly. When you define a vector a type T, the vector's constructor automatically calls the constructor of T for all the elements.
This poses a restriction that T should have at least one constructor.

siddhant3s 1,429 Practically a Posting Shark

>>Or Have you tried?
He don't have to as your advices are very incorrect.

To the OP:
There is NO WAY you could get the size of an passed array inside a function. Why? Because arrays cannot be passed. The compiler converts the definitions like this:

void f1(int a[])
{
...
}

to this:

void f1(int* a)
{
...
}

So, when you pass an array, you are actually passing a simple pointer. And hence, there is NO WAY you could tell if a pointer is pointing to an array or not.

The only suggestion is to make your function definition like this:

void f1(int a[], int row, int col)
{
...
}

and let the function user pass the rows and columns as the parameter.

siddhant3s 1,429 Practically a Posting Shark

Line 11: Do you expect, for a fraction, denominator to be zero?

As per for the simplify(), It is simple:
1.Write a function that calculates the gcd of two number
2. Divide numerator and denominator by that GCD

For finding GCD use the Euclidean Algorithm

siddhant3s 1,429 Practically a Posting Shark

>>Can anyone confirm that it is working correctly?
What do you mean by working correctly?
I don't think there is any problem with the code now.
If you are pointing that your debugger is not showing protectedsixspeed for listname[0], if should not. As listname[o] contains the pointer to a Vehical Object. You know it is actually a SportsCar. To get a SportsCar object pointed by listname[0], consider doing a static_cast: SportsCar sp=*(static_cast<SportsCar*>(listname[0]));

siddhant3s 1,429 Practically a Posting Shark

1.Seed using srand()
Visit http://www.daniweb.com/forums/thread1769.html
2.Computer can only generate pseudo random number. Understand the difference. Please visit http://www.eternallyconfuzzled.com/arts/jsw_art_rand.aspx

siddhant3s 1,429 Practically a Posting Shark

Yes. Input the date as a std::string .
Then use the substr function to slice the string to get individual strings for Date, Month and year.
Lastly you would want to convert the std::string to integer, Use stringstream to convert the string into the integer(refer http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2)

siddhant3s 1,429 Practically a Posting Shark

>>And when I do Visual Studio 2005 reports:
Thats because you are still appending a SportsCar in the list while it requires a Pointer to SportsCar.
So change listname.push_back( *ptrToSportsCar ); to listname.push_back( ptrToSportsCar );

siddhant3s 1,429 Practically a Posting Shark

You are almost there:
start of with this:

#include <iostream>
#include <string>
using std::cout;    using std::cin;
using std::string;

int main()
{
    // write the code to Declare PointsScored [10] of reals
    // Reals are represented as 'double' in c++

    // write the code to Declare sum, average as real
    //Write a code to Declare B as int
    //Set sum = 0
    // Construct a for loop: For B = 0 1 to 11 
    //Code for displaying output “Enter players points scored”, B +1
            //output is displayed  cout
    //code to accept input in PointsScored
          //input is done by cin
    // Set Sum = Sum + Points Scored (B)
    // terminate For-block
    //Set Average = Sum/10
//No need of for here just display the Avarage

}
siddhant3s 1,429 Practically a Posting Shark

>>why are using a template for this application?
Perhaps to save the run-time

siddhant3s 1,429 Practically a Posting Shark

Template parameter are instantiated pre-runtime. So when your program is running, you cannot change them.

If you are making a Matrix class, why don't you consider vector or vectors as the backend data structure. Then make your own resize function. Alternatively, you can create a copy constructor. Then, when you wish to resize the object, create a bigger new object, copy to it the content of original object and destroy the former.

siddhant3s 1,429 Practically a Posting Shark

>>.i will user ur code as a reference code and will write my own code after
>>undertanding it
You know, first I thought I should believe your on this. But then my 6th sense told me not to. I am sorry.

tux4life commented: LOL, He'll use it as a "reference", where he copies all the code from I believe :P +4
siddhant3s 1,429 Practically a Posting Shark

Yes, Tux, That was a Typo.

I don't think the OP is clear what he wants.

siddhant3s 1,429 Practically a Posting Shark

I don't think you would like rounding the number the use inputs. You will loose on the accuracy of your result.
What you want may be is that when your display the output, the precision should be only 2 digits. Do something like this:

#include<iostream>
#include<iomanip>
int main()
{
double d=3.1457545;
std::cin>>d;
//do your calculation with d
//with great acuraccy !!
const std::streamsize orig=std::cout.precision();//save the orignal precision
std::cout<<std::setprecision(3)<<d<<std::endl;//set precision to 3 significant digits
std::cout<<std::setprecision(orignal);//regain orignal precision
}
siddhant3s 1,429 Practically a Posting Shark

The type of p is obviously a pointer-to-int.
While the type of p is pointer-to-pointer-to-int.
The type of *p and p[j] is an int.

vmanes>>So, each p is the name of a single 1D array of int.

Actually, because of the infamous analogy of pointer and arrays, few often ignore that they are actually not the same thing. Nevertheless, it doesn't matter here. But strictly speaking, the OP explicitly declared p as pointer-to-pointer-to-int hence p is not an array but a pointer-to-int
Although, I appreciate you being more simple.

siddhant3s 1,429 Practically a Posting Shark

Isn't this the assignment similar to this one? http://www.daniweb.com/forums/post864074.html#post864074

Read my post: http://www.daniweb.com/forums/post864074.html#9 I have posted the algorithm. Try to implement it and let us know

siddhant3s 1,429 Practically a Posting Shark

I say: your eyes must be burning.
I also reread it with eyes of a Noob. Here is what I did next:
I went on searching where these Announcements or Sticky threads are there.
=>Either I was able to find out:
I apologized on this thread. Or perhaps said "I am new, thats why I didn't knew this"
=>Or I was not able to find out those announcement:
I requested on the thread for the links of the announcements

Then I realized, thats its not nice to throw instruction in a new place. So I apologize and seek help again.

siddhant3s 1,429 Practically a Posting Shark

I would point out to them, that giving homework is against daniweb rules and ask them to show some effort. If they respond with a post that shows some effort (code), I'll be still happy to help them out.

You must have missed the 'OR' part of the post #3.

>>Yes it does, as all the better things in live do. Like coffee, alcohol and greesy
>>burgers
Ummm....... can you make coffee an exception. I love it like anything. It doesn't kill actually.(even if it does, I don't mind)

siddhant3s 1,429 Practically a Posting Shark

Just helping you out by compiling all the fact that has already been posted.
1. Find the squares of lengths a,b,c by using distance formula : [tex]d^2=(x_{1}-x_{2})^2+(y_{1}-y_{2})^2[/tex]
2. Check if the greatest of the three square is equal to the sum of the square of other two sides.
[tex]a^2=b^2+c^2 \forall a> b\geq c[/tex]

Now code the above algorithm and let us know if your find any problem.

siddhant3s 1,429 Practically a Posting Shark

>>Then why did he package the computer with the program calc.exe
Humans packed calc.exe not god.
LoL, my mobile phone has a C++ compiler running on DosBox.

siddhant3s 1,429 Practically a Posting Shark

>> Take it easy dude... have some tea and a smoke - niek_e
>>You've taken being a jerk a little too far in this post. - WaltP
I don't understand you guys. You may be generous to the 'lazy' visitors of this website, I am not.
I can stay happy enough on the fact that I said nothing wrong.
I don't smoke, it kills.

siddhant3s 1,429 Practically a Posting Shark

Listen Kid, Recursion = avoiding loop.
I don't know why your instructor told you to use loop in a recursive function.
the while loop your using is doing all the trouble. It is making your function a junk.
Your code (for Search) is absolutely fine if you remove the while loop:

//corrected version. Loop removed
NodePtr Search( NodePtr head, key)
{
if(head==NULL)
{
return 0 ; 
}
if (head->info==key)
return head;
else
Search(head->link, key);
}

Now do the needful for FindMax yourself.

siddhant3s 1,429 Practically a Posting Shark

Short answer: You cannot.
Long answer:
You cannot stop anyone from copying your program (until unless your seize its production). You can only make it harder for the user to reverse engineer your application.
Now as per the last part, your can have various check about the authenticity of the user. The implementation of this depends on how more cautious you are regarding the software and how much time can you spend in protecting it.
Is it worth it?

You may wish to google around finding various programs that will protect your software. There may be guides available too.
If there had been a system by which you can restrict illegal copies of your software, big companies like MS, Adobe, etc would have been implementing it on their products. But as I find, their products are also reverse engineered a lot.

siddhant3s 1,429 Practically a Posting Shark

Yeah, Yeah thats true.
because arr[0] is read as *(arr+0) which will change the value of the memory pointed by arr+0 directly.

Good.

NathanOliver commented: you have cleared up arrays for me thanks +1
siddhant3s 1,429 Practically a Posting Shark

The God has sent me to say "C++ compiler is not a pocket calculator."

tux4life commented: ROFL :P +4
siddhant3s 1,429 Practically a Posting Shark

>>I need the answer as soon as you can
We need your to leave this website as soon as you can.
Or:
Read the forum guidelines ( I usually posts the link along but for you, no mercy)
Read the sticky thread by Narue: Read before posting
Read the Forum announcement by the Administrator.

We are not your slave. Neither are you our employer. We are sitting here to help. Not to accept orders from some Tom Dick and Harry.

WaltP commented: You've taken being a jerk a little too far in this post. +17
Nick Evan commented: Take it easy dude... have some tea and a smoke ;) -3
Salem commented: Works for me :) +30
siddhant3s 1,429 Practically a Posting Shark

follow djextream5.
Visit http://www.nychold.com/em-arith.html for more algorithms on basic mathematical operations

siddhant3s 1,429 Practically a Posting Shark

You have not written a recursive function.
Loosely speaking, Recursive functions should imply removal of ugly loops. I shall rather guide you in your first function.
You are using while to check an condition rather than if. This is unlikely (and maybe wrong too) by your instructor.
Here is a quick TODO for the first function:

START
* Check if Head is NULL; if it is return some value(preferably  zero) indicating failure of search
* Check if Head-info==key; if it is, return head
if it is not, call search(head->link,key)
END

All the checks are to be made be if's and not while. The idea is not to use loops.

blackhawk9876 commented: thx +2
siddhant3s 1,429 Practically a Posting Shark

>>, but the array (the memory location of the first element of the array) is by
>> reference since it is not copied.
No. The memory location of the first element is passed by value. This is what the name of the array points to. Look at the following snippet

void foo(int arr[])
{
    arr=0;//nulling the pointer passed to the first element
}
int main()
{

    int p[]={3,5,4};
    std::cout<<"The arr points to --->  "<<p<<std::endl;
    foo(p);//actually the array is not passed. But the pointer
// to the first element is passed by value 
    std::cout<<"Now, the arr points to --->  "<<p;//the output is same as above
//That proves that the memory address of the first element is passed by value. If it was not, zeroing it in foo would have been reflected in main
}
siddhant3s 1,429 Practically a Posting Shark

>>That's not possible -- arrays can only be passed by reference. Passing by value
>>implies creating another copy of the array and passing the copy. The language
>>does not support passing arrays by value.

Just being too strict in saying, the passing of arrays is converted into passing to the equivalent pointer by the compiler.

void f1(char a[])
{}

is automagically converted to

void f1(char* a)
{}

And the above pointer is passed by value. In effect it appears that the array has been passed 'by reference' but in reality, arrays are actually never passed to a functions.

siddhant3s 1,429 Practically a Posting Shark

Second statement is wrong. You must have not seen it in many codes.
There is no function called fopen for the istream class.
This line should have been:
ipfile.open(ipfname);

siddhant3s 1,429 Practically a Posting Shark

Line 42, defination of function is not proper. The second formal parameter is missing.

Returning of array doesn't makes sense. As arrays passed are mutable in nature. Any changes applied to arrays inside a function is reflected back to the caller.
So sales_total doesn't return anything.
sales_input should also doesn't return anything, so make it void returning.

siddhant3s 1,429 Practically a Posting Shark

Learn C,
Learn C++
Do the conversion manually.

Or try this link to c++ conversion

siddhant3s 1,429 Practically a Posting Shark

>>Using Windows API's how can i
>>copy to another file and Get different properties of a file (size, type, date
>>created and more).

Try reading :http://www.dreamincode.net/forums/showtopic93676.htm
Try googling before starting new thread.
Don't over post on web, it will blast eventually.


>>plz
Thats good.
>>someone reply me quickly
Thats not very good

siddhant3s 1,429 Practically a Posting Shark

I am not sure if I understood the your question.
Unordered and random codes are nightmare for the new programmer.It is really unfortunate situation and your are suffering from this.
Now I would advice you to either find that bloody programmer who wrote all that. Or try to scratch your head figuring it out the code. I know it is a trivial advice but in this case I cannot be specific.

Try to put some debugger's output code like:
std::cout<<" The control has reached line 54";
to perhaps fetch a better picture out.

siddhant3s 1,429 Practically a Posting Shark

>>Good point but is the C++ way of handling exceptions the preferred way to
>>handle this ?
Yes. It much much better. But then, you can sometime run into situation of using the C-style if checks.
But I generally don't like if-checks. They're ugly. And very ugly.

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

nothrow is a (ad-hoc) way to control program flow.
As you may be clear, no throw does not throw exceptions.
So you get the old C type check rather than the great exception handling mechanism.

siddhant3s 1,429 Practically a Posting Shark

To check if assignment failed, catch the bad_alloc execption.

siddhant3s 1,429 Practically a Posting Shark

You need to know a virtual function : http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.1
Thats perhaps your best shot.

siddhant3s 1,429 Practically a Posting Shark

>>That is incorrect. The pointer is assigned whatever random value is at that
>>memory location. For example char *ptr; the address of ptr is whatever is at that
>>memory location on the stack (assuming its not a global variable). It is never
>>auto set to NULL by the compiler in either C or C++ languages.

I was just about to point out that to the OP and tux.
This might now confuse OP as Tux said "that explicitly initializing a pointer to 0 is a overhead because it is done by default" which is actually wrong.
The overhead is because you can construct the pointer pointing to a new location by directly by initializing it to the result of a new operation:

//version 1// BAD
int* P;
P=new int;
/
//version 2// Good
int* P= new int;
//This is good as you are saving the overhead of assignment.
//As there is no need of assignment, cause you have initialized the P already

Not to mention, assignment and initialization are two different things

tux4life commented: Everywhere siddhant is looking for confusion :) +3
siddhant3s 1,429 Practically a Posting Shark

>>It's perfectly acceptable to compare floats. You just have to understand the
>>difficulties and know how to deal with them.
Good. I mean you are right.


>>Now if you input 5.0 and you get 5.00000001 your comparison works fine.
A you see, if now I put inputValue =5.0 and targetVal=5.0, your posted snippet tells me that they are not equal.
What say?
Actually. You are right in saying that we can trade off by getting the result in a desired range. This is the next best thing one can get.

siddhant3s 1,429 Practically a Posting Shark

>>i just had a thought and i though that i would at least give it one more shoot. if it
>>is truly a no no to test for floats instead of an integer input then so be it. with that
>>out of the way here it is tell me what you think
I think the code you just posted is junk. Seriously, it may work ( I have not tested) but it is Non-standard [ string::size returns size_t ], cruel [you are unnecessarily using cstrings ], untidy and too complicated for a simple process like this.
You may ignore my comments and continue to work as you wish, but this will surly lead you nowhere.

ArkM has posted a decent solution (post#3). Try to learn from it.

As side notes:
1. Line 10 is ended with two semicolons . Syntactically right but ........
2. The standard library for <stdlib.h> is actually <cstdlib>
3. Rather than using 46 use '.' which is more readable.

siddhant3s 1,429 Practically a Posting Shark

>>It's a rather strange thought that the C++ language defines built-in bool
>>operator==(double,double) which inevitably leads to undefined behaviour.
As a side note, I was just wondering if I could somehow overload operator--(double,double) so that it could just throw me an exception-" Error/Warning, you are using floating point comparisoin" LO L :D

siddhant3s 1,429 Practically a Posting Shark

Undefined Behaviour as per Scot Mayers;

For a variety of reasons, the behavior of some constructs in C++ is literally not defined: you can't reliably predict what will happen at runtime. To emphasize that the results of undefined behavior are not predictable and may be very unpleasant, experienced C++ programmers often say that programs with undefined behavior can erase your hard drive. It's true: a program with undefined behavior could erase your hard drive. But it's not probable. More likely is that the program will behave erratically, sometimes running normally, other times crashing, still other times producing incorrect results.

This tells me that the snippet posted on post #4 is in state of undefined behavior by using float comparison.


>>How so?
Good point. You may be right. As I may be over cautioning the programmer about float comparison. But consider this:
Lets say the user inputs 5.00000001. Hence input=5.00000001 Then test=5.0 Now it is perfectly undefined that test==float