College project on arrays and functions

This is a discussion on College project on arrays and functions within the C Programming forums, part of the General Programming Boards category; First post here Im a computer science major and my c programming class was assigned a project and i was ...

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    17

    Smile College project on arrays and functions

    First post here

    Im a computer science major and my c programming class was assigned a project and i was wondering if someone could give me a push. its on arrays and functions. We use K.N. King's c programming book. I understand everything so far except probably arrays. Let me also say I really want to learn this stuff and im not interested in a free ride but I would like some input from you guys. I appreciate any help.

    Basically these are the directions

    Coach Whytlaw, the local swim coach has a problem he wants you to help solve.
    The timing system at the pool gives him a le containing information about
    each race. The le contains:
    The number of races in the le, on a line by itself.
    For each race, there is a line in the le containing the following:
    Information about the pool as follows: Whether the Pool is Long corse (L)
    or Short Corse (S) Whether the Pool is Meters (M) or Yards (Y)
    Information about the length of the race, in appropriate units. The shortest
    race is 50 yards or meters and the longest race is 1650 yards or meters.
    The time (in seconds) for each length of the pool (A length of the pool in a
    long corse pool is 50 meters or yards. A length of the pool in a short corse pool
    is 25 meters or yards).
    The coach would like you to use the times to do some analysis on the races.
    Here is the information he would like:
     The total length of time it took to swim the race (displayed in minutes
    and seconds).
     The time for each 50 yards in the race (displayed in minutes and seconds).
     For races longer than 100 yards or meters, the time of each multiple of
    100 yards or meters.
     The fastest 50 yards or meters, by number (1st 50, 2nd 50,etc)
     the slowest 50 yards or meters, by number (1st 50, 2nd 50,etc)
     the fastest 100 yards or meters, by number (1st 100, 2nd 100,etc)
     the slowest 100 yards or meters, by number (1st 100, 2nd 100,etc)
     Wheter or not the race was a negative split (was the rst half of the race
    slower than the second half ).

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Welcome to the forum, JThunder!

    However, we don't do what you're asking for -- yet.

    It's totally up to YOU to give your assignment a start. When you get stuck on some programming issue on C or pseudo code, then post what you have done so we know where you're at with it, and tell us what is the problem(s), specifically.

    What you've posted here, is WAY too broad, and there's no intelligent way to answer what it asks, without basically doing it.

    So, get started, and when you get stumped, even if it's just a skeleton of a program or pseudo code, post it back when you have questions/problems.

    For a general start on these things, I like to put off all the details that are not essential, and work on the basic flow of the program, first. Get the functions laid out even though they're just a stub function, atm.

    Then take the easiest requirement, and do it first, check it, then next easiest, etc.

    Last thing I do is add any details I left out previously.

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    17
    Thanks for the reply. That sounds good man, ill get started and i appreciate the tips. ill be sure to post back in this thread.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    if you write out by hand two things, following exactly what the instructions say
    1. what the data in the file would look like
    2. what steps you would do to figure out the answers to the questions (without a computer)
    3. translate that stuff to a data file and code (with the results of #2 as comments)

  5. #5
    Registered User
    Join Date
    Sep 2011
    Posts
    111
    If you are having issues with arrays, remember you ARE NOT limited to that book the professor assigned. There is always the internet, and other books, you can use.

    But take a look at Arrays in C - Cprogramming.com (Lesson 8: Arrays in C).

  6. #6
    Registered User
    Join Date
    Dec 2011
    Posts
    17
    Thanks a lot guys. I am starting to work on it again now. Its due tomorrow at midnight so hopefully ill cover a lot of ground today. Much appreciated

  7. #7
    Registered User
    Join Date
    Dec 2011
    Posts
    17
    Thanks for posting the link to that chapter on arrays! very helpful. I'm thinking I'm going to have to scan the values into the array and use them to answer the questions. If I have that correct I think this project will be easier than I thought.

    Quick question, lets say an array has 4 slots (for four times of the race) can I scan in four values to store into that array ? Silly question maybe lol but I think with that I can finally begin this project

  8. #8
    C Newbie
    Join Date
    Oct 2011
    Posts
    59
    Quote Originally Posted by jthunder View Post
    Thanks for posting the link to that chapter on arrays! very helpful. I'm thinking I'm going to have to scan the values into the array and use them to answer the questions. If I have that correct I think this project will be easier than I thought.

    Quick question, lets say an array has 4 slots (for four times of the race) can I scan in four values to store into that array ? Silly question maybe lol but I think with that I can finally begin this project
    Yep, each 'slot' of the array can hold a value. (Excluding strings which need a 'slot' per character.)

  9. #9
    Registered User
    Join Date
    Dec 2011
    Posts
    17
    Great. I'll get started now and post later. Thanks

  10. #10
    Registered User
    Join Date
    Dec 2011
    Posts
    17
    Thanks to all who have helped so far. I actually am almost finished. My question is how would one find the largest and smallest value in an array, when the values in the array have been entered in by the user
    ?
    I plan to compute this using 3 functions, one for each race.

    Code:
    /*Function to compute info for first race*/ 
    float longcourse (float lcm[])
    {
     
    /*INTENTIONALLY LEFT BLANK FOR NOW FASTEST 50*/
     
    
    
     
    /*SLOWEST TIME GOES HERE SLOWEST 50*/
    
    
    /*FASTEST 100*/
    
    
    /*SLOWEST 100*/
    
    
    /*NEGATIVE SPLIT*/ 
    
    
    return 0;
    }
    /*Function to computer info for second race*/
    float shortcourse1 (float scm[])
    {
    
    
    
    
    
    
    return 0;
    }
    /*Function to compute info for third race*/
    float shortcourse2 (float scy[])
    {
    
    
    return 0;
    }

  11. #11
    Registered User
    Join Date
    Dec 2011
    Posts
    17
    This is what I ended doing for the fastest 50. Maybe inefficient..what do you think? Im sure there is a better way but it works..

    Code:
    /*Function to compute info for first race*/ float longcourse (float lcm[])
    {
     
    /*INTENTIONALLY LEFT BLANK FOR NOW FASTEST 50*/
     if (lcm[0] > lcm[1] && lcm[0] > lcm[2] && lcm[0] > lcm[3])
      return  printf("Fastest 50: %.2f\n", lcm[0]);
     else if(lcm[1] > lcm[0] && lcm[1] > lcm[2] && lcm[1] > lcm[3])
      return printf("Fastest 50: %.2f\n", lcm[1]);
    else if (lcm[2] > lcm[1] && lcm[2] > lcm[0] && lcm[2] > lcm[3])
      return printf("Fastest 50: %.2f\n", lcm[2]); 
    else if (lcm[3] > lcm[0] && lcm[3] > lcm[1] && lcm[3] > lcm[2])
      return printf("Fastest 50: %.2f\n", lcm[3]);

  12. #12
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    You had better check what the return value of printf() is... your function is going to return garbage.

    Look it up in your compilers library documentation ... if you don't have it... get it.

  13. #13
    Registered User
    Join Date
    Dec 2011
    Posts
    17
    I got this in compile time warnings

    warning C4244: 'return' : conversion from 'int' to 'float', possible loss of data

    it works but i get a lot of those warnings

  14. #14
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You would probably just use a min and max variable. They are both assigned the first value entered. Then for every value entered thereafter, you do two if statements:
    Code:
    for(each value entered) {
       //any other code here
       if(Value is the first Value) {
          min = Value;
          max = Value;
       }
       else {
          if(newValue > max)
             max = newValue;
    
          if(newValue < min)
             min = newValue;
       }
    
    }
    For maximum speed, you'd want to assign min and max variables to the first value of the array[0] (or entered value from the user), outside the for or while loop, and just start the array index from 1, instead of 0, and keep the "else" code only, inside the loop.

    No "else" is kept in that case, of course.
    Last edited by Adak; 12-04-2011 at 10:06 PM.

  15. #15
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by jthunder View Post
    I got this in compile time warnings

    warning C4244: 'return' : conversion from 'int' to 'float', possible loss of data

    it works but i get a lot of those warnings
    Because you are not paying attention to types, return values and other necessary things.

    Don't ignore warnings... fix them.

    Like I said... get the documentation and look this stuff up...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with while statement for college project
    By fsutati in forum C Programming
    Replies: 8
    Last Post: 10-24-2010, 08:47 PM
  2. this project - functions and arrays - getting few errors
    By arps789 in forum C++ Programming
    Replies: 10
    Last Post: 12-10-2007, 07:29 PM
  3. Should I go to a state college and be 20k in debt, or a private college and be 90k in
    By Terrance in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 10-10-2003, 08:22 PM
  4. need help with C++ project for college
    By dawiz66 in forum C++ Programming
    Replies: 6
    Last Post: 04-05-2002, 11:08 AM
  5. Help with Project using arrays
    By dustinc in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 04:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21