~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I tried to fix the problem by changing the arrays to
I tried to call the sort method to sort the array by doing this,

sortHand( char const *faceValue ); // Sort the array

but there is still a problem.

I dont if if its just me but how can you expect a procedure to sort a data item for you which involves manipulating teh data by passing the argument as constant ??? In you function prototype the const qualifier applies to the char array data and not the pointer if thats what you wnated to do ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

If i were being paid by you then it would have made sense to post such thing, since your questions look very similar to the customer requirement phase of software development. So how much you paying Miss Dani for the project ???

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

1. X & 1 stands for bitwise AND ing of the unsigned variable X with 1.

2. b++ stands for post incrementing b which means that the value of b is incremented afer it has been used in teh expression.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Two points about ur program:

1. Dont flush the input stream because it has got undefined behaviour.

2. YOu are assigning the char array "okay" to char pointer stuff but till that point okay has not been defined. Swap the two stmts to avoid the syntax error.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

a magical staff

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You get the hampster song

I put in a boiled egg

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Write a costructor which accepts 4 arguments along with the constructor which you have written which accpets 2 args.

Write something like

Circle (T a, T b, T c, T d) { ... }

Bye.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You get a chicken

I put in Dead Fish

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm it just requires few mods which u can esily do, but still if the below solution doesnt satisfy your requirement feel free to modify.

int main()
{
    string name = "here is the code" ;
    char* tmp_name = new char ( name.size() ) ;
    strcpy ( tmp_name,name.c_str() ) ;
    for (int i = 0; i < strlen (tmp_name); ++i )
    {
        cout << endl << "Character " << i + 1 << " is " << tmp_name [i] ;
    }
    return 0 ;
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
#include <iostream>
#include <cstdlib>
#include <cmath>
#define pi 3.14159265
using namespace std;
template <class T>
class circle {
  public:
    circle();
    circle(T,T,T,T);
    void populate_classobj(T a1, T b1, T a2, T b2);
    T radius();
    T circumference();
    T area();
  private:
    T x1,x2,y1,y2;
  protected:
    T distance();
}; //End of class
//Function definitions
template <class T>
circle<T>::circle(T a1,T b1,T a2,T b2)
{
  x1=a1;
  y1=b1;
  x2=a2;
  y2=b2;
}
template <class T>
circle<T>::circle()
{
  x1=0;
  x2=0;
  y1=0;
  y2=0;
}
template <class T>
void circle<T>::populate_classobj(T a1, T b1, T a2, T b2)
{
  x1=a1;
  y1=b1;
  x2=a2;
  y2=b2;
}
template <class T>
T circle<T>::radius()
{
  return distance();
}
template <class T>
T circle<T>::circumference()
{
  return pi*radius()*2;
}
template <class T>
T circle<T>::area()
{
  return pi*pow(radius(),2);
}
template <class T>
T circle<T>::distance()
{
  return sqrt( pow((x2-x1),2) + pow((y2-y1),2) );
}
 
int main()    //Main
{
  //Initialize variables
  float x1,x2,y1,y2;
  int input=0;

// specyin type is must

   circle<double> my_obj1 (1,3, 4, 5); 

// you didnt write a constructor which took 2 args but still were 
// constructing objs by passing in just 2 values 

   circle<double> my_obj2 (1.5,-0.5,-6.65,10.0);


  while(input<4)
  {
    //Choose functions to compute
    cout<<"Press 1 to compute the radius of the circle"<<endl;
    cout<<"Press 2 to compute the circumference"<<endl;
    cout<<"Press 3 to compute the area of the circle"<<endl;
    cout<<"Press 4 to enter new values for Object 1"<<endl;
    cout<<"Press 5 to enter new values for Object 2"<<endl;
    cout<<"Press 6 to exit"<<endl;
    cin>>input;
    //If statements
    if(input>6)
    {
      cout<<"PLEASE PICK A NUMBER BETWEEN 1 AND 6"<<endl;;
      input=0;
    }
    if(input==1)
    {
      cout<<"Radius of object 1 equals: …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Try something like:

int main()
{
    string name = "here is the code" ;
    char* tmp_name = (char*) malloc ( name.size() ) ;
    strcpy ( tmp_name,name.c_str() ) ;
    for (int i = 0; i < strlen (tmp_name); ++i )
    {
        printf ( " \ncharacter %d is %c ", i + 1, tmp_name [i] ) ;
    }
    return 0 ;
}

It is pretty simple to undertand program, ofcourse there are many other ways out there to do the same thing. This was just one of them.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

the wooden bridge

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

YOu get only the fizz

I put in an iron rod

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

from a mage

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

YOu get smeared in fake blood

I put in digital clock

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Try out this simple code snippet:

int main (void)
{
    const int LIMIT = 4 ;
    int counter_I = 0, counter_J = 0, counter_K = 0 ;
    int i, j, k ;

    for ( i = 0; i < LIMIT; ++ i )
    {
        ++ counter_I ;
        for ( j = 0; j <= i; ++ j )
        {
            ++ counter_J ;
            for ( k = 0; k <= j ; ++ k )
            {
                ++ counter_K ;
            }
        }
    }
    printf ( "\nThe value of counter i is %d ", counter_I ) ;
    printf ( "\nThe value of counter j is %d ", counter_J  ) ;
    printf ( "\nThe value of counter k is %d ", counter_K ) ;
    printf ( "\nThe value of counter is %d ", counter_I + counter_J + counter_K ) ;

    return 0 ;
}

Thus the total times is:

Outermost loop = 4
Middle Loop = 4 + 6
InnerMost loop = 4 + 6 + 10

Hope you see the pattern.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

wearing a hood

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Before answering your question i for the last time request you to post the code in the way which i have posted, neat , clean, indented and make it stand out using code tags. Last and final warning otherwise you would lose the friend who is trying to help you out.

printf ("Enter weight #%d ", i+1);
// ask the user to input in the weight

fgets (buf, BUFSIZ, stdin);

// this is a function which accepts the input given by the user and puts
// it in a character array. The variable "buffer" is declared and defined
// an array of BUFSIZ or "512" characters (here BUFSIZ is a constant
// built inside the compiler )

// stdin : since i am accepting the input from standard input stream
// or device which is the keyboard in this case. You can check the
// prototype of this function at www.cppreference.com

if ( buf [strlen(buf) - 1] == '\n' )
buf [strlen(buf) - 1] = '\0' ;

// here in these two stmts i remove the stray newline character which
// also entered the char arrray along with the normal input since you
// pressed the RETURN or the ENTER key. so if the last element of the
// char array is the newline character, i replace it with a null terminator
// (c style strings are character arrays with the '\0' at …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You get to drink jellyfish soup

I put in a Cell phone

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Maybe you should start looking at the mobile specific forums of microsoft for moreinformation

http://msdn.microsoft.com/windowsmobile/
http://www.windowsdevcenter.com/pub/a/windows/2006/01/24/windows-mobile5-emulators-in-visual-studio-2005.html

Hope it helped, bye.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Application development just appears natural to you when you gain enough knowledge to code an application all by your own accord. So if you still fuzzy on how applications are made then you havent quite reached the mark.

Application developement in C++ is no different from the simple programs you used to write except now those small programs become the modules or small part of some big time application.

Also the concept of GUI (graphical user interface) libraray comes into play which you have to use to render text boxes, buttons and handle button events.

If you need to explore or experiment with such libraries i would recommend an Opensource GTK+ library for application development in C++. Just google for it and you will be able to find out from where it can be downloaded as well as the forums and tutorials related to it.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I didnt change the logic of the program but just made the syntax errors which bugged you to go away. I would very much recommend you to format your code properly otherwise i wont be much of a help in the near future coz its really difficult to make out the problem with the code formatted in a bad way.

Also in your code in place of "i" variable you have written the number "1" which caused your program to crash. If you are coding in Notepad i would very much recommend you to switch to a syntax highlighter and indenter IDE which would make your as well as our task easy.

int main(void)
{
    double x[4] = {1.2,2.4,3.6,4.8};
    double f[4] = {0.1,0.2,0.3,0.4};
    double xave = 0.0;
    double ftotal = 0.0;
    int i;
    double weights[4] = {0};
    char buf[BUFSIZ];
    for(i = 0; i < 4; ++i)
    {
        printf ("Enter weight #%d ", i+1);
        fgets (buf, BUFSIZ, stdin);
        if ( buf [strlen(buf) - 1] == '\n' )
            buf [strlen(buf) - 1] = '\0' ;
        weights[i] = atof(buf);
    }

    for (i=0; i <4; i++)
        ftotal += f[i];


    if  ( (int) ftotal != 1 )
    {
        printf("error\n");
        exit (1);
    }

    for(i=0; i<4;i++)
    {
        xave += f[i]*x[i] ;
        printf("\nThe weights are %f",f [i]);
    }
    printf("\nThe average is %f\n",xave);

}

Hope it helped, bye.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

who at night

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Moral of the story :
"It pays to have a Wolf by your side" :D

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

time building softwares

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Slavery

"Slavery is not dead, its just that we cant recognize it"

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yeah even i respect Python really a lot coz of the top class games made using it (search www.gamespot.com for Severance:Blade of Darkness and Freedom Force) and also since its used in game scripting (stackless python for threading support).

Well I better stop going off the track least some Mod busts me :)
(if you have anything to ask or say just PM me)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You are most welcome Mr. Moderator :)
Hope you enjoyed your stay at the C++ forums

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm maybe you should carry out the processing in your snippet only when the vector is not empty.
It can be easily done using something like:

vector<int> v;

for( int i = 0; i < 5; i++ ) {
   v.push_back(i);
 }
 while( !v.empty() ) {
   cout << v.back() << endl;
   v.pop_back();
 }

Hope it helped, bye.

[edit]
Or maybe you can in a smart way check if the user decided to leave the vector empty and in that case you can just create a default floating point vector for illustrating your point. That way it wont make a difference if the user leaves out the inputting part since your point will be very well driven home with your default array and the teachings will reach the needy :mrgreen:
[/edit]

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I am waiting for someone to give me one so that I can see how much is subtracted from my rep points.

Would you mind if it were me !!!:mrgreen:

Anyways thanks a lot Wolfie for clearing my doubts and yeah you said it right.I completely agree with you, as long as i am doing it right i need not fear anyone. Hats off to you.

'Stein commented: Looking to override that red dot. ;) -'Stein +3
arjunsasidharan commented: My turn :) +3
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

an open-source proponent

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Now that is sweet, except I wouldn't use exit (1), but would rather stay in the input loop.

Thanks for the appreciation.
Hmm i guess you are right, no use being too harsh :)
But that just involves adjusting the "if" stmt a bit and voila one would get what he wants.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm strange, but here i get a red dot in my CP with someone mentioning

