中小企业网络管理技术完全篇
2007-04-05 14:43
295 查看
#include <iostream> #include <iomanip> #include <cstdio> #include <windows.h> using namespace std; // 返回值类型 enum status {success,fail,underflow,overflow,range_error}; // 客户类 struct Client { string name; string id; double credit; struct Client *next; }; /* 可以存储客户的数据库 链表实现 */ class DataBase { private: Client *headp; protected: // 客户数目 int count; public: DataBase(void); ~DataBase(void); // 数据库是否为空 bool empty(void) const; // 客户数目 int length(void) const; // 创建数据库 status create(void); // 清空数据库 status clear(void); // 新增加一个客户 status insert(const Client &item); // 删除一个客户 status remove(int position); // 更新 position 位置的客户信息 status replace(int position,const Client &item); // 遍历数据库 status traverse(void) const; // 读取一个客户信息 status retrieve(int position,Client &item) const; // 客户消费 -> 计算客户的积分情况 // 根据客户的积分 -> 计算客户的优惠情况 // 第几个客户,消费金额 status consume(int position,double maney); }; DataBase::DataBase() { headp = new Client; if (!headp) exit(-1); headp -> next = NULL; count = 0; } DataBase::~DataBase() { if (headp) { delete headp; headp = NULL; } count = 0; } bool DataBase::empty(void) const { return (count == 0); } int DataBase::length(void) const { return count; } status DataBase::create(void) { // 如果原数据库含有数据 // 则清空数据库 if (count) delete headp; // 调用构造函数创建数据库 DataBase(); Client *searchp = headp; Client *newClient; cout << "Please input the number of the clients: "; int num; cin >> num; cout << "\nPlease input the information of the clients...\n(like that: name id credit)" << endl; for (int i = 0; i < num; i++) { newClient = new Client; if (!newClient) exit(-1); cin >> newClient -> name; cin >> newClient -> id; cin >> newClient -> credit; searchp -> next = newClient; newClient -> next = NULL; searchp = searchp -> next; ++ count; } searchp -> next = NULL; return success; } status DataBase::clear(void) { Client *searchp = headp -> next; Client *followp = headp; while (searchp) { followp = searchp; searchp = searchp -> next; delete followp; } headp -> next = NULL; count = 0; return success; } // 倒序创建数据库 status DataBase::insert(const Client &item) { Client *newClient = new Client; if (!newClient) exit(-1); newClient -> name = item.name; newClient -> id = item.id; newClient -> credit = item.credit; //cout << newClient -> name << newClient -> id << newClient -> credit << endl; newClient -> next = headp -> next; headp -> next = newClient; count ++; return success; } status DataBase::remove(int position) { if (empty()) return underflow; if (position < 1 || position > count) { cout << "Range_Error!" << endl; return range_error; } Client *searchp = headp -> next; Client *followp = headp; int i = 1; while (i < position && searchp) { followp = searchp; searchp = searchp -> next; i++; } followp -> next = searchp -> next; delete searchp; -- count; return success; } status DataBase::replace(int position,const Client &item) { if (empty()) { cout << "Data Bank Is Empty!" << endl; return underflow; } if (position < 1 || position > count) { cout << "Range_Error!" << endl; return range_error; } Client *searchp = headp -> next; int i = 1; while (i < position && searchp) { ++ i; searchp = searchp -> next; } searchp -> name = item.name; searchp -> id = item.id; searchp -> credit = item.credit; return success; } status DataBase::traverse(void) const { if (empty()) { cout << "Data Bank Is Empty!" << endl; return underflow; } Client *searchp = headp -> next; cout << "BEGIN:" << endl; while (searchp) { cout << setw(6) << searchp -> name << ' '; cout << setw(12) << searchp -> id << ' '; cout << setw(6) << searchp -> credit << endl; searchp = searchp -> next; } cout << "END!" << endl; return success; } status DataBase::retrieve(int position,Client &item) const { if (empty()) { cout << "Data Bank Is Empty!" << endl; return underflow; } if (position < 1 || position > count) { cout << "Range_Error!" << endl; return range_error; } Client *searchp = headp -> next; int i = 1; while (i < position && searchp ) { i++; searchp = searchp -> next; } item.name = searchp -> name; item.id = searchp -> id; item.credit = searchp -> credit; return success; } status DataBase::consume(int position,double maney) { if (empty()) { cout << "Have no one person!" << endl; return underflow; } if (position < 1 || position > length()) { cout << "Have none this person!" << endl; return overflow; } // 获得这位顾客 Client item; retrieve(position,item); // 根据客户积分计算优惠比率 double rate = item.credit; while (rate > 100) rate -= 100; rate = rate / 100; // 实际优惠计算需要交付的金额 double realManey = maney * (1 - rate); cout << "Client: " << item.name << " ID: " << item.id; cout << " Should pay: " << realManey << endl; // 根据所交金额计算该客户所得积分 if (realManey <= 10) { item.credit += realManey * 0.01; } else if (realManey <= 20) { item.credit += realManey * 0.02; } else if (realManey <= 30) { item.credit += realManey * 0.03; } else if (realManey <= 40) { item.credit += realManey * 0.04; } else if (realManey <= 50) { item.credit += realManey * 0.05; } else { item.credit += realManey * 0.1; } cout << "And now his credit is:" << item.credit << endl; return success; } int main() { DataBase D; cout << "Let's Begin!" << endl; cout << "\nDataBase is empty ? " << endl; if (D.empty()) cout << "Yes"; else cout << "No"; cout << "!" << endl; cout << "\nFirst!" << endl; freopen("input.txt","r",stdin); D.create(); D.traverse(); cout << "\nSecond:" << endl; cout << "After insert two clients:" << endl; Client C; cin >> C.name >> C.id >> C.credit; D.insert(C); cin >> C.name >> C.id >> C.credit; D.insert(C); D.traverse(); cout << "And we have " << D.length() << " clients!" << endl; cout << "\nThird:" << endl; cout << "After remove 3 clients:" << endl; D.remove(1); D.remove(1); D.remove(1); cout << "We have " << D.length() << " clients!" << endl; cout << "And they are: " << endl; D.traverse(); cout << "\nForth:" << endl; cout << "we can replace a client:" << endl; cin >> C.name >> C.id >> C.credit; D.replace(1,C); cout << "And they are: " << endl; D.traverse(); cout << "\nFifth:" << endl; cout << "We can get a certain client,please input his position: "; int position; cin >> position; D.retrieve(position,C); cout << "His name is " << C.name << " and his id: " << C.id << endl; cout << "And his crident: " << C.credit << endl; cout << "\nSixth:" << endl; D.clear(); cout << "Ater clear the DataBase,we still have " << D.length() << "'s client!" << endl; cout << "And we read them agin!" << endl; for (int i = 0; i < 5; i++) { cin >> C.name >> C.id >> C.credit; D.insert(C); } D.traverse(); cout << "\nSeventh:" << endl; cout << "If them goto shopping,and we can give them a discount ^_^" << endl; cout << "Please input the number of the client,and how maney he will pay!" << endl; double maney; cin >> position; while (position) { cin >> maney; D.consume(position,maney); cin >> position; } return 0; }
本文出自 “Boost” 博客,请务必保留此出处http://zhujifang.blog.51cto.com/8634872/1380221
相关文章推荐
- 中小企业网络管理技术完全篇
- 技术分享和交流-中小企业(SMB)如何设计IDC网络架构?如何管理运维资源和知识?
- [技术讨论]网络软件开发的bug分析与公司开发管理问题之网易篇(有更新)
- 无线网络通信技术完全介绍
- 网工七大计策掌握网络管理中的实战技术(转)
- [技术讨论]网络软件开发的bug分析与公司开发管理问题之阿里篇
- 网络行业 技术转管理行业的建议
- 基于Web的网络管理技术简介
- 中小企业网络管理
- 基于Web的网络管理技术简介
- 基于Web的网络管理技术简介
- 家庭网络设备的远程管理技术 (转贴)
- 网络管理之中小企业局域网网络管理方法
- [技术讨论]网络软件开发的bug分析与公司开发管理问题之腾讯篇二(有更新)
- 中小型企业网管员网络管理技术
- 中小型企业网管员网络管理技术
- 无线网络通信技术完全介绍
- 存储入门:存储区域网络SAN技术完全详解
- NetFlow技术与高校网络管理