商店销售某一件商品,每天公布统一的折扣(discount)。同时允许销售人员在销售时灵活掌握售价(price),在此

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了商店销售某一件商品,每天公布统一的折扣(discount)。同时允许销售人员在销售时灵活掌握售价(price),在此相关的知识,希望对你有一定的参考价值。

用C++
商店销售某一件商品,每天公布统一的折扣(discount)。同时允许销售人员在销售时灵活掌握售价(price),在此基础上对一次购10件者还可以享受9.8折优惠。现已知当天3名销售人员的销售情况为:
销售员号(num) 销售件数(quantity) 销售单价(price)
101 5 23.5
102 12 24.56
103 100 21.5
请编程序计算出当日此商品的总销售款sum,以及每件商品的平均售价。要求用静态数据成员和静态成员函数。
提示:将折扣、总销售款和商品的总件数声明为静态数据成员,再定义静态成员函数average(求平均售价)和display(输出结果)。

参考技术A #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:上述答案不正确,我运行过了,以上答案是我修改过的,保证正确啊
参考技术B #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;
参考技术C #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;
参考技术D #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;

第5个回答  2010-11-15 #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();
本回答被提问者和网友采纳

LeetCode:Database 103.周内每天的销售情况

要求:写一个SQL语句,报告 周内每天 每个商品类别下订购了多少单位,返回结果表单 按商品类别排序 。

你是企业主,想要获得分类商品和周内每天的销售报告。

表:Orders的结构

+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| order_id      | int     |
| customer_id   | int     |
| order_date    | date    | 
| item_id       | varchar |
| quantity      | int     |
+---------------+---------+
(order_id, item_id) 是该表主键
该表包含了订单信息
order_date 是id为 item_id 的商品被id为 customer_id 的消费者订购的日期

表:Items的结构

+---------------------+---------+
| Column Name         | Type    |
+---------------------+---------+
| item_id             | varchar |
| item_name           | varchar |
| item_category       | varchar |
+---------------------+---------+
item_id 是该表主键
item_name 是商品的名字
item_category 是商品的类别

Orders 表:

+------------+--------------+-------------+--------------+-------------+
| order_id   | customer_id  | order_date  | item_id      | quantity    |
+------------+--------------+-------------+--------------+-------------+
| 1          | 1            | 2020-06-01  | 1            | 10          |
| 2          | 1            | 2020-06-08  | 2            | 10          |
| 3          | 2            | 2020-06-02  | 1            | 5           |
| 4          | 3            | 2020-06-03  | 3            | 5           |
| 5          | 4            | 2020-06-04  | 4            | 1           |
| 6          | 4            | 2020-06-05  | 5            | 5           |
| 7          | 5            | 2020-06-05  | 1            | 10          |
| 8          | 5            | 2020-06-14  | 4            | 5           |
| 9          | 5            | 2020-06-21  | 3            | 5           |
+------------+--------------+-------------+--------------+-------------+

Items 表:

+------------+----------------+---------------+
| item_id    | item_name      | item_category |
+------------+----------------+---------------+
| 1          | LC Alg. Book   | Book          |
| 2          | LC DB. Book    | Book          |
| 3          | LC SmarthPhone | Phone         |
| 4          | LC Phone 2020  | Phone         |
| 5          | LC SmartGlass  | Glasses       |
| 6          | LC T-Shirt XL  | T-Shirt       |
+------------+----------------+---------------+

Result Table:

+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
| Category   | Monday    | Tuesday   | Wednesday | Thursday  | Friday    | Saturday  | Sunday    |
+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
| Book       | 20        | 5         | 0         | 0         | 10        | 0         | 0         |
| Glasses    | 0         | 0         | 0         | 0         | 5         | 0         | 0         |
| Phone      | 0         | 0         | 5         | 1         | 0         | 0         | 10        |
| T-Shirt    | 0         | 0         | 0         | 0         | 0         | 0         | 0         |
+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
在周一(2020-06-01, 2020-06-08),Book分类(ids: 1, 2)下,总共销售了20个单位(10 + 10)
在周二(2020-06-02),Book分类(ids: 1, 2)下,总共销售了5个单位
在周三(2020-06-03),Phone分类(ids: 3, 4)下,总共销售了5个单位
在周四(2020-06-04),Phone分类(ids: 3, 4)下,总共销售了1个单位
在周五(2020-06-05),Book分类(ids: 1, 2)下,总共销售了10个单位,Glasses分类(ids: 5)下,总共销售了5个单位
在周六, 没有商品销售
在周天(2020-06-14, 2020-06-21),Phone分类(ids: 3, 4)下,总共销售了10个单位(5 + 5)
没有销售 T-Shirt 类别的商品

SQL语句:

with c as(
select a.order_id as o1,a.customer_id as c1,dayofweek(a.order_date) as d1,a.item_id as i1,a.quantity as q1,b.item_category as ic1 
from orders a
right join items b
on a.item_id=b.item_id)

select ic1 as Category,
sum(case when d1=2 then q1 else 0 end) as Monday,
sum(case when d1=3 then q1 else 0 end) as Tuesday,
sum(case when d1=4 then q1 else 0 end) as Wednesday,
sum(case when d1=5 then q1 else 0 end) as Thursday,
sum(case when d1=6 then q1 else 0 end) as Friday,
sum(case when d1=7 then q1 else 0 end) as Saturday,
sum(case when d1=1 then q1 else 0 end) as Sunday
from c
group by ic1
order by Category;

以上是关于商店销售某一件商品,每天公布统一的折扣(discount)。同时允许销售人员在销售时灵活掌握售价(price),在此的主要内容,如果未能解决你的问题,请参考以下文章

每日一题1475. 商品折扣后的最终价格

c语言 商品管理系统

LeetCode 1475. 商品折扣后的最终价格 / 687. 最长同值路径 / 652. 寻找重复的子树

LeetCode 1475. 商品折扣后的最终价格 / 687. 最长同值路径 / 652. 寻找重复的子树

以下信息,,用T-SQL语言创建表

用matlab编写程序3个题目,求解答,越详细越好,急啊,谢谢了!