it's not neccesary to comment on everything. above post eas sufficient

Should i send a screenshot ???

[edit]Hmm when i come to think of it, it seems to be "-ve reputation"
But why would someone do such a thing for a perfectly harmless post.
Cant MODS find out why someone feels like i am breaking the forum rules ?
[/edit]

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I agree with you, cin.get() is the portable way to wait, but take a look at a small code snippet I wrote a long time ago:
http://www.daniweb.com/code/snippet105.html

I would love, if you could explain to me why cin.get() is such a flop in this fairly simple case.

Just thought would let you know that your program crashes when i dont enter any floating point input when asked for before entering "q" and pressing the RETURN key. (maybe you wanted to have it that way, i have no way of knowing, just my 2 cents).

I would love, if you could explain to me why cin.get() is such a flop in this fairly simple case.

This is because of the stray '\n' left in the input stream which occurs when the user presses the return key to convey his choice.

Just append the stmts:

cin.clear();
cin.ignore(std::numeric_limits<streamsize>::max(),'\n');

at the end of program before the cin.get () and everything should work out to be fine without that nasty "system" call which kills the so much loved portability.

Maybe you would want to take a look here:
http://www.augustcouncil.com/~tgibson/tutorial/iotips.html

Hope it helped, bye.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

my orders strictly

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

OH sorry Mr. Vegaseat my bad, thanks for pointing out the flaw to me. The OP required the user to input floating point values so i actually shouldnt have taken a decimal input in the first place.

Well here is a near foolproof Implementation of the input accepting phase for your program which accpets only valid floats.

int main (void)
{
    int counter = 1 ;
    float  my_weight = 0;
    char buffer [BUFSIZ] = {'\0'} ;

    while (counter <= 4 )
    {
       printf ("Enter the weight %d: ", counter) ;
       fgets (buffer, BUFSIZ, stdin) ;

        if ( ! isdigit (buffer [0] ) )
        {
            printf ("Illegal input") ;
            exit (1) ;
        }

       if ( buffer [strlen (buffer) - 1] == '\n' )
         buffer [strlen (buffer) - 1] = '\0' ;

         my_weight = atof (buffer) ;

       if ( my_weight > 0 && my_weight < 10)
       {
          counter ++ ;
        }
       else
       {
          printf ("Incorrect choice!!!\n") ;
        }
    }
    return 0 ;
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

piece of crap

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I dont know how to put this but Miss Dani i would please request you to place a moderator for this button or anything related to bad posts or atleast come up with a good idea to stop someone misusing this button.

Looks like someone out there, just to take out his personal spite on me has marked the reply posted by me on this thread as "bad post".
http://www.daniweb.com/techtalkforums/post258739.html#post258739

with the demented comment

it's not neccesary to comment on everything. above post eas sufficient

No crap, so spam, no flaming just a good piece of info !!!!

In the name of god, i would request Miss Dani to personally visit the thread and judge for yourself what was wrong with my reply.


Only because someone snuck in to reply when i was writign down my own one. Just for a difference of 5 MINS, i tell you 5 MINS someone thinks i am doing this as a formality.

Hope you please tackle this matter personally least i should lose my faith in the functioning of this forum which i have always loved.
The response of my post will decide what has become of my dedication to this forum.

Requesting everyone out there to judge for urself if i was really wrong or not.

The Dude commented: Its ok my friend........Heres some GOOD rep to make up for it!!! (1 red dot wont hurt ya) +1
joshSCH commented: hahaha.. Aww.. poor, naive Sanjay.. :D +13
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

My post was not meant to contradict or show you wrong, just to point to the OP not to use the system functions when the same thing can be done using the std library functions.

This will be useful when he wants to write normal programs not involving "windows" specific code and needs the pause functinality.

Talking about heavy overhead, the iostream header creates about 95% of the overhead.

which cant be avoided when you are all set to write some concrete code snippets.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

For a full blown implementation of Binary trees in OO C++ see here:

http://library.thinkquest.org/C005618/text/binarytrees.htm

A good way of approaching the problem will be to jot down all the details (like variables, class design, usage etc) which though may seem as a waste of time to you will definately help you in the long run. IF this kind of documentation is made, the coding just becomes mechanical.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Better not call the "system" functions like system ("pause") .

Your job can be very well done using the function cin.get() which does the same function without invoking the system procedures which incur heavy overheads.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hi,
What should i add on so that user can enter the four weights from the keyboard. The program should print an error message is the weights are out of range?

Try something like:

int counter = 1 ;
while (counter <= 4 )
{
   printf ("Enter the weight %d: ", counter) ;
   scanf ("%d", &my_weight [counter - 1] ) ;
   
   if ( some_condition_of_validity)
   {
      counter ++ ;
    }
   else
   {
      printf ("Incorrect choice!!!") ;
    }
}

This should keep on asking the user the choice until he enters a correct number.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

what the hell..

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yes if your OS is 32 bit windows OS and if it is 64 bit OS then just call it Win64 API :)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
for (int a = 0; a <= numbers.size(); a++)
   cout << numbers[a] << ", ";

I think you are in for a bit of surprise ;)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

in presence of

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

which occured at

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

started to run

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Pride

Have pride in your work and the world will be proud of you