siddhant3s 1,429 Practically a Posting Shark

>Can any one help me to improve it (by adding graphics) and making code short.
No we cannot.
We don't give away codes.
What you can do is, ask more specific questions.

siddhant3s 1,429 Practically a Posting Shark

Array of Pointers can be used to do fast sorting.
For eg. If you want to sort a unsorted array of integer. You generally can use all sorts of algorithms on the int array. But it would be less efficient as the runtime head for moving the values of int array will be more.
Now other alternative is to sort by using array of pointers. Say, now, you create array to int pointers (int*) and let each one of them point to the corresponding elements of the integer array. Now when you need to sort them, just re-locate the pointers in correct order, which would be faster.
Read: http://www.gidforums.com/t-10801.html

siddhant3s 1,429 Practically a Posting Shark

Yeah, why not: Yes, vectors are used in C++
They are part of the Standard Template Library.
Now go and Use google.com to find out more.
And further: Search for your answers before asking : Read this sticky thread :http://www.daniweb.com/forums/thread78223.html

siddhant3s 1,429 Practically a Posting Shark

Takafoo, groom your basics. You don't even know how to use the modulo operator %.
Now lets work upon how to guess if number is prime or not.
What we gonna do is take the number and find its remainder when divided by numbers from 2 till the number-1.
For say, if the input number is 33 we gonna check if the number is divisible by
2? 3? 4? 5?........... 31? 32?
If all the answers are NO, then the number is prime. If even one of the answer is YES, the number is not a prime.
So, how do we do that?
We construct a for-loop from 2 to the number-1:

for(int i=2; i < n ; i++)
{
//body of loop
}

Now, inside the body, we will check if the number, n is divisible by each i by using the modulo operator:

for(int i=2; i < n ; i++)
{
if (n%i==0)
return 0;//indicating it is not a prime
}
return 1;//after the loop pass all the test, we are confirmed that
              //the number is prime, so return 1 for success

so the whole thing will look something like this :

int isPrime(int n)
{
  for(int i=2; i < n ; i++)
     {
       if (n%i==0)
            return 0;//indicating it is not a prime
     }
   return 1;//after the loop pass all the test, we are confirmed that
              //the number is prime, so return 1 for success
}

Note that …

siddhant3s 1,429 Practically a Posting Shark

So, you want to go back to some line without a loop?
It is not suggested. Beware, do not do this practice, but for the sake of your curiosity, there exists a goto statement. Please do not use this in your everyday life.
There is a good example on implementing goto instead of loops here:http://www.java2s.com/Tutorial/Cpp/0060__Operators-statements/gotoloopexample.htm and also here:http://www.cplusplus.com/doc/tutorial/control.html but I don't recommend it.

PS: The title of your thread suggest that the problem is something to do with Temperature Conversions though it is not. Please use more specific names such as "Control Flow without loops" or "Alternative of loops"

siddhant3s 1,429 Practically a Posting Shark

>And I'd like to point out that hajiakundov and siddhant3s have both not helped >confused! to learn. Giving answers only gets the assignment done, but does >not promote learning how to do the assignment.

I agree. Neither do I like it. Read My post about it.
http://www.daniweb.com/forums/post813528.html#post813528
These are few quotes from in there:

Please note:
I know no one gets paid to help here. I even know that you can debug the flawed code very quickly and repost it. But the real pain lies in explaining the things to the new-bie so that he can get meaning to your code.

I was just trying to point to Haji Akhundov's post, that the things could be done in much simple manner with STL in hand. I was trying to show, the number of lines which gets reduced while using STL

siddhant3s 1,429 Practically a Posting Shark

I am not showing-off, But just want to tell that how can STL come to your rescue.
The program submitted by Haji Akhundov, Can be shorten to few lines only.

#include<iostream>
#include<string>
#include<algorithm>
int main()
{
    std::string orig, rev;
    std::cin>>orig;
    rev=orig;
    std::reverse(rev.begin(), rev.end() );
    if (rev==orig)
        std::cout<<"Yes";
    else
        std::cout<<"No";
}
siddhant3s 1,429 Practically a Posting Shark

Don't use such a adhoc method.
Use the STL method like this:

#include<sstream>
 inline std::string stringify(double x)
 {
   std::ostringstream o;
   if (!(o << x))
     cou<<"Bad Conversion";
   return o.str();
 } 

//Heres is how to use it:
string s1("123456");
int number=stringify(s1);
cout<<number;

For more, refer :http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2

siddhant3s 1,429 Practically a Posting Shark

