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;
}
相关文章推荐
- 纪念逝去的岁月——C++实现一个栈
- C++面试题(二)——自己实现一个String类
- 每日一个算法------二叉树实现、递归和非递归算法(c++版)
- C++实现在一个字符串中寻找最大子串
- 读书笔记 effective c++ Item 25 实现一个不抛出异常的swap
- 一个通用的Trie树,标准C++实现
- java web中实现同一帐号同一时间只能一个地点登陆(类似QQ登录的功能)
- C++面试题(二)——自己实现一个String类
- Linux C++ 一个线程池的简单实现(附代码)
- 一个尽可能正确的Singleton实现 - c++描述
- C++实战:一个轻型数组类的实现
- 用PHP实现同一个帐号不允许同时登陆,只允许一个帐号登录?
- 两个栈模拟一个队列和两个队列模拟一个栈(c++实现)
- c++ 模版函数的定义和实现放在一个文件中
- 一个C++的BlockingQueue实现
- 用C++实现一个哈希桶(插入,删除,寻找)
- 【C++】通过模板实现一个通用的冒泡排序
- 一个简单位的C++ 类实现
- java web中实现同一帐号同一时间只能一个地点登陆(类似QQ登录的功能)
- More Effective C++ Item 附2:一个auto_ptr的实现实例