fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class Product{
  4. int id;
  5. string name;
  6. int price;
  7. int quantity;
  8. friend void newbranch_stock(Product ,int);
  9. public:
  10. Product(int price,int quantity,string name){
  11. id=rand();
  12. this->price=price;
  13. this->quantity=quantity;
  14. this->name=name;
  15. }
  16. ~Product(){
  17.  
  18. }
  19. Product(const Product &S){
  20. id=S.id;
  21. name=S.name;
  22. price=S.price;
  23. }
  24. int total_value(int quentity){
  25. return quentity*price;
  26. }
  27. void Display(){
  28. cout<<"Product id :"<<id<<endl;
  29. cout<<"Product name :"<<name<<endl;
  30. cout<<"Product price :"<<price<<endl;
  31. cout<<"Product quentity: "<<quantity<<endl;
  32.  
  33.  
  34. }
  35.  
  36. };
  37. void newbranch_stock(Product P,int quantityyyy){
  38. Product A(P);
  39. // cout<<"amount : "<<A.total_value<<endl;
  40. A.quantity=quantityyyy;
  41. A.Display();
  42.  
  43.  
  44. }
  45. int main()
  46. { Product A(25,100,"pran");
  47. Product B(35,150,"MOJO");
  48. cout<<"quantity for new brance :";
  49. int q;
  50. cin>>q;
  51. A.Display();
  52. cout<<endl;
  53. B.Display();
  54. cout<<endl;
  55. newbranch_stock(A,q);
  56. cout<<endl;
  57. newbranch_stock(B,q);
  58. }
  59.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
quantity for new brance :Product id :1804289383
Product name :pran
Product price :25
Product quentity: 100

Product id :846930886
Product name :MOJO
Product price :35
Product quentity: 150

Product id :1804289383
Product name :pran
Product price :25
Product quentity: 5237

Product id :846930886
Product name :MOJO
Product price :35
Product quentity: 5237