Results 1 to 9 of 9

Thread: C++ Help!!

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    Thanks
    0
    Thanked
    0 times in 0 posts

    Unhappy C++ Help!!

    Hi Everyone,

    I've just started a C++ course and finding myself to be struggling through it worse than i expected. I need to create a coding for this:

    class MarClass
    {
    private:
    // Details not shown. An object of this class maintains information for
    // each competitor in the form of a name, an identification number and
    // the time taken to complete the race.

    public:
    void Initialise(void);
    // Initialises an object by supplying names and identification numbers.
    // All times are set to a sentinel value to indicate "no entry".
    AnsiString GetName(AnsiString Number);
    // Searches for a competitor with this identification number.
    // If one is found the name of the competitor is returned.
    // Otherwise the string "No such competitor." is returned.
    AnsiString GetTime(AnsiString Number);
    // Searches for a competitor with this identification number.
    // If found returns the time taken in the form "hrs/mins/secs"
    // or, if no time has been entered, returns "No time recorded.".
    // Otherwise the string "No such competitor." is returned.

    AnsiString GetByRank(int Rank);
    // As competitors complete the run they are placed in rank order. Rank 1
    // corresponds to quickest recorded time, rank 2 to second quickest, etc.
    // Two competitors with the same time may be ranked in either order.
    // The method returns the identification number of the competitor with
    // rank given by the parameter, or the string "No such rank.".
    bool SetTime(AnsiString Number, int Hrs, int Mins, int Secs);
    // Records the time for competitor with this identification number.
    // If there is no such competitor false is returned. Otherwise true
    // is returned and the time, given by the parameters, is recorded.
    }

    I'm looking at it as a mission impossible Any pointers on an approach? i have got :

    class MarClass
    {
    public: void initialse()
    {
    int IdNumber;
    AnsiString nameOfComp;
    numberComp = ReadIntPr “Enter the number of competitors: “
    cin>>n;
    for (I = 1; I<=n; I++)
    {
    nameOfComp = ReadStringPr “Enter the name”;
    cin>>nameOfComp [Index];
    IdNumber = ReadIntPr “Enter the ID number of competitors: “
    cin>> IdNumber [Index];
    }
    }


    AnsiString getName( number)
    {

    for ( I=1; I<=n; I++)
    {
    if ( number == IdNumber[I])
    return name[I];

    else
    cout<< ”No such competitor”;
    }
    }





    Its too mixed up :S

  2. #2
    Hexus.net Troll Dougal's Avatar
    Join Date
    Jun 2005
    Location
    In your eyeball.
    Posts
    2,750
    Thanks
    0
    Thanked
    0 times in 0 posts
    Lets go through this step by step.

    With a class in C++ your private section can only be accessed by the class or polmorphic (don't worry you'll get to this in youir course) versions of the class.

    Now I won't give you the entire answer, just hints.

    For you Private section you should declare your variables.

    Code:
    class MarClass
    {
    private:
    //declare your variables for name (string), ID (int) and time (double or float)
    
    public: 
    
    void initialse()
    {
    //int IdNumber; <- not needed as we'll be using the IDnumber you've declared //in private
    
    //AnsiString nameOfComp; <- same as above
    numberComp = ReadIntPr “Enter the number of competitors: “
    cin>>n;
    for (I = 1; I<=n; I++)
    {
    nameOfComp = ReadStringPr “Enter the name”;
    cin>>nameOfComp [Index];
    IdNumber = ReadIntPr “Enter the ID number of competitors: “
    cin>> IdNumber [Index];
    }
    }
    This doesn't look like C++ at all, When you have spotted your mistakes I'll give you hints on the rest, check you assignment, for loops and display strings
    Quote Originally Posted by Errr...me
    I MSN offline people
    6014 3DMk 05

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    Thanks
    0
    Thanked
    0 times in 0 posts
    ive got:

    Class MarClass
    {
    private: // declare variables
    AnsiString compName;
    int idNumber;
    float timeTaken;

    public:
    void intialise ();
    {
    numberComp = ReadIntPr “Enter the number of competitors: “;
    idNumber = ReadIntPr “Enter the ID number of competitors: “;
    timeTaken = “no entry”
    }

    AnsiString GetName(AnsiString Number);

    that cleared things up a little!!
    thanks

  4. #4
    Hexus.net Troll Dougal's Avatar
    Join Date
    Jun 2005
    Location
    In your eyeball.
    Posts
    2,750
    Thanks
    0
    Thanked
    0 times in 0 posts
    Looks like you're using an API, not standard ANSII C++.

    So the way I'm used to using it will be different to yours.

    Which course are you doing?
    Quote Originally Posted by Errr...me
    I MSN offline people
    6014 3DMk 05

  5. #5
    Senior Member
    Join Date
    Jan 2005
    Location
    Manchester
    Posts
    2,899
    Thanks
    67
    Thanked
    180 times in 135 posts
    • Butcher's system
      • Motherboard:
      • MSI Z97 Gaming 3
      • CPU:
      • i7-4790K
      • Memory:
      • 8 GB Corsair 1866 MHz
      • Storage:
      • 120GB SSD, 240GB SSD, 2TB HDD
      • Graphics card(s):
      • MSI GTX 970
      • PSU:
      • Antec 650W
      • Case:
      • Big Black Cube!
      • Operating System:
      • Windows 7
    Quote Originally Posted by Dougal
    With a class in C++ your private section can only be accessed by the class or polmorphic (don't worry you'll get to this in youir course) versions of the class.
    That's protected - private data/functions are only accessable by the current class.

  6. #6
    Hexus.net Troll Dougal's Avatar
    Join Date
    Jun 2005
    Location
    In your eyeball.
    Posts
    2,750
    Thanks
    0
    Thanked
    0 times in 0 posts
    My bad. I hate typing code and not seeing it in an IDE. Throws me off a tadge.
    Quote Originally Posted by Errr...me
    I MSN offline people
    6014 3DMk 05

  7. #7
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    Thanks
    0
    Thanked
    0 times in 0 posts
    Hi well thanks everyone

    Jas

  8. #8
    Hexus.net Troll Dougal's Avatar
    Join Date
    Jun 2005
    Location
    In your eyeball.
    Posts
    2,750
    Thanks
    0
    Thanked
    0 times in 0 posts
    If you want to I can give you some help outside of Hexus, I'm about to start helping some of my classmates revise for retakes.
    Quote Originally Posted by Errr...me
    I MSN offline people
    6014 3DMk 05

  9. #9
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    Thanks
    0
    Thanked
    0 times in 0 posts
    Hi, if thats possible? i wud like the extra help?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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