I don't think I am able to understand you.
You can always forward declare furlong class (as you did it to Kilometer), just before the declaration of Kilometer class.

siddhant3s 1,429 Practically a Posting Shark

Now what should I say to charleen.
Should I get angry or should I blow my head.
charleen, NEVER USE VOID MAIN. Okay? and say it 100 times," I WILL NEVER USE VOID MAIN".
Go and search the internet about this:
This is from Bajarne Stroustup Official Homepage :http://www.research.att.com/~bs/bs_faq2.html#void-main
And this is a small article about why not to use void main:http://cppdb.blogspot.com/2009/02/should-i-use-void-main-or-int-main-or.html
And you know Salem? He is a valuable poster on this forum, look at his avatar:[img]http://www.daniweb.com/forums/customavatars/avatar57744_3.gif[/img]

>and if you are using int main() please return some value like "return 0;"
As I told you, there is no need to return 0; this is what Bajarne Stroustrup write on his page : These are the lines quoted from his page :

In C++, main() need not contain an explicit return statement. In that case, the value returned is 0, meaning successful execution.

Such a post shows your unexperienced and non-standard behavior towards C++

siddhant3s 1,429 Practically a Posting Shark

You should perhaps read those two value in two strings variables. And then write your own add function which would find there sum.

siddhant3s 1,429 Practically a Posting Shark

>Don't forget the return value..
0(zero) is returned by default. You don't need to return a value.
As mentioned by Bajarne Stroustrup, this is a perfectly valid shortest C++ program:

int main() {}
siddhant3s 1,429 Practically a Posting Shark
int age;

cout << "Enter your age" << end1;
cin >> age;

Ha Ha Ha Look at the second line end1;
it should be endl not end1

siddhant3s 1,429 Practically a Posting Shark

Look at line 34 furlong.h (class Kilometer& kilo) You are using Kilometer here. Right? Now just tell me, have you told your compiler before that something called Kilometer exists? No.
So, what to do?
Simple, you need to tell your class furlong that there exists something called Kilometer by declaring it once before the declaration of class furlong. This is called forward declaration.
You just need to put a

class Kilometer;

just before the declaration of furlong class(i.e. line 12 of furlong.h). Something like this:

class Kilometer;
class Furlong{
private:
int furlongs;class Kilometer;
..
..
..
..

For more info about forward declarations:http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.11

CPPRULZ commented: AWESOME +1
siddhant3s 1,429 Practically a Posting Shark

I am still confused why do you want to do this. I just can wonder that probably your implementation lacks a C++ compiler and hence you want to convert the C++ code to C.
Well, the very first compiler(cfront), made by Bajane Stroustrup actually did this thing only. It converted C++ code to C code. I don't think cfront is being maintained now. But I heard that certain compiler can actually do this. This doesn't mean that the code will be readable after conversion. This just means that it will compile with a C compiler.
If you want to convert this code to C for educational purpose, nothing beats a programmer who knows a little C and C++ both. So its best to actually compile this code in C compiler and check where at what point the compiler complaints. And then do a little bit of googling and find out what is the alternative to those commands in C.
Wish you luck.
PS: If you really thought that you will yell out HELP and some wizard will convert your C++ code to C, you probably were over dreaming.

siddhant3s 1,429 Practically a Posting Shark

Daily in the morning, chant out this line " Its better to detect error at compile time than at link time or run time."
And this is the whole key to const-correctness, this is what you call it in technical terms.
Read:http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.1
const-correctness basically ensure type safety. It should be practiced by every efficient programmer. It can sometime saves you hour of work!!

siddhant3s 1,429 Practically a Posting Shark

So, you are a new bie in C++. You are just doing console programming right now. Right? I mean all sought of Black& white interface. You want create a window-like GUI.
Hmm, Well, there are lot of GUI library out there. You can try anyone you want. But the choice matters.
I personally use GTK+ Library which is (i feel the best) free, cross-platformed, LGPLed and comes with a huge support. Basically it is meant for C users. But there exists a (famous) C++ port to it which implements GTK+ as a OOP tool. It is called gtkmm (GTK minus minus). Go grab it.
BTW, what is your compiler, Operating system?

Also, wxWidget is a good library indeed. You can check that as well.

siddhant3s 1,429 Practically a Posting Shark

Umm,
Well I just know don't why would I use the scanf() to read out a character when I have the pretty getchar() in hand.

char a
a=getchar();

While another thing to keep in mind (this is for you, the thread starter) is that all these functions are related to C rather than C++. So the C forum would have been a better place. But never mind. You are free to exploit the inter-compatibility of C and C++

siddhant3s 1,429 Practically a Posting Shark

>I don't understand. How do I set data to tmp?
You would, just look at the piece below:

class Foo
{
int *A;
int B
public
Foo():{A=new int; B=0;}
Foo(const Foo& other)
{
int *tmp= new int;
*tmp=*other.A;
//////////////
A=tmp;//You did not do this step
}
};
siddhant3s 1,429 Practically a Posting Shark

First let us work about flushing the input stream. Well, when you cin>>choice The user press some character(like 'a' or 'e' or 'm') and the enter key(which means '\n'). So what happens is, that the character gets stored in the variable called choice but the '\n' still remains in the stream. So whenever the next input is required, that '\n' gets inputed there.
You can think like this: The input from keyboard is taken from the user and stored in a buffer( which can be thought of as a temporary storage ) . That means whatever the user types get stored first in buffer. Then from the buffer, it is passed on to your variable considering the capacity of the variable. i.e If you have cin a char variable c_var , and the buffer contains "Hello" then only H will be copied to c_var. And the rest of the input will still remain in buffer. If now, you issue another input statement(like getline() or whatever) all the left over characters("ello") gets passed to it.
Now, what is happening in your case is, that when the user enters a character and presses enter, the character gets stored in the choice, but the next character (which is '\n') get passed over. This is automatically get poured into the next input statement encountered .( which in your case is cin.getline(your_string, 256); )
Hence you never get a chance to Enter the string the second time.
Now what cin.ignore does …

siddhant3s 1,429 Practically a Posting Shark

>I don't think I can use the default copy-ctor
Yes you are right. That's why I ask to check if you were stupid enough to use them. So it turns out that you are smart enough.

>I don't have it with me but it's something similar to this
This looks good, but the only problem is that tmp is getting wasted. I mean you need to set some of your data member(which is Pointer to ItemType) to tmp.

siddhant3s 1,429 Practically a Posting Shark

Have you defined your own copy-constructor, or using the default one?

(que1.IsEmpty() != true && que2.IsEmpty() != true ) is depreciated. Use

( !que1.IsEmpty() && !que2.IsEmpty() )


vmanes is rather right. you must construct a else case also.

Another point to note is, you should avoid recursions as far as possible. This problem could have been done without recursion .

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

I've read the thread on homework help and am not here asking for someone to do my program.
I guess you didn't read about posting your code in the code tags:http://www.daniweb.com/forums/misc-explaincode.html

I decided to use a linked list with this type declaration
This is a Node of the linked list, not the linked list itself.
(I dont recomend the typedef you chose. monomial would have been a better option)
So you have a made a monomial Node. Good.
Now start by designing a Class which would actually make all those things to work.
Since it is a linked list, it wouldnt be as easy.
So, start writing the Class, write ways to input and output a polynomial etc.

siddhant3s 1,429 Practically a Posting Shark

Out of scope means when the object is no longer usable.
Consider,

void main()
{
Sample s1;
}//this is where s1 get out of scope.

The string str will be successfully destroyed if you are catching the exceptions. If you are not,( like what your friend was doing) will cause immediate termination of the program and alas the memory will not be freed. This is a horrible situation! I know its painful but even the compiler is help less here.

siddhant3s 1,429 Practically a Posting Shark

>destructor will probably not be called
Yes, It will not be called
>what happens to the memory allocated for str?
It will be released by the compiler as soon the object of Sample gets out of scope
>Would this result in a memory leak?
No.

Remark: The compiler assures that every thing you create statically(and whose constructor was successfully called) will get destroyed once the object become out of scope.
To be precise, compiler assures that he will call the destructor every object you create statically(and whose constructor was successfully called) once the object become out of scope.
And thus you should make a note that, the constructor of str will be successfully called( as soon as the constructor of Sample was called) hence it will be destructed by the compiler. But the constructor of Sample was not fully called, so it won't be destructed by the compiler.

siddhant3s 1,429 Practically a Posting Shark

C++ FAQs by Marshal Cline is a good, free resource.
If you are a absolute biginer you must read "The Correct C++ Tutorial" http://home.no.net/dubjai/win32cpptut/html/
Thinking in C++ by Bruce Eckel is a nice book(free online)
You may visit the Sticky forum about C++ books http://www.daniweb.com/forums/thread70096.html

vmanes commented: Good advise for the student +7
siddhant3s 1,429 Practically a Posting Shark

Well, your do-while loop is absolutely fine.
The problem you are suffering is that:
1. You are not initializing the array new_string when you are using it. Add a for(int i=0;i<256;(new_string[i]=0),i++); before the int x = strlen(your_string)-1; in definition of ReverseString().
2. You are not flushing the input stream. Add a cin.ignore(1000,'\n'); after cin>>choice Thats all,
Try not to use global variables. Use the code-tags to post the code.

Mossiah commented: Nice work. thanks very much for your help +1
siddhant3s 1,429 Practically a Posting Shark

This is called, to kill a Mosquito with a Bazooka.
Why did you went into the char thing. Look at ArkM's code, its neat, decent and much faster. And does almost the same work which you were trying to accomplish.
BTW, char chr_digits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '\0'}; is same as char chr_digits[] ="0123456789";

