Thread: C project

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    16

    C project

    Post Office Project

    I have to do this project, but I really don't know how to. If someone could help me, please do, I would really appreciate it

    We suppose we have N cities identified by a numeric code and by their geographical position (north, center, south) and many different postal products identified by a code, a type (letter, recorded delivery, etc.)and shipping prices.
    For each city it's possible to insert a max of M products.
    The program must allow the user to:
    -given a city, the user can insert a new product, if possible. We have to consider the positions of previously entered products.
    -calculate entire price of products for a city.
    -delete a shipped product.

  2. #2
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Make a structure that will hold all of the cities values
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    16
    C pastebin - collaborative debugging tool

    that's what I did, but I miss the correct way to delete an item from the cue... anyone could help me?

  4. #4
    Lost in the C ZaC's Avatar
    Join Date
    Jun 2008
    Location
    Italy
    Posts
    47
    Visto che sei italiano usiamo la nostra lingua madre :P
    Ho dato un'occhiata veloce al codice, hai scelto di usare un vettore per memorizzare i vari prodotti, e non una coda, per cui quello che dovresti fare, trovato il "j" che corrisponde al prodotto (linea 181) devi fare un secondo ciclo che vada da j al termine del vettore (city[i-1].num_prod) e copiare il prodotto successivo nella posizione corrente e solo successivamente diminuire il numero di prodotti per quella data città. Non è necessario ma per correttezza dovresti anche "resettare" l'ultima posizione del vettore non più utilizzata.
    Sono stato chiaro?
    OT: di dove sei? Che materia è?

    edit: linea 188 non 181
    Last edited by ZaC; 06-10-2009 at 09:03 AM.
    Sorry for my bad English
    and also for my bad programming style...

    ZaC'ZaCoder (?!)

  5. #5
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Your use of m, n, and p make me sad
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    16
    ehm... no, non ho capito come dovrei fare :/

    comunque e' l'esame di programmazione 1 ^_^

    p.s. ma che vuole questo qua sopra? 2 risposte, una piu' inutile dell'altra ha dato

  7. #7
    Lost in the C ZaC's Avatar
    Join Date
    Jun 2008
    Location
    Italy
    Posts
    47
    Devi sapere che qui se la tirano tutti e non poco
    Passando a noi, avevo letto decisamente di fretta il codice! Spiegami cosa intendi dire per cancellare un prodotto: data una città da input ed un determinato prodotto, cancellare questo dalla città?
    Se la risposta è sì, dalla riga 186 alla riga 189 dovresti modificare così:
    Code:
    while(j<city[i-1].num_prod)
        {
          if(strcmp(prodotto,city[i-1].listprod[j].type)==0){
              while(j<city[i-1].num_prod-1){
                     city[i-1].listprod[j].code_n=city[i-1].listprod[j+1].code_n;
                     strcpy(city[i-1].listprod[j].type,city[i-1].listprod[j+1].type);
                     city[i-1].listprod[j].prezzo=city[i-1].listprod[j+1].prezzo;
                     j++;
              }
         }
          j++;
        }
    La domanda te l'ho posta perchè non capisco a cosa ti serva il flag eliminato.
    Con questo codice:
    -hai trovato il prodotto da eliminare;
    -lo hai eliminato copiandoci sopra il prodotto successivo (se è l'ultimo prodotto semplicemente diminuisce il numero dei prodotti).
    Ora è più chiaro?
    Fammi sapere

    PS: come dovresti affrontare il caso in cui nella città ci siano due prodotti uguali?
    PPS: cosa studi?

    Translation:
    I read your code too much quickly. What do you mean by deleting a product?
    If you mean a certain product must be deleted from a certain city (both given by input) you could try this code:
    ....
    I'm asking this cause i don't understand why you should use the flag "eliminato".
    With this code:
    -you found the position of the product to erase;
    -you erase it coping the next product in it and so on (if it's the last one, you just reduce the number of product in that city).
    Now is it clearer?
    Let me know.

    PS: how should you manage the case two product with the same name are present?
    PPS: what do you study?
    Last edited by ZaC; 06-10-2009 at 12:26 PM.
    Sorry for my bad English
    and also for my bad programming style...

    ZaC'ZaCoder (?!)

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Please post in English.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Lost in the C ZaC's Avatar
    Join Date
    Jun 2008
    Location
    Italy
    Posts
    47
    Ok, sorry, have I to translate?
    Sorry for my bad English
    and also for my bad programming style...

    ZaC'ZaCoder (?!)

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by ZaC
    Ok, sorry, have I to translate?
    That would probably be a good idea.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    Registered User
    Join Date
    May 2009
    Posts
    16
    sei un grande!

    facevo lo stesso ciclo... sbagliando la condizione ._.

    rincretinito completamente mettevo (j==k), con k=cit[i-1].num_prod... lo so, merito solo schiaffi, ma avevo un mal di testa assurdo oggi

    nel caso in cui ci siano 2 prodotti uguali... brutta storia, dovrei riscrivere il codice ed affidarmi a degli ID credo, ma la consegna e' venerdi' e devo studiare, quindi va benissimo cosi'!

    comunque studio Informatica, esame di Prog 1... e non ci sono code e liste nel programma, per questo ho dovuto usare questo metodo!

    grazie mille ^_^

  12. #12
    Lost in the C ZaC's Avatar
    Join Date
    Jun 2008
    Location
    Italy
    Posts
    47
    Quote Originally Posted by laserlight View Post
    That would probably be a good idea.
    already done
    Sorry for my bad English
    and also for my bad programming style...

    ZaC'ZaCoder (?!)

  13. #13
    Lost in the C ZaC's Avatar
    Join Date
    Jun 2008
    Location
    Italy
    Posts
    47
    Quote Originally Posted by thenewbiecoder View Post
    sei un grande!
    ehehe thanks

    Quote Originally Posted by thenewbiecoder View Post
    facevo lo stesso ciclo... sbagliando la condizione ._.

    rincretinito completamente mettevo (j==k), con k=cit[i-1].num_prod... lo so, merito solo schiaffi, ma avevo un mal di testa assurdo oggi
    That's happen don't you worry
    Quote Originally Posted by thenewbiecoder View Post
    comunque studio Informatica, esame di Prog 1... e non ci sono code e liste nel programma, per questo ho dovuto usare questo metodo!
    Messina by chance?
    Quote Originally Posted by thenewbiecoder View Post
    grazie mille ^_^
    No problem we are here for this... really?!


    PS: I sudgest you to use for instead while, it's clearer. And also typedef if it's allowed in your exam.
    Last edited by ZaC; 06-10-2009 at 01:50 PM.
    Sorry for my bad English
    and also for my bad programming style...

    ZaC'ZaCoder (?!)

  14. #14
    Registered User
    Join Date
    May 2009
    Posts
    16
    I put a for cycle, thank you again for your help!

    I also put typedef, I put comments... I link you the code, if you can tell me if you see any error, I have to send it to the professor tomorrow ^_^

    http://pastebin.com/d3d22b39

    p.s. Naples!

  15. #15
    Lost in the C ZaC's Avatar
    Join Date
    Jun 2008
    Location
    Italy
    Posts
    47
    I spotted only a logic error, you flag as erased not the sent product but the last one, this is meaningless... I think that you don't need that flag ("eliminato").
    Example:
    You have to send the products a,b,c to the city x. Number of products = 3.
    You send b and now in the x product list you have: a,c,c (b erased, c copied in the position of b)
    The number of products now = 2.
    Now you flag c as erased but it's useless.

    The other thing I noticed is the use of typedef. I sudgested you to use it so you don't have to repeat struct a_product evrywhere so...
    Code:
    typedef struct a_product{
    ... 
    } product;
    and
    Code:
    #
    typedef struct a_city{
    ...
            product listprod[m];
    ...       
    } city;
    and so on...
    Tomorrow morning I will read it better now i'm a little tired so I could miss some error.

    edit:
    I told you I could miss something...
    From line 181 to 195:
    Code:
                                for(j=0;j<city[i-1].num_prod;j++)
                                    {
                                        if(strcmp(prodotto,city[i-1].listprod[j].type)==0)
                                        {
                                            for(;j<city[i-1].num_prod-1;j++) //note nothing inizilized!
                                            {
                                                city[i-1].listprod[j].code_n=city[i-1].listprod[j+1].code_n;
                                                strcpy(city[i-1].listprod[j].type,city[i-1].listprod[j+1].type);
                                                city[i-1].listprod[j].prezzo=city[i-1].listprod[j+1].prezzo;
                                            }
                                        }
                                    }
    Last edited by ZaC; 06-10-2009 at 06:04 PM.
    Sorry for my bad English
    and also for my bad programming style...

    ZaC'ZaCoder (?!)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 09:01 AM
  4. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM