1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Problem with C++ Exercise

Discussion in 'C++' started by kabom, May 24, 2010.

  1. kabom

    kabom New Member

    Joined:
    May 24, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hey guys.. Im stucked at my final exam with this exercise

    To create a class UnordArray which can store
    a number of data (integers), the new
    embedded data are placed at the end of the structure.
    Create a class described by creating appropriate
    header and implementation files, which contain
    following data:

    • buffer, which is a sequence of integers in which
    stored data.
    • numElem, which represents an integer which stores the number
    the currently inserted in the data structure.
    To define a constructor, which landed the initial
    value of data member numElem. To define
    following functions of the class members:

    • int size (), which returns the number of data
    structure.
    • void insert (int val), which inserts the data value
    val at the end of the structure.
    • boolean delete (int val), searching the structure and if
    it does not contain data with a value val, returns false; in
    Otherwise removes data with value val, January
    terminator structure, and returns true.

    • int find (int val), searching through the structure if it
    contains data with a value val, returns -1, otherwise January
    Returns the value of the index which is the value val
    structure.

    • void print (), prints the data structure in
    order from beginning to end.
    To create a file koristi.cpp, which will be demonstrated
    use of the newly created class and all UnordArray
    Its features members. When creating the class
    It is forbidden to use ready-library classes and
    functions (other than iostream).

    I Tryed 1000 times to make it work but it's always says SOMETHING MISSING!!!!:freak::freak:
    Can u give me a hand here pls? ... Maybe some 1 can wrote some part of it.. or anything ? Pls guys , let's do it :S
    Thank you
    Kabom
     
  2. bluecoder

    bluecoder New Member

    Joined:
    Mar 11, 2010
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    You say that the you have tried 1000 times but can you tell me what you have coded so far ?
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    SOMETHING MISSING doesn't look like any C error message I've ever seen.

    Post the latest version of your code (use code tags) and the error messages from the compiler and let's see what the problem is.

    What version of what compiler are you using, and what operating system?
     
  4. kabom

    kabom New Member

    Joined:
    May 24, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    class UnordArray{
          private:
          
          int buffer[100];
          int numElem;
          int i;
          
          public:
          UnordArray(int pocetna){
                 numElem = pocetna;
          }      
          
          int size(){
                return numElem;
          }
                
          void insert(int val)
          {
               if(numElem >= 100)
                          cout << "Bufferot e veke poln! Nemozete da vnesuvate veke vrednosti" << endl;
               else
               {
                   buffer[numElem++] = val;  
               }
          }
          
          bool deleteElem(int val)
          {
               bool najden = false;
               int temp;
               for(i=0;i<numElem;i++)
               {
                           if(buffer[i] == val) // elementot e najden
                           {
    							
                                        for(int j=i;j<numElem;j++)
                                        {
                                                buffer[j] = buffer[j+1];
                                        }             
                                        najden = true;
                                        numElem--;                  
                                        break;
                           }
               }
               
              return najden;
          }
          
          int find(int val)
          {
              int pozicija = -1;
              for(i=0;i<numElem;i++)
              {
                    if(buffer[i] == val)
                    {
                          pozicija = i;              
                          break;
                    }         
              }
              
              return pozicija;
          }
          
          void print()
          {
               for(i=0;i<numElem;i++)
                   cout << "index[" << i << "] = " << buffer[i] << endl;
          }          
    };
    
    int main()
    {
        
        
        UnordArray test(0);
        int n,vnes;
        
        cout << "Kolku vrednosti ke vnesuvas? (MAX 100): ";
        cin >> n;
        
        for(int i=0;i<n;i++)
        {
                cout << "Vnesi go n[" << i << "]=";
                cin >> vnes;
                test.insert(vnes);        
        }
        
        cout << "Strukturata izgleda vaka: " << endl;
        test.print();
        
        cout << "Golemina na strukturata e: ";
        cout << test.size() << endl;
        
        cout << "Vnese element za prebaruvanje: ";
        cin >> vnes;
        
        int poz = test.find(vnes);
        if(poz != -1)
             cout << "Elementot e najden na pozicija: " << poz << endl;
        else
            cout << "Elementot ne e pronajden." << endl;
            
        cout << "Vnesi element za brisenje: ";
        cin >> vnes;
        
        if(test.deleteElem(vnes))
               cout << "Elementot e uspesno izbrisan." << endl;
        else
               cout << "Ne postoi takov element." << endl;
               
        cout << "Na kraj strukturata izgleda vaka: " << endl;
        test.print();
        
        system("PAUSE");
        return 0;
    }
    
    Im done.. if u want to translate it at english u can try it ;) it's on my Language - MACEDONIAN
    see ya
     
  5. jimblumberg

    jimblumberg New Member

    Joined:
    May 30, 2010
    Messages:
    120
    Likes Received:
    29
    Trophy Points:
    0
    Im done.. if u want to translate it at english u can try it ;) it's on my Language - MACEDONIAN
    see ya[/quote]

    So does the program compile without any errors? If not what are the error messages??
     
  6. jimblumberg

    jimblumberg New Member

    Joined:
    May 30, 2010
    Messages:
    120
    Likes Received:
    29
    Trophy Points:
    0
    So does the program compile without any errors? If not what are the error messages??
     
  7. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    What errors did you get? I compiled it in Visual Studio 2008 and got no errors, just one warning about an unused variable temp.

    Tried running it but I don't speak Macedonian so haven't got a clue what it says or is supposed to do. If the problem is not that you got compile errors but that the runtime behaviour differed from what you expected, what input did you give, and what output did you expect? Remember I can't see your screen or read your mind, so I need some other way of understanding what the problem is.

    By the way you don't need to ask if you need to translate code into English. The answer is almost always going to be yes, unless by sheer chance you just happen to get someone who speaks the same language as you, but that's only likely to happen on a Macedonian-specific forum, not an international forum like Go4Expert. On international forums you can always safely assume the dominant language is English.
     

Share This Page