Here is what I got so far
also can anyone help me align the output
#include <iostream>
#include <iomanip>
using namespace std;
class Person
{
private:
string name;
public:
Person()
{
name = "";
}
Person(string name)
{
this->name = name;
}
string getName()
{
return name;
}
void setName(string name)
{
this-> name = name;
}
};
class Publication
{
private:
int pubNumber;
string title;
Person borrower;
public:
static int count;
Publication()
{
title = "";
}
Publication(string title)
{
this-> title = title;
count++;
pubNumber = count; // Generate pub number from static variable count
}
Person getBorrower()
{
return borrower;
}
void setBorrower(Person p)
{
borrower = p;
}
void display()
{
cout << "\n" << pubNumber << setw(25) << title << setw(25) << borrower.getName() << endl;
}
};
int Publication::count = 0; // static variable
int main(){
Person p1("Lady Gaga");
Person p2("Albert Einstein");
Person p3("Muhammad Ali");
Publication pub1("War and Peace");
pub1.setBorrower(p1);
Publication pub2("Object-Oriented Programming");
pub2.setBorrower(p2);
Publication pub3("Grapes of Wrath");
pub3.setBorrower(p3);
cout << "\nPublication Number\tTittle\t\t\tBorrower Name";
cout << "\n-------------------\t-----\t\t\t-------------";
pub1.display();
pub2.display();
pub3.display();
return 0;
}
ANSWER:
CODE:
#include<iostream>
#include <iomanip>
using namespace std;
// Base class person definition
class Person
{
// Data member to store data
string name;
public:
Person(){}
// Parameterized constructor to assign parameter value to data
member
Person(string n)
{
name = n;
}// End of parameterized constructor
// Function to set name
void setName(string n)
{
name = n;
}// End of function
// Function to return name
string getName()
{
return name;
}// End of function
};// End of class
// Class Publication derived from base class Person
class Publication : public Person
{
// Data member to store data
private:
int pubNumber;
string title;
Person borrower;
public:
// Parameterized constructor to assign parameter value to data
member
Publication(string s, int no, Person per)
{
title = s;
pubNumber = no;
borrower = per;
}// End of parameterized constructor
// Function to return Person object
Person getBorrower()
{
return borrower;
}// End of function
// Function to set Person object
void setBorrower(Person p)
{
borrower = p;
}// End of function
// Function to display publication number, title and borrower
name
void display()
{
cout<< left << setw(25) <<pubNumber<< left
<< setw(40)<<title<< left << setw(20)
<<borrower.getName();
}// End of function
};// End of class
// Class Book derived from base class Publication
class Book : public Publication
{
// Data member to store data
private:
int pages;
// Static data member to count number of books
static int count;
public:
// Parameterized constructor to assign parameter value to data
member
Book(string title, int no, Person per, int page):Publication(title,
no, per)
{
pages = page;
// Increase the counter by one
count++;
}// End of parameterized constructor
// Function to return number of pages
int getPages()
{
return pages;
}// End of function
// Function to set number of pages
void setPages(int page)
{
pages = page;
}// End of function
// Function to return number of books
int getCount()
{
return count;
}// End of function
// Function to display book information
void display()
{
// Calls the base class display function
Publication::display();
cout<< left <<setw(15) <<pages<<endl;
}// End of function
};// End of class
// Initializes static counter for book
int Book::count = 0;
// Defines derived class Video derived from base class
Publication
class Video : public Publication
{
// Data member to store data
private:
// Static data member to count number of video
static int count;
string format;
public:
// Parameterized constructor to assign parameter value to data
member
Video(string title, int no, Person per, string
form):Publication(title, no, per)
{
format = form;
}// End of parameterized constructor
// Function to return format
string getFormat()
{
return format;
}// End of function
// Function to set format
void setFormat(string form)
{
format = form;
}// End of function
// Function to return number of video
int getCount()
{
return count;
}// End of function
// Function to display video information
void display()
{
// Calls the base class display function
Publication::display();
cout<< left <<setw(15)
<<format<<endl;
}// End of function
};// End of class
// Initializes static counter for video
int Video::count = 0;
// Defines derived class Music derived from base class
Publication
class Music : public Publication
{
// Data member to store data
private:
// Static data member to count number of books
static int count;
string genre;
public:
// Parameterized constructor to assign parameter value to data
member
Music(string title, int no, Person per, string
gen):Publication(title, no, per)
{
genre = gen;
// Increase the counter by one
count++;
}// End of parameterized constructor
// Function to return genre
string getGenre()
{
return genre;
}// End of function
// Function to set genre
void setGener(string gen)
{
genre = gen;
}// End of function
// Function to return number of music
int getCount()
{
return count;
}// End of function
// Function to display music information
void display()
{
// Calls the base class display function
Publication::display();
cout<< left <<setw(15) <<genre<<endl;
}// End of function
};// End of class
// Initializes static counter for music
int Music::count = 0;
// main function definition
int main()
{
// Creates an array of pointer for Person class using parameterized
constructor
Person *per[] = {new Person("Lady Gaga"), new Person("Albert
Einstein"),
new Person("Muhammed Ali"), new Person("Donald Trump"),
new Person("Indira Gandhi"), new Person("Diego Maradona")};
// Creates an array of pointer for Book class using
parameterized constructor
Book *pb[] = {new Book("War and Peace", 1, *per[0], 1500),
new Book("Object oriented Programming", 3, *per[1], 998),
new Book("Grapes of Wrath", 5, *per[2], 246)};
// Displays heading
cout<<"\nBooks"<<endl;
cout<< left << setw(25) <<"Publication
Number"<< left << setw(40)
<<"Title"<< left << setw(20) <<"Borrower
Name"<<left <<setw(15)
<<"Pages"<<endl;
cout<< left << setw(25)
<<"------------------"<< left << setw(40)
<<"-----"<< left << setw(20)
<<"-------------"<<left <<setw(15)
<<"-----"<<endl;
// Loops till number of Books and calls the function to display
Book information
for(int x = 0; x < pb[0]->getCount(); x++)
pb[x]->display();
// Creates an pointer for Video class using parameterized
constructor
Video *pv = new Video("Star Wars", 2, *per[3], "mp4");
// Displays heading
cout<<"\nVideos"<<endl;
cout<< left << setw(25) <<"Publication
Number"<< left << setw(40)
<<"Title"<< left << setw(20) <<"Borrower
Name"<<left <<setw(15)
<<"Format"<<endl;
cout<< left << setw(25)
<<"------------------"<< left << setw(40)
<<"-----"<< left << setw(20)
<<"-------------"<<left <<setw(15)
<<"------"<<endl;
// Calls the function to display Video information
pv->display();
// Creates an array of pointer for Music class using
parameterized constructor
Music *pm[] = {new Music("Don't Worry Be Happy", 4, *per[4],
"Popular"),
new Music("Kind of Blue", 6, *per[5], "Jazz")};
// Displays heading
cout<<"\nMusic"<<endl;
cout<< left << setw(25) <<"Publication
Number"<< left << setw(40)
<<"Title"<< left << setw(20) <<"Borrower
Name"<<left <<setw(15)
<<"Genre"<<endl;
cout<< left << setw(25)
<<"------------------"<< left << setw(40)
<<"-----"<< left << setw(20)
<<"-------------"<<left <<setw(15)
<<"-----"<<endl;
// Loops till number of videos and calls the function to display
music information
for(int x = 0; x < pm[0]->getCount(); x++)
pm[x]->display();
}// End of main function
Sample Output:
PLZZZZZZZZZZZZZ RATE THUMBSUP PLLLLLZZZZZZZZ
Here is what I got so far also can anyone help me align the output #include...
I wrote this code but there’s an issue with it : #include <iostream> #include <vector> #include <string> #include <fstream> using namespace std; class Borrower { private: string ID, name; public: Borrower() :ID("0"), name("no name yet") {} void setID(string nID); void setName(string nID); string getID(); string getName(); }; void Borrower::setID(string nID) { ID = nID; } void Borrower::setName(string nname) { name = nname; } string Borrower::getID() { return ID; } string Borrower::getName() { return name; } class Book { private: string...
Can anyone help me with my C++ assignment on structs, arrays and bubblesort? I can't seem to get my code to work. The output should have the AVEPPG from highest to lowest (sorted by bubbesort). The output of my code is messed up. Please help me, thanks. Here's the input.txt: Mary 15 10.5 Joseph 32 6.2 Jack 72 8.1 Vince 83 4.2 Elizabeth 41 7.5 The output should be: NAME UNIFORM# AVEPPG Mary 15 10.50 Jack 72 8.10 Elizabeth 41 7.50 Joseph 32 6.20 Vince 83 4.20 My Code: #include <iostream>...
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...
using the source code at the bottom of this page, use the following instructions to make the appropriate modifications to the source code. Serendipity Booksellers Software Development Project— Part 7: A Problem-Solving Exercise For this chapter’s assignment, you are to add a series of arrays to the program. For the time being, these arrays will be used to hold the data in the inventory database. The functions that allow the user to add, change, and delete books in the store’s...
HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...
I need the following code to keep the current output but also include somthing similar to this but with the correct details from the code. Truck Details: Skoda 100 Nathan Roy 150.5 3200 Details of Vehicle 1: Honda, 5 cd, owned by Peter England Details of Vehicle 2: Skoda, 100 cd, owned by Nathan Roy, 150.5 lbs load, 3200 tow --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- class Person { private String name; public Person() { name="None"; } ...
Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; //function void displaymenu1(); int main ( int argc, char** argv ) { string filename; string character; string enter; int menu1=4; char repeat; // = 'Y' / 'N'; string fname; string fName; string lname; string Lname; string number; string Number; string ch; string Displayall; string line; string search; string found; string document[1000][6]; ifstream infile; char s[1000];...
I need help with this assignment, can someone HELP ? This is the assignment: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by...
I need help modifying this code please ASAP using C++ Here is what I missed on this code below Here are the instructions Here is the code Produce correct70 pts O pts Full Marks No Marks results and statisfy requirements view longer Comments 1. Your display amount is not readable 2. I withdraw more than my balance, but I didn't see any error message description Documentations10 pts 0 pts Full Marks No Marks : comment i code and block comment...
HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...