GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Mar-2005, 19:04
leanieleanz leanieleanz is offline
New Member
 
Join Date: Mar 2005
Posts: 10
leanieleanz is on a distinguished road
Unhappy

Identifier not found - quick help


I am trying to get the code to work for the following homework assignment:

Write a function, removeAll, that takes three parameters: an array of integers, the length of the array, and an integer (say, removeItem). The function should find and delete all the occurrences of removeItem in the array. If the vlaue does not exist or the array is empty, output an appropriate message. (Note that after deleting the element, the array size is reduced.) Assume that the array is unsorted.

I tried my best and have the following code. I am getting an identifier not found for seqSearch and a few other problems. Any help is appreciated. C++ is going to drive me crazy!!!

CPP / C++ / C Code:
 
//**************************
// Lena Esho
// CIS217A - Tuesday Night
// Week Five Homework
// Chapter 10 Exercise 5
//**************************
#include <iostream>
#include <iomanip>

using namespace std;

void RemoveAll (int array[],   			// array from which all copies of item are to be removed 
                int & length, 			// current size of array (will possibly be decremented)
                int removeItem)	// item to be removed
     {
          int targetLoc;  // subscript where item to be removed is located
		  int n;

          if (length == 0)
          {
                cout << "Array is empty; no action taken" << endl;
                return;
          }

          // call the sequential search function (from the book or my optimized version)
          // or you could reproduce that logic here 

          targetLoc = seqSearch(array, length, removeItem);

          if (targetLoc == -1)   // item to be removed was not found in the array
          {
                cout << "Item to be removed is not found in the array; no action taken"
                        << endl; 
                return;
          }
          else  // we found the item to be removed
          {
                while (targetLoc != -1)
                {
                 // we can’t leave an empty element when we remove the item, so we need to
                 // shift all the element values below it back one position in the array to fill up 
                 // the vacated position and leave the newly empty element at the end

                     for (n = targetLoc + 1; n < length; n++)
                           array[n – 1] = array[n];
                     length --;

                // Search again to see if there’s another copy of item to be removed
                targetLoc = SeqSearch (array, length, removeItem);
                }
     } 
Last edited by LuciWiz : 05-Mar-2005 at 07:30. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #2  
Old 04-Mar-2005, 19:39
machinated machinated is offline
Regular Member
 
Join Date: Mar 2004
Location: victoria, canada
Posts: 324
machinated has a spectacular aura aboutmachinated has a spectacular aura about
fix your seqSearch spellings. some places it's seqSearch, other places it's SeqSearch.
__________________
spasms!!!
  #3  
Old 04-Mar-2005, 19:43
leanieleanz leanieleanz is offline
New Member
 
Join Date: Mar 2005
Posts: 10
leanieleanz is on a distinguished road

Sequential Search


Quote:
Originally Posted by machinated
plz post the entire program including the sequential search.

Thats actually all I did =\
  #4  
Old 04-Mar-2005, 20:13
machinated machinated is offline
Regular Member
 
Join Date: Mar 2004
Location: victoria, canada
Posts: 324
machinated has a spectacular aura aboutmachinated has a spectacular aura about
Quote:
Originally Posted by leanieleanz
Thats actually all I did =\
you've only posted a single function, no main or seqSearch def. either way, did you try fixing the spellings yet?
__________________
spasms!!!
  #5  
Old 04-Mar-2005, 20:16
leanieleanz leanieleanz is offline
New Member
 
Join Date: Mar 2005
Posts: 10
leanieleanz is on a distinguished road
Quote:
Originally Posted by machinated
you've only posted a single function, no main or seqSearch def. either way, did you try fixing the spellings yet?

If you read my first post the question only wants you to write a function, so I did the best I could. I don't know what else I need to do. I don't see any spelling errors. I have 3 other classes I am studying for (finals) and my brain is boggled.

Sorry if I sound stupid I am
  #6  
Old 04-Mar-2005, 20:22
machinated machinated is offline
Regular Member
 
Join Date: Mar 2004
Location: victoria, canada
Posts: 324
machinated has a spectacular aura aboutmachinated has a spectacular aura about
ok sorry. but seqSearch spellings are different in two places
in one it's seqSearch and in other it's SeqSearch. Thats probably your problem.
__________________
spasms!!!
  #7  
Old 05-Mar-2005, 07:47
leanieleanz leanieleanz is offline
New Member
 
Join Date: Mar 2005
Posts: 10
leanieleanz is on a distinguished road
Quote:
Originally Posted by machinated
ok sorry. but seqSearch spellings are different in two places
in one it's seqSearch and in other it's SeqSearch. Thats probably your problem.

I think I have fixed the problem in the function. Now I need to create a main function to test it. Can anyone help me start it. Sorry I am a beginner! :-?

CPP / C++ / C Code:
//**************************
// Lena Esho
// CIS217A - Tuesday Night
// Week Five Homework
// Chapter 10 Exercise 5
//**************************
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{


void RemoveAll (int array[], int & length, int removeItem)
{
	int SeqSearch(const int array[], int length, int removeItem);
	int targetLoc;  // subscript where item to be removed is located
	int n;

    if (length == 0)
    {
		cout << "Array is empty; no action taken" << endl;
        return;
    }

    // call the sequential search function (from the book or my optimized version)
    // or you could reproduce that logic here 

    targetLoc = SeqSearch(array, length, removeItem);

    if (targetLoc == -1)   // item to be removed was not found in the array
    {
		cout << "Item to be removed is not found in the array; no action taken"
             << endl; 
        return;
    }
    else  // we found the item to be removed
    {
		while (targetLoc != -1)
		{
    //shift all the element values below it back one position in the array
	//to fill up vacated position and leave the newly empty element at the end

              for (n = targetLoc++; n < length; n++)
				   array[n--] = array[n];
                   length --;

                // Search again to see if there’s another copy of item to be removed
				   targetLoc = SeqSearch (array, length, removeItem);
        }
     }
}
Last edited by JdS : 05-Mar-2005 at 08:06. Reason: please insert your example C codes between [c] and [/c] bbcode tags
  #8  
Old 05-Mar-2005, 10:00
leanieleanz leanieleanz is offline
New Member
 
Join Date: Mar 2005
Posts: 10
leanieleanz is on a distinguished road

Nevermind


Nevermind I figured it out. Thanks to nobody but me!
  #9  
Old 05-Mar-2005, 10:04
machinated machinated is offline
Regular Member
 
Join Date: Mar 2004
Location: victoria, canada
Posts: 324
machinated has a spectacular aura aboutmachinated has a spectacular aura about
you might want to take out the entire RemoveAll function and place it above main and then call it from main. also your main needs to return 0 before terminating. make sure SeqSearch function definition is also located not only above the main but also above RemoveAll function definition. example:
CPP / C++ / C Code:
int SeqSearch(/*parameters*/)
{
//code goes here
}

void RemoveAll(/*parameters*/)
{
//code goes here
}

int main(void)
{
/*declare arrays and other variables*/
RemoveAll(/*pass parameters*/);
/*other code if need be*/
return 0;
}
__________________
spasms!!!
  #10  
Old 05-Mar-2005, 10:06
leanieleanz leanieleanz is offline
New Member
 
Join Date: Mar 2005
Posts: 10
leanieleanz is on a distinguished road
[quote=machinated]you might want to take out the entire RemoveAll function and place it above main and then call it from main. also your main needs to return 0 before terminating. make sure SeqSearch function definition is also located not only above the main but also above RemoveAll function definition.

Thank you so much for your input! I appreciate it very much. However, I figured it out. Thanks again =)
 
 

Recent GIDBlogMeeting the local Iraqis by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fraction program SpudNuts C++ Forum 6 25-Sep-2006 03:50
Can enum have same name as class? crystalattice C++ Forum 3 08-Dec-2004 16:43
Help! undeclared identifier error wfillis .NET Forum 8 25-Aug-2004 06:03
Dummie needs help - URL not found Lrosewitz Apache Web Server Forum 1 28-May-2004 14:32
Kernel panic: No init found JdS Computer Software Forum - Linux 9 04-Dec-2003 01:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:46.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.