siddhant3s 1,429 Practically a Posting Shark

>Can somebody simply the function for me plz.
You mean explaining it?

siddhant3s 1,429 Practically a Posting Shark

>But where is i,the control variable is c
Yeah, never mind. I overlooked it.
>else you 'll get only the last occurrence of that number in the 'loc'
Yes, he is right. You should perhaps issue a break statement after loc=c;

siddhant3s 1,429 Practically a Posting Shark

Please be specific. No one has time to look at your 1MB code and point out the error.

Salem commented: Quite so! +29
siddhant3s 1,429 Practically a Posting Shark

It is not completely his fault though, I know the schools in India, they teach "Ancient" C++. But I completly agree with Narue's first comment. You have a internet connection. So go and get "Decent Book" (I told you about Thinking in C++ by Bruce Eckels).
Be with the Standard C++ and just pour all that crap on your answer sheet in the examination , what your teacher expects from you.

siddhant3s 1,429 Practically a Posting Shark
for(c=0;c<5;c++)
{
if(d==no[c])
loc=loc+1;<<< change it to loc=i;
}
printf("\n The location is: %d", loc);
getch();
}

Read my comment on the above code;
I dont think it is a C++ program. Looks more or less look like a C program.
Very bad
.
Please use code tags to post the code.
And don't start two thread for the same thing

siddhant3s 1,429 Practically a Posting Shark

>You don't have to go upto sqrt(num). The loop may be like this.
Wrong!!
consider 25: its square-root is 5, According to you, we should check till 4.
25 is not divisible by 2
25 is not divisible by 3
25 is not divisible by 4
So, is it a prime number?

Hence the correct thing is to check till the square-root including the square-root itself like I mentioned in my earlier post.

siddhant3s 1,429 Practically a Posting Shark

Please mark the thread as "Solved"

siddhant3s 1,429 Practically a Posting Shark

>warning : making that enum will break your code.
Agreed. (+&-) have same weight.
One alternative is ( the non-OOP way) to map a function say weight(char) which gives you the weight of any char you entered.

siddhant3s 1,429 Practically a Posting Shark

>its like no matter what numbers are entered they are set to 0 but for the life of me i dont get why
Look at the read_money() you still have declared the local dollars, cents; Delete them

void AltMoney::read_money()

{  
	[B] int dollars, cents;<<Delete this line[/B]
     cout << "Enter dollar \n";

Plus, the prototype of the function should be just void read_money. So just strike of the AltMoney:: before the defination

class AltMoney 
{ 
    public: 
        AltMoney(); 
        AltMoney(int d, int c); 
		friend AltMoney add(AltMoney m1, AltMoney m2);
        void display_money(); 	
		void AltMoney::read_money();//change it to [B]void read_money();[/B]

But the defination should remain with the AltMoney::read_money() { }

void AltMoney::read_money()

{  
	// int dollars, cents; deleted this line
     cout << "Enter dollar \n"; 
     cin >> dollars; 
blah
blah
siddhant3s 1,429 Practically a Posting Shark

Oh man! its your fault. You have spoiled all over by writing definitions like AltMoney read_money() while they should be AltMoney::read_money() i.e It should be a member function of AltMoney.
Ok now here is what to do:
Rewrite read_money as a member function of AltMoney
and read the post by nucleon he has explained it all.
Also, in the read_money function, you should cin the dollar, and cent not d and c.
Getting me?

siddhant3s 1,429 Practically a Posting Shark

Keep it simple. You should perhaps say that you want to write a parser.
I guess you already have made the stack class. At any point of time the comparison operator works with characters too.

siddhant3s 1,429 Practically a Posting Shark

SEARCH MILLIONS OF VIDEOS:


Error: no file category

You will be redirected to the Top 50 page in 5 seconds

This is what I get while opening your link

siddhant3s 1,429 Practically a Posting Shark

The error is definitely right. You are using uninitialized d and c.
So what to do?
Look at the defination of

AltMoney read_money()
{ 
[B]	 int d, c;[/B]
     cout << "Enter dollar \n"; 
     cin >> d; 
     cout << "Enter cents \n"; 
     cin >> c; 
    blah
blah
}

I think you suerly meant the global d and c right? The one you defined in main(). So just strike off this line . Doing so will cause the function to use the global d and c instead and hence you will be happy.

siddhant3s 1,429 Practically a Posting Shark

The last funtion IsPrimeNumber () is giving me an error that states ..."Local Function definitions are illegal"....can someone please tell me why?
This is because you didn't closed the function definition of void ConvertTotalSeconds (void) (i.e. you didn't put the closing } while ending the definition of void ConvertTotalSeconds (void)
)

Also, even if you did, your function isPrimeNumber() will not work. This is because in your function you used if (Num % Num == 0) and rather I should tell you that every number divided by itself leaves remainder zero.
So you function will always show each number is prime.
djextreme5 showed you how the definition of the isPrime should be, but there is a error in his program too.
He didn't initialized the variable count and incremented its value.
So the definition should be something like this :

[B]int[/B] IsPrimeNumber (int num)
{
  for(int i = 2; i <= sqrt(num); i++)
   if(num % i == 0)
      { cout<<"Is not a prime";
         return 0;}

cout<<"Is a prime";
  return1;
}

Moreover, the style
void function_name(void ) is not good. Use
void function_name() instead. The first one is old and outdated and is usually used by C programmers.

siddhant3s 1,429 Practically a Posting Shark

>can't quite figure out how to get the queue to appear on screen.
Complete the queue::print() function.
First of all, make print() a member function of the class. In the print () function, you should simply print your main data array which is. int a; from front to rear with help of a loop.

for(int i=front;i<rear;i++)
     cout<<a[i];

>I also think I may have messed up my loops as well
Yes indeed, you have messed up the Menu by not using switch-case.
Use this template

int main()
{
//define choice,value and list
do
{
    //Display the menu
    cout << "1. Insert and dispaly" << endl;
    cout << "2. Delete and display" << endl;
    cout << "3. Exit" << endl;
    cout << "Enter your choice: ";
    cin >> choice;//take choice
    switch (choice)
    {
    case 1://when choice ==1
        cout << "Enter your value to be inserted: ";
        cin >> value;
        //cout << //Queue with added item will go here
        //
        //
        break;
    case 2://when choice ==2
        ;//cout << //Queue with deleted item will go here

    }
}while(choice != 3);
return 0;
}//end of main
siddhant3s 1,429 Practically a Posting Shark

>Can you add a semicolon after MYVAR(DLLINFO, DllInfo), like
Look at macro definition, the macro itself is adding a semi-colon. Adding a semicolon will actually add two semicolons.

@joejoe55
Yeah, you should send the code. If is huge, just attach it, otherwise paste it here.

siddhant3s 1,429 Practically a Posting Shark

You can use system() function and issue a copy command.
I don't know what are the alternative.

But this will definitively work.

siddhant3s 1,429 Practically a Posting Shark

There is a much better way:
Just add a i-- in the body of the if statement;

for (int i = 0; i < inp.length(); i++)
	{
		if (inp[i] == '~')
		{
			inp.erase(i, 1);
			i--;
		}
	}

And it works like charm.
I dont know why are you using strlen instead of .length()

If you didn't understand why it worked by adding i--, call me back.

siddhant3s 1,429 Practically a Posting Shark

>i need code for scientific calculator in vc++ by using switch case statement
So tell me what have you tried. Remember, we don't provide codes. We only help those who show efforts. Please try and then tell us on what part are you having problem.

siddhant3s 1,429 Practically a Posting Shark

The code tags are [[B]CODE=c++[/B]][[B]/CODE[/B]].
You are getting the error because you are redefining myfile at two places: first as ifstream and then as ofstream which is illegal.
use fstream instead as:

fstream myfile;
myfile.open(filename);

As I can see, your array is of type double. getline() works only for strings and not for numerical data types. You should use the << and >> overloaded operators
Do not use myfile.eof() as it does not work as you suppose it to be. It will cause the loop to be iterating one additional time in the last.
Rather Use:

int x = 0;
while (myfile >>truck_data2[x++]));

Simple and best

siddhant3s 1,429 Practically a Posting Shark

You have to code that. So its completely your decision. By the way.... if "online" mean through the internet, then it will be a nice one. You will have to learn something about sockets and protocols.