#include <iostream>
#include <string>
using namespace std;
class TV {
public:
enum TVKind { BLACK_WHITE, COLOR };
TV( TVKind kind=COLOR, string company="changhong", int size=21, double weight=33.2, bool satae = false ):
m_num(++TV::m_total), m_kind(kind), m_company(company),
m_size(size), m_weight(weight), m_satae(satae) {}
void print()const;
private:
int m_num;
TVKind m_kind;
string m_company;
int m_size;
double m_weight;
bool m_satae;
static int m_total;
};
int TV::m_total=0;
void TV::print()const {
cout<<"Number:"<<m_num<<" ";
cout<<"TVKind:"<<((m_kind==BLACK_WHITE)?"BlackWhite":"Color")<<" ";
cout<<"Company:"<<m_company<<" ";
cout<<"Size:"<<m_size<<" ";
cout<<"Weight:"<<m_weight<<" ";
cout<<"State:"<<(m_satae?"On":"Off")<<endl;
}
int main() {
int i;
TV vec[10];
for( i=0; i<10; ++i ) vec[i].print();
}
|