优惠网 > 优惠大全 > 商店销售某一件商品,每天公布统一的折扣(discount)。同时允许销售人员在...

商店销售某一件商品,每天公布统一的折扣(discount)。同时允许销售人员在...

作者:优优 | 分类:优惠大全 | 浏览量:70
发表时间:2025-04-05 02:07:26
#include <iostream>
using namespace std;
class salesman
{
public:
salesman()
{
quantity=0;
price=0;
}
static float average();
static void display();
void total();
void set();
private:
static float discount;
static int n;
static float sum;
int quantity;
float price;
};
void salesman::set()
{
cout<< 销售件数 <<endl;
cin>>quantity;
cout<< 售货单价 <<endl;
cin>>price;

}
void salesman::total()
{
if(quantity>=10)
price=price*0.98;
sum+=quantity*price*discount;
n+=quantity;
}
float salesman::average()
{return(sum/n);}
float salesman::discount=0.9;
int salesman::n=0;
float salesman::sum=0;
void salesman::display()
{
cout<< 总销售款为 <<sum<<endl<< 平均售价为 <<salesman::average()<<endl;
}
int main()
{
salesman sal[3];
sal[0].set();
sal[0].total();
sal[1].set();
sal[1].total();
sal[2].set();
sal[2].total();
salesman::display();
return 0;
}
PS:上述答案不正确,我运行过了,以上答案是我修改过的,保证正确啊
#include<iostream.h>
class Xiao
{
public:
Xiao(int n,int q,double p):num(n),qua(q),price(p){}
void total();
static double average();
static double sum;
static int count;
static double discount;
static double zhe;
private:
int num;
int qua;
double price;

};
double Xiao::sum=0;
int Xiao::count=0;
double Xiao::discount=0.80;
double Xiao::zhe=0.98;
void Xiao::total()
{
if(qua>10) sum+=(price*zhe*qua);
else sum+=(price*qua);
count+=qua;
}
double Xiao::average()
{
return ((sum*discount)/count);
}
int main()
{
Xiao xia[3]={
Xiao(101,5,23.5),
Xiao(102,12,24.56),
Xiao(103,100,21.5)
};
for(int i=0;i<3;i++)
xia[i].total();
cout<< the sum of Xiao is : <<Xiao::sum<<endl;
cout<< the average price of Xiao is : <<Xiao::average()<<endl;
return 0;
}
#include<iostream>
using namespace std;
class Shop
{
public:
Shop(int m,int q,float p):num(m),quantity(q),price(p){};
void zongjia();
static float average();
static void display();
private:
int num;//人员号码
int quantity;//件数
float price;//单价
static float discount;//每天折扣
static float sum;//总金额
static int n;//总件数
};
void Shop::zongjia()
{
float rate=1.0;
if(quantity>10)rate=0.98*rate;
sum=sum+quantity*price*rate*(1-discount);
n=n+quantity;
}
void Shop::display()
{
cout<<sum<<endl;
cout<<average()<<endl;
}
float Shop::average()
{
return (sum/n);
}
float Shop::discount=0.05;
float Shop::sum=0;
int Shop::n=0;
int main ()
{
Shop s[3]={
Shop(101,5,23.5),
Shop(102,12,24.56),
Shop(103,100,21.5)
};
int i;
for(i=0;i<3;i++)
s[i].zongjia();
Shop::display();
return 0;
}
#include<iostream>
#include<string>
using namespace std;

class sale {
protected:
string num;//销货员号
int quantity;//销货件数
float price;//销货单价
static float discount;//折扣
static float sum;//总销售款
static int n;//销售总件数
public:
sale(string nu, int qu, float pr);
static float average();//求平均售价
static void display();//输出结果
};

sale::sale(string nu, int qu, float pr)
{
num = nu;
price = pr;
if (qu >= 10)
quantity = qu * 0.98;
else
quantity = qu;
sum += quantity * price * discount;
n += quantity;
}

float sale::discount = 0.9;
float sale::sum = 0;
int sale::n = 0;
float sale::average()
{
return sum / n;
}
void sale::display()
{
float a = average();
cout << 当日总销售额为: << n << \n << 每件商品的平均售价为: << a << endl;
}

int main()
{
sale s1( 101 , 5, 23.5);
sale s2( 102 , 12, 24.56);
sale s3( 103 , 100, 21.5);
sale::display();
return 0;

}
#include <iostream>
using namespace std;
class salesman
{
public:
salesman()
{
quantity=0;
price=0;
}
static float average();
static void display();
void total();
void set();
private:
static float discount;
static float sum;
static int n;
int quantity;
float price;
};
void salesman::set()
{
cout<< 销售件数 <<endl;
cin>>quantity;
cout<< 售货单价 <<endl;
cin>>price;
}
void salesman::total()
{
if(quantity>=10)
price=price*0.98;
sum+=quantity*price*discount;
n+=quantity;
}
float salesman::average()
{
return(sum/n);
}
float salesman::discount=0.9;
int salesman::n=0;
float salesman::sum=0;
void salesman::display()
{
cout<< 总销售款为 <<sum<<endl<< 平均售价为 <<salesman::average()<<endl;
}
int main()
{
salesman sal[3];
sal[0].set();
sal[0].total();
sal[1].set();
sal[1].total();
sal[2].set();
sal[2].total();
salesman::display();
}

粤ICP备2024332802号-3 | 优惠信息大全 | Sitemap
深圳市华诚易配电子商务有限公司 旗下网站
本站内容由AI生成或转载自网络,如有版侵,请与我们联系