1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Structure and Functions Help

Discussion in 'C' started by prockaz, Apr 12, 2012.

  1. prockaz

    prockaz New Member

    Joined:
    Apr 12, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Define a structure called Pagent that stores contestant no, first and last name, country, their scores (a floating-point array that stores 5 judges score), a floating-point array stats that stores statistics such as average, highest score and lowest score.



    Define a function AddPerson that will accept a pointer to an array of Pagent. The function should enter contestant details (names, country and the judges scores) into the array using pointer notation. The first contestant number begins with 200, and is incremented by 1 for each member following. The function should allow the user to add only one or more Contestant as they wish.
     
  2. hobbyist

    hobbyist New Member

    Joined:
    Jan 7, 2012
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    0
    What part(s) are you having a problem with?

    Code:
    #define INIT_PAG_NUM 200
    
    typedef struct {
       /* add vars as required */
    } pagent;
    
    void addPerson(pagent *); /* function prototype */
    
    int main(void) {
       ... bits of code
    }
    Based on what you've posted, the function would probably need a control loop, so that the user could enter data for as many contestants as wanted.

    Code:
    void addPerson(pagent *tmp) {
    
       loop(while user wanting to add data is true) {      
          /* pointer notation (tmp + current_index)->member_field */
       }
    }
    that loop should also check against current_index being valid for the maximum number of contestants... you don't want to add data to a record that doesn't exist even if the user insists on trying. :)
     
  3. prockaz

    prockaz New Member

    Joined:
    Apr 12, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    thanks man !
     
  4. geethesh babu

    geethesh babu New Member

    Joined:
    Apr 26, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    k k can u tell me this programm it s immediately so..........
    1) write a cprogeamm that will be the value x and evaluate the following function?
    y=1 for x>0
    y=0 for x=0
    y=-1 for x<0
     
  5. geethesh babu

    geethesh babu New Member

    Joined:
    Apr 26, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    1) write a cprogeamm that will be the value x and evaluate the following function?
    y=1 for x>0
    y=0 for x=0
    y=-1 for x<0
     
  6. hobbyist

    hobbyist New Member

    Joined:
    Jan 7, 2012
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    y = myfunction(x);
    y = x > 0 ? 1 : x == 0 ? 0 : -1;
    you could write a function and pass x as a parameter, evaluate it inside of the function body and then return the appropriate value. you could use the ternary operator to evaluate it too, or even an if / else if / else structure.
     

Share This Page