首页 > 编程语言 > 详细

C++课程设计类作业4

时间:2017-06-14 01:04:22      阅读:265      评论:0      收藏:0      [点我收藏+]
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 class xiexin
 4 {
 5 public:
 6     xiexin()
 7     {
 8         weight=0;
 9         grade=0;
10         cout<<"weight="<<weight<<",grade="<<grade<<endl;
11     }
12     xiexin(int w,int g)
13     {
14         weight=w;
15         grade=g;
16         cout<<"weight="<<weight<<",grade="<<grade<<endl;
17     }
18     ~xiexin()
19     {
20         cout<<"Destructor......\n";
21     }
22     void setvalue(int w=100,int g=40)
23     {
24         weight=w;
25         grade=g;
26         cout<<"weight="<<weight<<",grade="<<grade<<endl;
27     }
28     static int calculate(xiexin obj)
29     {
30         return obj.weight*obj.grade;
31     }
32     friend void display(xiexin obj);
33 private:
34     int weight;
35     int grade;
36     static int cnt;
37 };
38 int xiexin::cnt=0;
39 void display(xiexin obj)
40 {
41     cout<<"weight="<<obj.weight<<",grade="<<obj.grade<<",total="<<xiexin::calculate(obj)<<endl;
42 }
43 int main()
44 {
45     xiexin boxl;
46     display(boxl);
47     xiexin box2(5,10);
48     display(box2);
49     box2.setvalue(20,18);
50     display(box2);
51 }

如果函数中有多条语句的话,会先执行完这些语句,直到函数结束再析构

技术分享

C++课程设计类作业4

原文:http://www.cnblogs.com/ECJTUACM-873284962/p/7004484.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!