mulfunction of array - Page 6
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 6 of 6 FirstFirst ... 3456
Results 76 to 85 of 85

Thread: mulfunction of array

  1. #76
    Join Date
    Jun 2003
    Location
    Armenia, Yerevan
    Posts
    696

    Re: mulfunction of array

    Quote Originally Posted by david16 View Post
    But I guess my main porb is searching a specific location each time in a loop . do I have tp use each time if , else if , else if ?
    Three are several straightforward ways to overcome this issue.
    If the comparison chain is not very lengthy the if/else if chain could be acceptable. Otherwise, one of the option is to use switch() construct. Or even better to have a hash_table with integer key and corresponding function's pointer (the address) as a value, then you can simply call func_map[spot[i][j]](arguments...).
    Cheers.

  2. #77
    Join Date
    May 2017
    Posts
    173

    Re: mulfunction of array

    Yah . I guess this can work for me thx.

  3. #78
    Join Date
    May 2017
    Posts
    173

    Re: mulfunction of array

    you mean I can creatr an index to track current row and column to fincd next one easily?

  4. #79
    Join Date
    Jun 2003
    Location
    Armenia, Yerevan
    Posts
    696

    Re: mulfunction of array

    I have expressed the idea how you can avoid the usage of if/else if chain and of course to save time on comparisons with a single address fetch from a memory. This is what relates to hashing.

  5. #80
    Join Date
    May 2017
    Posts
    173

    Re: mulfunction of array

    Ah you meant something else . Ok I see . I will try to see what best fit my code . Thank

  6. #81
    Join Date
    May 2017
    Posts
    173

    Re: mulfunction of array

    My prog is to display parking slots for 2 categories of people : students and principal . there is 3 spots available with different dimension . In each spot the first row is always for principal and the students start taking places from 2nd row . I should be able to ask user what spot he want choose ( 1 , 2, or 3 ) and what time he want . The number of column is fixed to 12 which means each column an hour ( 8 Am - 8PM ) . I should be able to change each value in each 2d array separately : If user was principal and chose to park at 10 Am that means first column third row of 12 Am that means first column 5th column .

    The total number of parked cars at a specific hour ( in all 3 spots that means <ctime> to track program start )
    The number of parked cars in each parking ( taken places )
    The number of available parking slots ( in all 3 spots number pf empty places ).
    View the three parking area (display map of chosen array to show user what are taken places and available )
    The number of rejected request ( in all 3 spots if user changed his mind didn't want to take the place he chose I should count reject) .
    Last edited by david16; May 19th, 2017 at 03:36 PM.

  7. #82
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,704

    Re: mulfunction of array

    For how long is a car parked - 1 hour, rest of day or is this to be requested?

    If requested spot and time is not available what happens - a simple rejection or offered an alternative spot or time?

    So for principals, as there are 3 slots can only 3 principals park at the same time - one in each slot for the specified time?

    What happens if the first row is full and more principals want to park - do they get allocated space in the other rows first then to another spot if the first one full or if the first row of eg spot1 is full then try to allocate in first row of spot2 or just a rejection?

    There's quite a lot of detail missing from the spec.

    Is this a homework exercise/coursework etc?
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++17 Compiler: Microsoft VS2017 (15.3.4)

  8. #83
    Join Date
    May 2017
    Posts
    173

    Re: mulfunction of array

    When A parking is taken at a chosen time it stay there the program is not responsible to check in same place again when it gives a place it stays occupied till end of day . for principal first row of each spot is for them only for principals . if user request a time and at that column is occupied I should check other 2 spots for same column if available then user will be asked if he want it . if yes he take it and if no reject count . if all places in all 3 spots are occupied then program should propose another place at later time. if he accepted he take it and we change value of that place from 0 to 1 so it becomes occupied . If he refuse again rejects count again . The dimension of the array is designed at exact number of principal and students so I was not asked to recheck for a parking that was taken or if number exceeded places available . If a place taken It will stay occupied till 8 Pm . students start in all 3 spots from 2nd row till end of array

    these are the given dimension with fixed column number ( 12 so from 8 AM till 8 PM )

    Code:
    spot_1 [15][12];
    spot_2 [10][12];
    spot_3 [5][12];
    and it should display the additional info in post #81 . its confusing to manage these tasks together .

  9. #84
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,704

    Re: mulfunction of array

    its confusing to manage
    Its only confusing when all the required info from a spec isn't available. Determining what info is needed but not specified is part of program design. When needed info can't be obtained then assumptions need to be made and these assumptions need to be stated.

    gives a place it stays occupied till end of day
    This means that all columns equal to or higher than the one for the entered time need to be set to occupied once a slot is found - so that when checking columns for an entered later time the spot is marked as occupied.

    I don't know how much c++ you have learnt - have you come across structs/classes yet? How are you learning c++?

    I'll re-ask again. Is this a homework exercise/coursework etc? Why are you required to write this program?
    Last edited by 2kaud; May 20th, 2017 at 03:05 AM.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++17 Compiler: Microsoft VS2017 (15.3.4)

  10. #85
    Join Date
    May 2017
    Posts
    173

    Re: mulfunction of array

    This is a practice. But if I can't do it how can I pass my exams its pretty much closer to this type. I still didn't study classes not even pointer the program should only do what I said . I'm not responsible yet of recheck for a place . If a place is given , It should stay occupied till the end . Yes so when user is students , first row of each parking are not for them search start from second row but on display only taken ones from both categories will appear to be taken . I should ask each user the time to give him the column that correspond to that time if not found in first spot it should search on other 2 if also not found will be then proposed another parking in the rows specified for his / her categories if he says yes he take it if not reject count . If found , we should also ask user if he want to take that place if yes he take it if no reject count . a map show be display also user can ask for places taken at a specified time or available slots and the infos I already told you about in post #81 .

Page 6 of 6 FirstFirst ... 3456

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)