Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

c++ program help!

Options
  • 05-02-2005 5:48pm
    #1
    Closed Accounts Posts: 478 ✭✭


    :) i must hav a c++ program running by friday
    i gotta write a program that accepts say 10 students names and exam result. the user must also be able to specify the number of students. there must aslo be a search featur in the prgram whereby the user can search for a student by name or result

    please please lads, can ye help me :o

    thanks a lot


Comments

  • Registered Users Posts: 1,372 ✭✭✭silverside


    hmm ... this is pretty basic stuff.
    I could write it for you very quickly, but that wouldn't really help you.
    show us what you have done so far. work from the basics - reading from the command line and storing one student and his exam result. work up from there to storing all the results. Then do the searching.

    tip: use the STL, std::string, cin and cout. Use either the vector or the map classes when you want to store more than one student.


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    From the FAQ:
    FREQUENTLY GIVEN ANSWER

    The most frequently given answer on the programming board is "Give us more info". So make sure that when posting a question you give as much detail as possible, including stuff you've tried that failed. If you show that you've made an effort at the problem then people are more likely to help. Asking people to write your homework without making any attempt at it will result in a PFO (Please Try Elsewhere).


  • Closed Accounts Posts: 478 ✭✭synchro


    all i hav done so far is used a struct and prompted the user to enter the student number and result
    i was just wondering how do i do the search thing








    silverside wrote:
    hmm ... this is pretty basic stuff.
    I could write it for you very quickly, but that wouldn't really help you.
    show us what you have done so far. work from the basics - reading from the command line and storing one student and his exam result. work up from there to storing all the results. Then do the searching.

    tip: use the STL, std::string, cin and cout. Use either the vector or the map classes when you want to store more than one student.


  • Registered Users Posts: 1,372 ✭✭✭silverside


    so you can store one mark. Can you store 2 by storing a vector of structs? It might be better to use a class - (why?).

    so here's one way of doing it.:
    ask the user to input a name.
    go through all your results to see if you have one that matches.
    This can be done by going through all the results one by one and seeing if result.mark == mark_to_search_for.
    if it is found say "found it and here's the name" otherwise say "nope its not here".

    Do somehting similar for name.


  • Closed Accounts Posts: 256 ✭✭$lash


    Search is simple ... just use a string for input and there is an inbuilt function in C++ to do string comparisons (I'll root it out and post it up later) so you could use that ...


  • Advertisement
  • Closed Accounts Posts: 478 ✭✭synchro


    $lash wrote:
    Search is simple ... just use a string for input and there is an inbuilt function in C++ to do string comparisons (I'll root it out and post it up later) so you could use that ...
    ysound out fortat
    is tat strcmp(string1,string1)


  • Closed Accounts Posts: 256 ✭✭$lash


    synchro wrote:
    ysound out fortat
    is tat strcmp(string1,string1)

    Yup its the strcmp function ... it returns a negative value if string1 is less than string2 ... a positive value if string1 is greater than string2 and a 0 if both strings are equal...

    you could use it something like this:
    
    void main()
    {
        char search[20];
        cin >> search;
        for (int i=0; i<SIZE_OF_ARRAY; i++)
        {
             if ( strcmp ( array_of_strings[i], search) == 0) 
                cout << "Item found";
        }
    }
    
    


  • Registered Users Posts: 1,372 ✭✭✭silverside


    hmm everyone here is assuming he is using C-style C++. It would be much easier to use STL-style C++ (with std::string and vectors). This makes your code easier rather than trying to remember arcane functions like strcmp. It's well worth learning it (maybe not by Friday but in the next few weeks).

    synchro what are you using?
    If you can get your hands on a copy of "accelerated c++" by Koenig and Moos, do so.


  • Closed Accounts Posts: 256 ✭✭$lash


    silverside wrote:
    hmm everyone here is assuming he is using C-style C++. It would be much easier to use STL-style C++ (with std::string and vectors). This makes your code easier rather than trying to remember arcane functions like strcmp. It's well worth learning it (maybe not by Friday but in the next few weeks).

    synchro what are you using?
    If you can get your hands on a copy of "accelerated c++" by Koenig and Moos, do so.

    Depends what your used to I guess... I presumed it looks like a collegey type thing so I'd say it's probably C-style C++ he is using.


  • Closed Accounts Posts: 9,314 ✭✭✭Talliesin


    silverside wrote:
    It would be much easier to use STL-style C++ (with std::string and vectors).
    20 Kudos points to silverside :)


  • Advertisement
  • Closed Accounts Posts: 256 ✭✭$lash


    Talliesin wrote:
    20 Kudos points to silverside :)

    Vectors are hard to grasp if you are only starting out in C++


  • Registered Users Posts: 1,372 ✭✭✭silverside


    i think they are easier than learning about char* and strcpy stuff. Especially if you come from a Java background. If you know C first though you might be tempted to stick with what you know.


  • Closed Accounts Posts: 9,314 ✭✭✭Talliesin


    20 more Kudos points :)


Advertisement