Question
For an ungraded C++ lab, we have practice with structs. I'm having a hard time calling the functions relating to our book struct correctly. The
For an ungraded C++ lab, we have practice with structs. I'm having a hard time calling the functions relating to our book struct correctly. The issues lie in main(). Here is the .cpp:
#include "book.h"
void add_author(Book& book){ if (book.num_auth==3){ std::cout<<" A book can't have more than 3 authors!"; } else{ std::cout<<" Add Author: "; getline(std::cin, book.authors[book.num_auth]); book.num_auth++; } };
void remove_last(Book& book){ if(book.num_auth<=1){ std::cout<<" A book must have at least 1 author!"; } else{ book.authors[book.num_auth-1]=""; book.num_auth=book.num_auth-1; } };
std::ostream& print(std::ostream& out, Book book){ std::cout<<" Title: "< void initializeBook(Book& book){ std::cout<<" Enter the Title of the book: "; getline(std::cin, book.title); std::cout<<" Genre: "; getline(std::cin, book.genre); std::cout<<" Publisher: "; getline(std::cin, book.publisher); book.authors=new std::string[3]; std::cout<<" First Author: "; getline(std::cin, book.authors[0]); book.num_auth=1; } int main(){ Book book; //QUESTION//what would this do? std::string Book = initializeBook(book.title, book.genre, book.publisher, book.authors); //QUESTION//how do I call this function correctly? add_author(Book& book); //QUESTION//same as above remove_last(Book& book); //QUESTION//same as above return 0; }; and the .h: #ifndef __BOOK_H_INCLUDED__ #define __BOOK_H_INCLUDED__ #include struct Book{ std::string title; std::string genre; std::string publisher; int num_auth; std::string* authors; }; void add_author(Book& book); void remove_last(Book& book); std::ostream& print(std::ostream& out, Book book); void initializeBook(Book& book); #endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started