Answer to Question #238574 in C++ for Asim

Question #238574
Write a program that declares a structure to store book Id, price and pages of a book.
The structure should include functions to assign user defined values to each book and
display the record of most costly book.
1
Expert's answer
2021-09-17T17:16:04-0400
#include <iostream>


using namespace std;


struct Bid {
public:
	Bid(int id, float price, short int pages) { // constructor
		this->id = id;
		this->price = price;
		this->pages = pages;
	}
	int Get_id() {	return id;  } //it shows you the id of the book
	float Get_price() { return price; }
	short int Get_pages() { return pages; }
	void Set_id(int id) { this->id = id; } //it sets the id of the book
	void Set_price(float price) { this->price = price; }
	void Set_pages(short int pages) { this->pages = pages; }


	float Get_themostcostly(Bid book) {
		return book.Get_price() > price ? book.Get_price() : price;
	}
private:
	int id;
	float price;
	short int pages;


};


int main() {
	Bid B1(0, 10, 500), B2(1, 15, 1000); //B1(id of the book, price of the book, pages of the book);
	cout << B1.Get_themostcostly(B2) << endl; //compares the price of the objects(in our case the books) B1 and B2
	cout << B1.Get_id() << endl;
	cout << B1.Get_pages() << endl;
	cout << B1.Get_price() << endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS