Please help me in this data structures question,, Write a program with structures which contains

+1 vote
asked Apr 3, 2018 by annonymus
Write a program with structures which contains information found in a library’s card catalog. It should contain the author name, the publishing year (in form of: yyyy), the company name, and status. Use functions to fill and display the books enrolled in the structures. Assume that there are 10 books in the library. in the status part if the book publishing year is before 1985 the program should indicate that this book is a reference otherwise it will show it available to borrow. The first 3 variables (author, publishing year and company) will be entered by user and the last variable (status) is filled by the program according to publishing year.

1 Answer

0 votes
answered May 22, 2018 by muha
/******************************************************************************

*******************************************************************************/

#include <iostream>

using namespace std;

struct Library

{

  char aname[20];

  char cname[20];

  int pyear;

}books[10];

int input (Library *);

void output (Library *, int);

int main ()

{

  int entries, Menu;

  do

    {

      

      

      

      cout << "\nChoose an option: " << endl;

      cout << "********************" << endl;

      cout << "**** 1 = input  ****" << endl;

      cout << "**** 2 = output ****" << endl;

      cout << "**** 3 = end    ****" << endl;

      cout << "********************";

      cin >> Menu;

      switch (Menu)

{

case 1:

  entries = input(books);

  break;

case 2:

  output (books, entries);

  break;

case 3:

  cout << "The End";

  break;

default:

  cout << "Error not a valid option!";

  break;

}

    }

  while (Menu != 3);

  return 0;

}

int input (Library * zbooks)

{

    int zentries;

    cout << "How many entries do you want to make? ";

    cin >> zentries;

    

  for (int x = 0; x < zentries; x++)

    {

      cout << "\nBook nr. " << x + 1 << ": " << endl;

      cout << "Enter the name of the author: ";

      cin >> books[x].aname;

      cout << "Enter the name of the company: ";

      cin >> books[x].cname;

      cout << "Enter the publishing year of the book: ";

      cin >> books[x].pyear;

    }

    return zentries;

}

void output (Library * zbooks, int zentries)

{

  for (int x = 0; x < zentries; x++)

    {

      cout << "\nBook nr. " << x + 1 << ": ";

      cout << books[x].aname << endl;

      cout << books[x].cname << endl;

      cout << books[x].pyear << endl;

      if (books[x].pyear < 1985)

{

  cout << "This book is a reference!" << endl;

}

      else

{

  cout << "This book is available for borrow!" << endl;

}

    }

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...