#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    2
    Rep Power
    0

    Two dimensional arrays


    Hey! I have a problem increming arrays. Lets say I initialize a dimensional array as, int 2array[2][2] ={1,A}, and I wan't to increment 1 and A together if a conditional statement I set is true. How would I do this? Would I need to convert it to hex? Yes, this is homework, part of a much bigger problem. If no one can help me with this problem, then here's the whole. I just need to get on the right track.

    " Airline needs a program to assign boarding passess on its only plane that has a seating capacity of 20. They want to use an alphanumeric seat number, and they want to enter the passenger's name(first and last). The seats in the plane are numbered as follows.
    First Class Business Class
    1A,1B,2A,2B 4A, 4B, 4C, 4D
    5A, 4B, 4C, 4D
    6A, 6B, 6C, 6D
    7A, 7B, 7C, 7D
    You will need to hard code the seat number array and set every element of the passenger array to blanks at the beginning. If a seat is empty, the corresponding element is blank. If a seat is reserved, the corresponding array element has someone's name on it. Assign the seats numerically on a first come first serve basis. When there are no more passengers to process or when the lane is full, display the total number of passengers in each class. Also display a plane manifest listing the seating number, the name of the passenger assigned to that seat, and the class of the seat in order by seat number. Only list seats that have someone assigned to them."

    If you know anything about this, even if it is minor, please help me. Thank you.
  2. #2
  3. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    243
    First of all, you can't set an int = A. You either need to tell the compiler it is hex or set it in single quotes.

    I don't really understand what you are trying to do. You increment the dimensions of the array however you like (as long as you stay in bounds!). You can do 2array[0][0] to access the first element, or 2array[1][1] to access the last element (there are only four elements in your array). You can use variables to access array elements (just be sure they do not go out of bounds, you will get ugly errors), very convenient for looping.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

IMN logo majestic logo threadwatch logo seochat tools logo