您的位置:首页 > 编程语言 > C语言/C++

c++实现 一个客户帐号

2010-04-24 22:27 357 查看

c++实现 一个客户帐号

//110.h 头文件

#ifndef WYZ_1

#define WYZ_1

#include<iostream>

#include<string>

class point

{

private:

int nsize,asize;

char* name;

char* account;

double saving;

public:

point();

point(char*,char*,double);

point(std::string &,std::string &,double);

point::point(const point& bank);

point& operator=(const point& bank);

inline void funsaving(double);





friend std::ostream& operator<<(std::ostream &os,const point & bank);

~point();

};

#endif

#ifndef WYZ_WYZ_

#define WYZ_WYZ_

class coustomer

{

private:

long arrive;

int processtime;

public:

coustomer() {arrive=processtime=0;}

void set(long when);

long when()const {return arrive;}

int ptime()const {return processtime;}

};

typedef coustomer Item;

class queue

{

private:

struct Node{Item item;struct Node *next;};

enum { Q_SIZE=10};

Node *front;

Node *reat;

int items;

const int qsize;

queue(const queue &q):qsize(0){}

queue & operator=(const queue &q){ return *this;}

public:

queue(int qs=Q_SIZE);

~queue();

bool isempty()const;

bool isfull()const;

int queuecount()const;

bool enqueue(const Item &item);

bool dequeue(Item &item);

};

#endif

#include"110.h"

#include<cstdio>

inline void point::funsaving(double dsaving)

{

saving=dsaving;

}

point::point()

{

asize=nsize=4;

name=new char[nsize];

strncpy(name,"***",nsize);



account=new char[asize];

strncpy(account,"***",asize);

saving=0;

}

point::point(char *strname,char* straccount,double dsaving)

{

nsize=strlen(strname);

name=new char[nsize+1];

strcpy(name,strname);

asize=strlen(straccount);

account=new char[asize+1];

strcpy(account,straccount);

saving=dsaving;

}

point::point(std::string &strname,std::string &straccount,double dsaving)

{

nsize=strname.size();

name=new char[nsize+1];

strcpy(name,strname.c_str());

asize=straccount.size();

account=new char[asize+1];

strcpy(account,straccount.c_str());

saving=dsaving;

}

point& point::operator=(const point& bank)

{

nsize=bank.nsize;

name=new char[nsize+1];

std::strcpy(name,bank.name);

//.........................

asize=bank.asize;

account=new char[asize+1];

std::strcpy(account,bank.account);

saving=bank.saving;

return bank;

}

point::point(const point& bank)

{

nsize=bank.nsize;

name=new char[nsize+1];

std::strcpy(name,bank.name);

//.........................

asize=bank.asize;

account=new char[asize+1];

std::strcpy(account,bank.account);

saving=bank.saving;

}

point::~point()

{

delete[]account;

delete[]name;

}

std::ostream& operator<<(std::ostream& os,const point& bank)

{

os<<"姓名:"<<bank.name<<std::endl<<"帐号:"<<bank.account<<std::endl<<"余额:"<<bank.saving<<std::endl;

return os;

}

#include<iostream>

#include<string>

#include"110.h"

int main()

{

using namespace std;

cout.setf(ios_base::fixed,ios_base::floatfield);

cout.precision(4);

string name,account;

double saving;

getline(cin,name);

getline(cin,account);

cin>>saving;

point wqn(name,account,saving),qan;

cout<<wqn<<endl<<qan;

cin>>saving;

wqn.funsaving(saving);

cout<<wqn;

cout<<"另一个"<<endl;

point stg=point("qwer","utryuyytr",456.123);

cout<<stg<<endl<<endl;

wqn=stg;

cout<<stg;

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: