2 Replies - 168 Views - Last Post: 12 May 2013 - 07:39 PM Rate Topic: -----

#1 gundamexia450  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-April 13

The element of the array as parameter

Posted 12 May 2013 - 06:37 PM

void findyear(BookCollection arr2[], int n, int searchyear)
{
    //Input:The array and the year and the element of the array
    //Process:To search the year
    //Output:To print that element info
    for(int i=0; i<n; i++)
    {
        if(arr2[i].Publisher.Year==searchyear)
        {
            printone(arr2, i);
            return;
        }
    }
    cout << "Not found." << endl;
    return;
}
void printone(BookCollection Bookfound[], int i)
{
    cout << Bookfound[i].BookTitle;
    cout << Bookfound[i].Name.First << '\t' << Bookfound[i].Name.Last;
    cout << Bookfound[i].Category;
    cout << Bookfound[i].Publisher.Company << '\t' << Bookfound[i].Publisher.Year << endl;
    return;
}

The findxxx function will receive three parameters: the array of objects, n (number of filled positions in the array), and the value to search for. The search function will first print the item to search for and then search for the item. Each time the item is found, it will call printone, to print all of the information for the object in the array that matches the search value. For example, if I have the function findyear and I search for the year 2011, I would call printone to print the title, author, category and publisher info for each book that was published in the year 2011. The only parameter sent to printone is the single element in the array that matches the year, for example mybook[0]. If the search item is not found in the array, the function should print “not found”.
DATA: Your array should allow for up to 25 items. To test the program, have a set with at least 5 items. Make sure that at least 2 items contain the value you are searching for. For example, if you are searching for the year 2011, be sure to have at least 2 books published in 2011
I don't know how to get the element of the array as the parameter

This post has been edited by modi123_1: 12 May 2013 - 06:42 PM
Reason for edit:: code tags - use 'em.


Is This A Good Question/Topic? 0
  • +

Replies To: The element of the array as parameter

#2 Skyla Blue  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 01-May 13

Re: The element of the array as parameter

Posted 12 May 2013 - 07:10 PM

Do you have a problem? If so, please state what it is.
Was This Post Helpful? 0
  • +
  • -

#3 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1343
  • View blog
  • Posts: 4,606
  • Joined: 19-February 09

Re: The element of the array as parameter

Posted 12 May 2013 - 07:39 PM

The array is an array of datatype BookCollection.

17	void printone(BookCollection Bookfound[], int i)




So one element is of datatype BookCollection.

17	void printone(BookCollection Bookfound)




A slight misnaming as an array of type Book is clearer.

// one hundred books
Book bookcollection[100];


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1