C++ Double Question :
1ST.
The printAllBooks function from Homework 5 was very useful, let’s do it again, but with an array of Book this time! Write a new printAllBooksfunction which will be useful to display the contents of your library. This function should:
Accept two parameters in this order:
array books: array of Book objects.
int: number of books in the array (Note: this value might be less than the capacity of 50 books)
This function does not return anything
If the number of books is 0 or less than , print “No books are stored”
Otherwise, print “Here is a list of books” and then each book in a new line using the following statement
cout << books[i].getTitle() << " by ";
cout << books[i].getAuthor() << endl;
In the Answer Box below, paste your Book class (both the header and implementation), and your printAllBooks function, not the entire driver program you are using to test your printAllBooks function. As in the previous problems, do not include all the extra headers and #ifndef/#define.
2ND :
As we have seen in homework5 that some users want to know if there are books by their favorite author. Instead of printing all books, we will print the list of books that are written by the given author. So let’s write a function printBooksByAuthor that fulfills the following criteria
Your function should be named printBooksByAuthor
Your function should take three parameters in the following order:
Array of book objects: books
int: number of books (Note: this value might be less than the capacity of 50 books array)
string: author name
You function should not return anything.
If the number of books is 0 or less than 0, print “No books are stored”
If there are no books by the author then you should print the following, “There are no books by <author>”
If there are one or multiple books by the same author, you should print the following statement, “Here is a list of books by <author>” followed by, each book’s title by this author in a new line.
Note: In the test case, you can always assume that the number of books matches the number of elements in the books array.
Example: There are two books by Author A.
|
Function Call: |
Book book1 = Book("Book 1", "Author A"); Book book2 = Book("Book 2", "Author B"); Book book3 = Book("Book 3", "Author A"); Book listOfBooks[] = {book1, book2, book3}; int numberOfBooks = 3; string author = "Author A"; printBooksByAuthor(listOfBooks, numberOfBooks, author); |
|
Expected Output: |
Here is a list of books by Author A Book 1 Book 3 |
In the Answer Box below, paste your Book class (both the header and implementation), and your printBooksByAuthor function, not the entire driver program you are using to test your printBooksByAuthor function. As in the previous problems, do not include all the extra headers and #ifndef/#define.
void printBooksByAuthor(Book [] listOfBooks, int numberOfBooks, string author) {
bool flag = false;
if(numberOfBooks == 0)
cout <<"No books are stored" <<endl;
else {
for(int i =0 ; i<numberOfBooks ; ++i) {
if(listOfBooks[i].getAuthor() == author ){
if(!flag )
cout << "Here is a list of books by "<<
author<<endl;
cout << listOfBooks[i].getTitle() << endl;
flag = true;
}
}
if(!flag ) {
cout << "There are no books by " <<
author<<endl;
}
}
}
Thanks, PLEASE COMMENT if there is any concern.
C++ Double Question : 1ST. The printAllBooks function from Homework 5 was very useful, let’s do...
C++
In this homework, you will implement a single linked list to store a list of computer science textbooks. Every book has a title, author, and an ISBN number. You will create 2 classes: Textbook and Library. Textbook class should have all above attributes and also a "next" pointer. Textbook Туре String String String Attribute title author ISBN Textbook* next Library class should have a head node as an attribute to keep the list of the books. Also, following member...
please Code in c++ Create a new Library class. You will need both a header file and a source file for this class. The class will contain two data members: an array of Book objects the current number of books in the array Since the book array is moving from the main.cc file, you will also move the constant array size definition (MAX_ARR_SIZE) into the Library header file. Write the following functions for the Library class: a constructor that initializes...
Part 1 The purpose of this part of the assignment is to give you practice in creating a class. You will develop a program that creates a class for a book. The main program will simply test this class. The class will have the following data members: A string for the name of the author A string for the book title A long integer for the ISBN The class will have the following member functions (details about each one are...
c++ /*This is the starter file for your final proficiency test This program has a function that will generate a list of integers using the rand function. Your job is to fill the insertNum and oddCount functions.*/ #include <iostream> #include <ctime> using namespace std; //constants and function prototypes const int CAP = 100; int buildList(int[], int size); void printList(int[], int size); //your functions to implement /*This function finds even numbers in the list, and inserts a number before the even...
Using C++ Skills Required Create and use classes Exception Handling, Read and write files, work vectors. Create Functions, include headers and other files, Loops(while, for), conditional(if, switch), datatypes, etc. Assignment You work at the computer science library, and your boss just bought a bunch of new books for the library! All of the new books need to be cataloged and sorted back on the shelf. You don’t need to keep track of which customer has the book or not, just whether...
How to write the insert, search, and remove functions for this hash table program? I'm stuck... This program is written in C++ Hash Tables Hash Table Header File Copy and paste the following code into a header file named HashTable.h Please do not alter this file in any way or you may not receive credit for this lab For this lab, you will implement each of the hash table functions whose prototypes are in HashTable.h. Write these functions in a...
in C++ and also each function has its own main function so
please do the main function as well. Previously when i asked the
question the person only did the function and didn't do the main
function so please help me do it.
1-1. Write a function that returns the sum of all elements in an int array. The parameters of the function are the array and the number of elements in the array. The function should return 0 if...
A library maintains a collection of books. Books can be added to
and deleted from and checked out and checked in to this
collection.
Title and author name identify a book. Each book object
maintains a count of the number of copies available and the number
of copies checked out. The number of copies must always be greater
than or equal to zero. If the number of copies for a book goes to
zero, it must be deleted from the...
IN c++ i post this question 5 times. hope this time somebody answer.. 16.5 Homework 5 OVERVIEW This homework builds on Hw4(given in bottom) We will modify the classes to do a few new things We will add copy constructors to the Antique and Merchant classes. We will overload the == operator for Antique and Merchant classes. We will overload the + operator for the antique class. We will add a new class the "MerchantGuild." Please use the provided templates...
C++ programing
1. [10pts] Assume you are adding a new method to the CoolString class called reverse(). Assume its signature is the following in the header file: #ifndef COOL_STRING_H #define COOL_STRING_H #include <iostream> class CoolString //ASSUME ALL OTHER METHODS AND VARIABLES ARE STILL HERE BUT //OMITTED FOR SPACE SAKE void reverse(); Fendif Reverse will reverse the order of values in the characters array (e.g. if the CoolString contained CAT,S then after a call to reverse it would contain S,T,A,C. Reverse...