#include<iostream>
#include<string.h>
#include<iomanip>
using namespace std;
class Stock{
public:
Stock(){count++;}
Stock(int a,int b,int c,int d,int e)
{ this->num=a;
this->todaymax=b;
this->todaymin=c;
this->todaybegin=d;
this->todayend=e;
count++;
}
~Stock() {count--;}
void Assign_stack(Stock &c)
{this->num=c.num;
this->todaymax=c.todaymax;
this->todaymin=c.todaymin;
this->todaybegin=c.todaybegin;
this->todayend=c.todayend;
}
void display()
{ cout<<"交易日 "<<this->num<<" ";
cout<<"当天最高 "<<this->todaymax<<" ";
cout<<"当天最低 "<<this->todaymin<<" ";
cout<<"当天开盘 "<<this->todaybegin<<" ";
cout<<"当天收盘 "<<this->todayend<<" "<<endl;
}
void show()
{ cout<<"Now the sum of Stack is "<<count<<endl;}
friend bool cmp(Stock &c);
double increase(Stock &c)
{ double x=c.todayend-todayend;
return double(x/c.todayend);
}
private:
static int count;
int num,todaymax,todaymin,todaybegin,todayend;
};
inline bool cmp(Stock &c)
{return c.todaybegin>c.todayend;}
int Stock::count=0;
int main()
{ Stock a[5];
Stock *p;
Stock b(1,2,3,4,5);
//cout<<b.count<<endl; 注意类的私有成员在类外不能访问,,只能通过类的成员函数来访问
p->show();
b.display();
Stock c(2,3,4,5,6);
p->show();
Stock d(3,4,5,6,7);
Stock e(4,5,6,7,8);
p->show();
Stock f(5,6,7,8,9);
a[0].Assign_stack(b);
p->show();
a[1].Assign_stack(c);
a[2].Assign_stack(d);
a[3].Assign_stack(e);
a[4].Assign_stack(f);
if(!cmp(a[0])) cout<<"profit \n";
else cout<<"not profit \n";
for(int i=0;i<5;++i)
a[i].display();
Stock *point=a;
for(;point!=&a[4];++point)
cout<<"今天的涨幅为......"<<setprecision(2)<<point->increase(*(point+1))<<endl;
system("pause");
return 0;
}
实验三类与对象
最新推荐文章于 2022-08-25 12:30:00 发布