In: Computer Science
Class object in C++ programming language description about lesson static variable example.
#include
using namespace std;
class product{
private:
static float price,total;
float qty, amount;
public:
product(const product&);
product(float = 0);
static float getprice();
static float gettotat();
static float getamount();
void setprice(float pr);
int equal();
void input();
void print();
};
float product::price=2000;
float product::total=0;
product::product(const product &qty){
this->qty=qty.qty;
this->amount=qty.amount;
total+=this->amount;
}
float product::product(float qty)
:qty(qty)
{
amount=qty*price;
total+=amount;
}
int product::equal(product other){
if(this->qty==other.qty && this->amount==other.amount)
return 1;
else
return 0;
}
float product::getamount(){
return amount;
}
float product::getprice(){
return price;
}
float product::gettotat(){
return total;
}
product::setprice(3800){
return price;
}
int main(){
product p1(2),p2(3);
p1
}