Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I NEED TO PROGRAM THIS IN 3 FILES HEADER.H MAIN.CPP AND THE .CPP IN C++ LANGUAGE

ID: 3827397 • Letter: I

Question

I NEED TO PROGRAM THIS IN 3 FILES HEADER.H MAIN.CPP AND THE .CPP IN C++ LANGUAGE I ONLY HAVE .H

THANKS

Contents of TextBook.h 1 #ifndef TEXTBOOK 2 #define TEXTBOOK 3 #include 4 #include 5 using namespace std; 6 7 // TextBook class 8 class TextBook { 10 private: 11 string title; // Book title 12 string author; // Author name 13 string publisher; // Publisher name 14 public: 15 // The default constructor stores empty strings 16 // in the string objects. 17 TextBook() 18 { set("", "", ""); } 19 20 // Constructor 21 TextBook(string textTitle, string auth, string pub) 22 { set(textTitle, auth, pub); } 23 24 // set function 25 void set(string textTitle, string auth, string pub) 26 { title = textTitle; 27 author = auth; 28 publisher = pub; } 29 30 // print function 31 void print() const 32 { cout << "Title: " << title << endl; 33 cout << "Author: " << author << endl; 34 cout << "Publisher: " << publisher << endl; } 35 }; 36 #endif

Explanation / Answer

#include <iostream>
using namespace std;

class TextBook
{
   private:
   string title;
   string author;
   string publisher;
  
   public:
   TextBook();
   TextBook(string textTitle, string auth, string pub);
   void set(string textTitle, string auth, string pub);
   void print();
};
TextBook::TextBook(){
   title="";
   author="";
   publisher="";
}
TextBook::TextBook(string textTitle,string auth, string pub) {
   title=textTitle;
   author=auth;
   publisher=pub;
}
void TextBook:: set(string textTitle,string auth, string pub){
       title = textTitle;
       author = auth;
       publisher = pub;
}
void TextBook::print() {
   cout << "Title: " << title << endl;
   cout << "Author: " << author << endl;
   cout << "Publisher: " << publisher << endl;
}
int main(){
   TextBook t;
  
string title, author, publisher;

cout << "Enter title:- ";
cin >> title;
cout << "Enter author:- ";
cin >> author;
cout << "Enter publisher:- ";
cin >> publisher;
  
t.set(title, author, publisher);
t.print();
return 0;
}

here i have made the same program as you have mentioned in the above question in c++

first i have declared the string variables as title, pub and author in string as private and in the public part i have declared the default constructor and the constructor with 3 arguments function set with 3 arguments and the print function.

by using the class name i have given the defination of all the constructor and functions. In the last main method just make the object of the class and entered the value of title, publisher and author by user and print then set those value to the function set and print the values by using the function print.

Thank You