⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xt9-9.cpp

📁 最新版谭浩强《c++语言程序设计》所有习题的原代码
💻 CPP
字号:
#include <iostream>
using namespace std;
class Product
 {public:
   Product(int n,int q,float p):num(n),quantity(q),price(p){};
   void total();
   static float average();
   static void display();

  private:
   int num;
   int quantity;
   float price;
   static float discount;
   static float sum;
   static int n;
 };

void Product::total()
 {float rate=1.0;
  if(quantity>10) rate=0.98*rate;
  sum=sum+quantity*price*rate*(1-discount);
  n=n+quantity;
 }

void Product::display()
 {cout<<sum<<endl;
  cout<<average()<<endl;
 }

float Product::average()
 {return(sum/n);}
 
 
float Product::discount=0.05;
float Product::sum=0;
int Product::n=0;

int main()
 {
   Product Prod[3]={
     Product(101,5,23.5),Product(102,12,24.56),Product(103,100,21.5)
    };
   for(int i=0;i<3;i++)
     Prod[i].total();
   Product::display();
   return 0;
 }
 
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -