Answer to Question #228754 in C++ for Karthi

Question #228754
Create a class Product with <PID, cost, quantity> as member
variables. Create a parameterized constructor to assign default values for
quantity and cost and assign consecutive PID starting from 100. Create a copy
constructor, and a destructor, findMaxProduct()as a friend function that
takes an array of N Products as parameter and returns the product with
maximum quantity, getProduct() to read quantity and cost details,
printProduct() to print product details, as member functions. In main()
create an array of Product objects and call findMaxProduct()appropriately
and print the details of the product with maximum quantity.
1
Expert's answer
2021-08-24T01:54:06-0400
#include <iostream>
using namespace std;
class Product
{
private:
	int PID;
	int cost;
	int quantity;
public:
	//Default constrcuctor(i)
	Product()
	{
		this->PID = 0;
		this->cost = 0;
		this->quantity = 100;
	}
	//(ii) Parametrazed constructor
	Product(int _p, int _c, int _q)
	{
		this->PID = _p;
		this->cost = _c;
		this->quantity = _q;
		
	}
		product(){//constructor 
			}
		~Product(){}// destructor
    Product FindMaxProduct(const Product& a, const Product& b)
	{
		int _p = (a.PID + b.PID)/100;
		int _c = (a.cost + b.cost + (a.PID + b.PID)/100) % 100;
		int _q = (((a.cost + b.cost + (a.PID+ b.PID)/100)) / 100 + a.quantity + b.quantity) % 24;
		return Product(_p, _c, _q);
	}


	
	


	void getProduct()
	{
		cout<<"";
	}


};
int main()
{
       int p, c, q,p1,q1,c1;
		cout << "Please enter PID First product: ";
		cin >> p;
		cout << "Please enter cost First object: ";
		cin >> c;
		cout << "Please enter quantity First object: ";
		cin >> q;
		Product one(p, c, q);
		cout << "Please enter PID Second object: ";
		cin >> p1;
		cout << "Please enter cost Second object: ";
		cin >> c1;
		cout << "Please enter quantity Second object: ";
		cin >> q1;
		Product two(p1, c1,q1);
		Product th ;
 th = th.FindMaxProduct(one, two);
 th.getProduct();
 if(q>q1){
 	cout<<"maximum product id is "<<p<<" and its cost is  "<< "with the quantity of "<<q;}
else{
	cout<<"Maximum product is "<<p1<<"  and its cost is  "<<c1<< "with the quantity of  "<<q1;
 }


		//int max_Product1 = FindMaxProduct(10);
        //cout << max_Product1 << endl;
	return 0;
}

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