北郵C銀行門戶與電商平臺(tái).docx_第1頁(yè)
北郵C銀行門戶與電商平臺(tái).docx_第2頁(yè)
北郵C銀行門戶與電商平臺(tái).docx_第3頁(yè)
北郵C銀行門戶與電商平臺(tái).docx_第4頁(yè)
北郵C銀行門戶與電商平臺(tái).docx_第5頁(yè)
已閱讀5頁(yè),還剩32頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

C+電商交易平臺(tái)設(shè)計(jì)班級(jí):2013211306 姓名:嚴(yán)浩 學(xué) 號(hào):2013211321一 實(shí)驗(yàn)?zāi)康?. 鍛煉我們用c+編程的能力2. 培養(yǎng)我們考慮問(wèn)題是否全面的能力3. 訓(xùn)練我們的代碼優(yōu)化能力二 基本內(nèi)容題目一:銀行門戶的設(shè)計(jì)該門戶是一個(gè)單獨(dú)的程序,程序要求至少支持以下功能:1) 注冊(cè)銀行卡,銀行可選;2) 修改銀行卡密碼;3) 存款取款;銀行卡至少需要有卡號(hào),密碼,所屬銀行名稱,持卡人身份證號(hào),卡內(nèi)金額等內(nèi)容。要求1:請(qǐng)把所有的銀行名寫入文件(或數(shù)據(jù)庫(kù)),注冊(cè)銀行卡的時(shí)候,要求只能選擇已經(jīng)存在的銀行進(jìn)行注冊(cè)。要求2:請(qǐng)做好錯(cuò)誤場(chǎng)景的處理,例如讀銀行文件錯(cuò)誤,輸入數(shù)據(jù)不合法等等。題目二:電商平臺(tái)的設(shè)計(jì)該平臺(tái)是銀行門戶之外的一個(gè)單獨(dú)的程序,程序要求至少支持以下功能:1) 注冊(cè)&登錄:支持新用戶注冊(cè)平臺(tái)賬號(hào),已注冊(cè)用戶用平臺(tái)賬號(hào)登錄平臺(tái)。(要求已注冊(cè)用戶的信息長(zhǎng)久保留。)2) 瀏覽平臺(tái)產(chǎn)品信息。3) 優(yōu)惠活動(dòng):支持對(duì)同一品類下所有產(chǎn)品打折的活動(dòng),支持單筆訂單滿X減Y的活動(dòng)。4) 購(gòu)買產(chǎn)品:支持用戶添加產(chǎn)品到購(gòu)物車,查看實(shí)際應(yīng)付的產(chǎn)品價(jià)格,提交訂單。在題目二我們暫時(shí)不考慮提交訂單后支付等后續(xù)需求。要求1:電商平臺(tái)上至少有三類產(chǎn)品:如食物、服裝、圖書等,每類產(chǎn)品中至少有三個(gè)具體的產(chǎn)品(如圖書中可以有C+ Primer、Effertive C+等),每個(gè)具體的產(chǎn)品請(qǐng)至少包含產(chǎn)品描述,產(chǎn)品原價(jià),產(chǎn)品剩余量等數(shù)據(jù)。所有的產(chǎn)品信息需要存儲(chǔ)在數(shù)據(jù)庫(kù)或文件中,不能寫在代碼中,平臺(tái)管理員通過(guò)直接修改數(shù)據(jù)庫(kù)或文件,管理本平臺(tái)上的產(chǎn)品,包括產(chǎn)品的增加和刪除,修改數(shù)量以及具體產(chǎn)品的屬性信息等。要求2:請(qǐng)至少設(shè)計(jì)一層繼承體系(產(chǎn)品基類-產(chǎn)品子類),設(shè)計(jì)一個(gè)產(chǎn)品基類,然后讓圖書類、電子產(chǎn)品類和服裝類等產(chǎn)品子類類繼承它,具體的產(chǎn)品是產(chǎn)品子類的實(shí)例對(duì)象( 是圖書類的實(shí)例對(duì)象) 。產(chǎn)品基類請(qǐng)至少具有一個(gè)虛函數(shù)getPrice()用于計(jì)算具體產(chǎn)品的價(jià)格。要求3:請(qǐng)通過(guò)為每個(gè)產(chǎn)品子類定義“品類折扣系數(shù)”來(lái)支持對(duì)同產(chǎn)品子類下所有產(chǎn)品打折扣的活動(dòng)(如圖書全場(chǎng)5折,則圖書類這一產(chǎn)品子類的折扣系數(shù)為0.5)。要求4:請(qǐng)做好錯(cuò)誤場(chǎng)景的處理。題目三:網(wǎng)上支付的設(shè)計(jì)實(shí)現(xiàn)題目三會(huì)讓你設(shè)計(jì)的平臺(tái)像個(gè)真正的運(yùn)行在網(wǎng)絡(luò)上的平臺(tái)。題目三要求在題目一、二的基礎(chǔ)上支持通過(guò)網(wǎng)上支付在電商平臺(tái)上購(gòu)物,請(qǐng)至少實(shí)現(xiàn)以下功能:1) 綁定銀行卡:支持電商平臺(tái)賬號(hào)綁定銀行卡。同一賬號(hào)可以綁定多張銀行卡,而且銀行卡可以屬于不同銀行。2) 網(wǎng)上支付:選擇綁定的任一銀行卡支付電商平臺(tái)上的訂單。要求1:綁定銀行卡和選擇銀行卡進(jìn)行支付時(shí)都要求提供對(duì)應(yīng)的銀行卡密碼。要求2:當(dāng)在電商平臺(tái)上綁定銀行卡或者進(jìn)行網(wǎng)上支付的時(shí)候,請(qǐng)不要直接打開(kāi)某個(gè)文件查找銀行卡的信息,因?yàn)殂y行卡信息文件是銀行門戶系統(tǒng)私有的,電商平臺(tái)系統(tǒng)無(wú)法直接訪問(wèn),而應(yīng)該由電商平臺(tái)系統(tǒng)去向銀行門戶系統(tǒng)對(duì)接數(shù)據(jù)。請(qǐng)用socket通信來(lái)傳送數(shù)據(jù)。要求3:請(qǐng)做好錯(cuò)誤場(chǎng)景的處理,如綁定銀行卡失敗,支付失敗等。三 實(shí)驗(yàn)方法題目一:創(chuàng)建了銀行卡類、銀行門戶類,銀行卡里包含了卡號(hào)、姓名、密碼、身份證號(hào)、銀行名稱、余額幾個(gè)屬性。銀行門戶有操作銀行卡,注冊(cè)銀行卡兩個(gè)功能,操作銀行卡又包括存取款,修改密碼等功能,賬戶信息和銀行名稱保存在文件里,銀行卡用vector類型保存。題目二:創(chuàng)建了電商平臺(tái)類、賬戶類、商品類(商品類有3個(gè)派生類)、綁定銀行卡類、購(gòu)物車項(xiàng)目類。其中賬戶類中包含了用戶名、密碼、手機(jī)號(hào)、購(gòu)物車、應(yīng)付款、綁定銀行卡、綁定銀行卡數(shù)量這幾個(gè)屬性,其中購(gòu)物車?yán)锏捻?xiàng)目用vector類型保存。電商平臺(tái)中的賬戶也用vector類型保存,平臺(tái)的功能有:登錄、注冊(cè),登錄后可以綁定銀行卡、查看商品并添加購(gòu)物車、查看購(gòu)物車和應(yīng)付金額、結(jié)算購(gòu)物車、退出登錄等功能。題目三:在綁定銀行卡和付款時(shí)用socket通信來(lái)傳送數(shù)據(jù)。綁定銀行卡時(shí),先向銀行門戶發(fā)送綁定銀行卡標(biāo)志位表示綁定功能,然后發(fā)送卡號(hào)密碼,驗(yàn)證通過(guò)后返回成功標(biāo)志位,電商平臺(tái)收到后綁定成功。付款時(shí),先向銀行門戶發(fā)送付款標(biāo)志位表示付款功能,然后發(fā)送卡號(hào)密碼,驗(yàn)證通過(guò)后返回成功標(biāo)志位,電商平臺(tái)收到后發(fā)送應(yīng)付金額,銀行門戶收到后調(diào)用付款函數(shù),余額不足返回余額不足標(biāo)志位,余額夠則返回付款成功標(biāo)志位。四 源代碼 銀行門戶代碼: #ifndef _BANKCARD_H_#define _BANKCARD_H_#include#includeusing namespace std;class bankcardprivate: string cardnum; string password; string bankname; string name; string ID; double remainder; public: bankcard() bankcard(string num,string password,string bankname,string name,string ID,double remainder); void setPassword(string password); void addRemainder(double money); void subRemainder(double money); string getCardnum(); string getPassword(); string getBankname(); string getName(); string getID(); double getRemainder(); bool matchPassport(string password); ofstream& operator cardnum=cardnum;this-password=passport;this-bankname=bankname;this-name=name;this-ID=ID;this-remainder=remainder;void bankcard:setPassword(string newpassport)this-password=newpassport;void bankcard:addRemainder(double money)this-remainder+=money;void bankcard:subRemainder(double money)this-remainder=this-remainder-money;string bankcard:getCardnum()return cardnum;string bankcard:getPassword()return password;string bankcard:getBankname()return bankname;string bankcard:getName()return name;string bankcard:getID() return ID; double bankcard:getRemainder()return remainder;bool bankcard:matchPassport(string password)if(this-password=password) return true; else return false;ofstream& bankcard:operator (ofstream& ofs)ofs 卡號(hào):cardnum;ofs 密碼:password;ofs 銀行:bankname;ofs 姓名:name;ofs 身份證號(hào):ID;ofs 余額:decremainderendl; return ofs;#ifndef BANKPORTAL_H#define BANKPORTAL_H#include #include #pragma comment(lib,ws2_32.lib)#include #include #include bankcard.husing std:vector;class BankPortalprivate:vector vBankN;vector vBankC;void init();void registerBankC();void loginBankC();void changePassword(int index);void deposit(int index);void withdraw(int index);int match(string cardnum);bool check(string cardnum);void output();void bankNaming();double StrToDouble(string str, int start, int end);void Bind();bool pay(string num,double money);int Match(string username,string password);public:BankPortal(); #endif#include #include #include #include #include #include #include bankportal.hconst string bankname_file = bankname.txt;const string output_file = output.txt;BankPortal:BankPortal()init();cout Select) | (Select0 != 1 & Select0 != 2)cout 輸入錯(cuò)誤,請(qǐng)重新輸入: endl;cout endl; Choice=std:atoi(Select.c_str();if(Choice=2) Bind();while(true)cout endl;cout =歡迎來(lái)到銀行門戶= endl;cout = endl;cout =您想進(jìn)行什么操作?= endl;cout =1:操作賬戶 = endl;cout =2:注冊(cè)銀行卡 = endl;cout =3:退出 = endl;cout = endl endl;cout Select) | Select0 3)cout 輸入錯(cuò)誤,請(qǐng)重新輸入: endl;cout endl; select=std:atoi(Select.c_str();switch(select)case 1:loginBankC();break;case 2:registerBankC();break;case 3:output();return;default:break;void BankPortal:registerBankC()cout 請(qǐng)選擇你要注冊(cè)的銀行: endl;for(unsigned int i=0;ivBankN.size();i+)if(i % 4 = 3)cout i : vBankNi endl;elsecout i : vBankNi;cout endl num) | num = vBankN.size()cout endl 輸入錯(cuò)誤,請(qǐng)重新輸入:;cout endl; string bank = vBankNnum;int cardnum;strstream t;string card;string password;string temp;string name;string ID;int i;cout name; cout ID;srand(int)time(0);docardnum=1000+(rand()%9000);tcard;while(check(card);docout password;cout temp;while(password != temp & cout endl 前后輸入的密碼不同,請(qǐng)重新輸入! endl);cout endl;bankcard bcard(card, password, bank, name, ID,0.0);vBankC.push_back(bcard);cout 注冊(cè)銀行賬號(hào)成功! endl; cout 卡號(hào)為:cardendl;void BankPortal:loginBankC()string cardnum;string password;unsigned int num;docout請(qǐng)輸入要操作的銀行卡號(hào):cardnum;while(num=match(cardnum)=vBankC.size()&cout賬號(hào)輸入錯(cuò)誤!endl);while(true)cout = vBankCnum.getName() 先生/女士= endl;cout =卡內(nèi)余額共 vBankCnum.getRemainder() RMB= endl;cout = endl;cout =請(qǐng)選擇您的操作:= endl;cout =1:存款 = endl;cout =2:取款 = endl;cout =3:修改銀行卡密碼= endl;cout =4:返回上一級(jí)菜單= endl;cout = endl endl;cout Select) | Select0 4)cout 輸入錯(cuò)誤,請(qǐng)重新輸入: endl;select=std:atoi(Select.c_str();cout endl;switch(select)case 1:deposit(num); break;case 2:withdraw(num);break;case 3:changePassword(num);break;case 4:return;default:break;void BankPortal:deposit(int num)double money;cout請(qǐng)輸入您要存入的金額:money;vBankCnum.addRemainder(money);void BankPortal:withdraw(int num)double money; cout請(qǐng)輸入您要取出的金額:money;if(vBankCnum.getRemainder()=money) vBankCnum.subRemainder(money);else cout對(duì)不起,余額不足!=money) vBankCindex.subRemainder(money);return true;else return false;void BankPortal:changePassword(int num)string password;string temp;docout請(qǐng)輸入新密碼:password;cout再次確認(rèn)新密碼:temp;while(password!=temp&cout 前后輸入的密碼不同,請(qǐng)重新輸入! endl);vBankCnum.setPassword(password);int BankPortal:match(string cardnum)unsigned int i=0;for(;ivBankC.size();i+)if(vBankCi.getCardnum()=cardnum) return i;return i;bool BankPortal:check(string cardnum)unsigned int i=0;for(;ivBankC.size();i+)if(vBankCi.getCardnum()=cardnum) return true;return false;void BankPortal:output()ofstream fout(output_file.c_str();for(unsigned int i=0;ivBankC.size();i+)vBankCi(fout);fout.close();void BankPortal:bankNaming()ifstream fin(bankname_file.c_str();string input;while(getline(fin,input)vBankN.push_back(input);fin.close();double BankPortal:StrToDouble(string str, int start, int end)/把字符串轉(zhuǎn)化成double類型 int state = 0;int i = 0;double num = 0;for(; start cardnum) cardnum=cardnum.substr(6); finpassword; password=password.substr(6); finbankname; bankname=bankname.substr(6); finname; name=name.substr(6); finID; ID=ID.substr(10); finremainders; remainder=StrToDouble(remainders,6,remainders.size(); bankcard bankc(cardnum,password,bankname,name,ID,remainder); vBankC.push_back(bankc);fin.close();bankNaming();int BankPortal:Match(string cardnum,string password)unsigned int i=0;for(;ivBankC.size();i+)if(vBankCi.getCardnum()=cardnum&vBankCi.getPassword()=password)return i;return i; void BankPortal:Bind() WORD sockVersion = MAKEWORD(2,2); WSADATA wsaData; if(WSAStartup(sockVersion, &wsaData)!=0) printf(嵌套字未打開(kāi)!); return; /創(chuàng)建套接字 SOCKET slisten = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if(slisten = INVALID_SOCKET) printf(socket error !); return; /綁定IP和端口 sockaddr_in sin; sin.sin_family = AF_INET; sin.sin_port = htons(8888); sin.sin_addr.S_un.S_addr = INADDR_ANY; if(bind(slisten, (LPSOCKADDR)&sin, sizeof(sin) = SOCKET_ERROR) printf(bind error !); /開(kāi)始監(jiān)聽(tīng) if(listen(slisten, 5) = SOCKET_ERROR) printf(listen error !); return; /循環(huán)接收數(shù)據(jù) SOCKET sClient; sockaddr_in remoteAddr; int nAddrlen = sizeof(remoteAddr); char sendBuf2; char receiveChoice2; int choice; while (true) printf(等待連接.n); sClient = accept(slisten, (SOCKADDR *)&remoteAddr, &nAddrlen); if(sClient = INVALID_SOCKET) printf(accept error !); continue; printf(接受到一個(gè)連接:%s rn, inet_ntoa(remoteAddr.sin_addr); recv(sClient,receiveChoice,2,0); /監(jiān)聽(tīng)選擇 choice=(receiveChoice0-0); if(choice=1) char receiveCard5; char receivePassword30; recv(sClient,receiveCard,5,0); /接受賬號(hào)密碼 recv(sClient,receivePassword,30,0); string cardnum; cardnum=receiveCard; string password; password=receivePassword; int index; if(index=Match(cardnum,password)vBankC.size() sprintf(sendBuf,1); send(sClient,sendBuf,strlen(sendBuf)+1,0); /發(fā)送綁定成功 sprintf(sendBuf,vBankCindex.getBankname().c_str();/發(fā)送銀行類型 send(sClient,sendBuf,strlen(sendBuf)+1,0); else sprintf(sendBuf,0); send(sClient,sendBuf,strlen(sendBuf)+1,0); else if(choice=2) char receiveCard5; char receiveShouldpay20; char receivePassword30; int index; recv(sClient,receiveCard,5,0); /接受賬號(hào)密碼 recv(sClient,receivePassword,30,0); string cardnum; cardnum=receiveCard; string password; password=receivePassword; index=Match(cardnum,password); if(indexvBankC.size() sprintf(sendBuf,1); send(sClient,sendBuf,strlen(sendBuf)+1,0); /發(fā)送驗(yàn)證成功 recv(sClient,receiveShouldpay,20,0); double shouldpay; shouldpay=std:atof(receiveShouldpay); if(pay(cardnum,shouldpay) sprintf(sendBuf,1); send(sClient,sendBuf,strlen(sendBuf)+1,0); /發(fā)送付款成功 output(); else cout余額不足!; sprintf(sendBuf,0); send(sClient,sendBuf,strlen(sendBuf)+1,0); /發(fā)送付款成功 elsesprintf(sendBuf,0); send(sClient,sendBuf,strlen(sendBuf)+1,0); /發(fā)送驗(yàn)證失敗 closesocket(slisten); WSACleanup(); 電商平臺(tái)代碼:#ifndef _ACOUNT_H_#define _ACOUNT_H_#include#include#include#include item.h#include bankcard.husing namespace std;class Accountprivate:string username;string password;string phonenum;double shouldpay;int cardnum;public:vector vBank;vector vItem;double getShouldpay() return shouldpay;int getCardnum()return cardnum;void addCardnum(int num) cardnum+=num;void clshouldpay()shouldpay=0.0;void addShouldpay(double price) shouldpay+=price;void subShouldpay(double price) shouldpay-=price; Account();Account(string username,string password,string phonenum,vector scart,double shouldpay,int cardnum);void setPassword(string password);void setPhone(string phonenum);string getUsername();string getPassword();string getPhonenum();ofstream& operator (ofstream& ofs);#endif#ifndef _BANKCARD_H_#define _BANKCARD_H_#include#includeusing namespace std;class bankcardprivate: string cardnum; string bankname; public: bankcard() bankcard(string cardnum,string bankname) this-cardnum=cardnum; this-bankname=bankname; string getCardnum() return cardnum; string getBankname() return bankname; ;#endif#ifndef _GOODS_H_#define _GOODS_H_#include#includeusing namespace std;/登錄后,1.查看現(xiàn)有商品1.查看哪一類商品(記得顯示產(chǎn)品描述,產(chǎn)品原價(jià),產(chǎn)品剩余量,優(yōu)惠信息)|2.回退class goodsprotected:string name;string description;double originalPrice;int remainder;double discount;/折扣public:goods()goods(string name,string description,double originalPrice,int remainder,double discount) this-name=name; this-description=description; this-originalPrice=originalPrice; this-remainder=remainder; this-discount=discount; string getName();string getDescription();double getOriginalPrice();int getRemainder();bool subRemainder(int num)if(remainder=num)remainder=remainder-num;return true;return false;double getDiscount();virtual double getPrice()return discount*originalPrice;ofstream& goods:operator (ofstream& ofs);class food : public goodspublic:virtual double getPrice();food(string name,string description,double originalPrice,int remainder,double discount):goods(name,description,originalPrice,remainder,discount);class clothing : public goodspublic:virtual double getPrice();clothing(string name,string description,double originalPrice,int remainder,double discount):goods(name,description,originalPrice,remainder,discount);class book : public goodspublic:virtual double getPrice();book(string name,string description,double originalPrice,int remainder,double discount):goods(name,description,originalPrice,remainder,discount);#endif#ifndef _ITEM_H_#define _ITEM_H_#includeusing namespace std;class itemprotected:string name;int num;double price;public:item(string name,int num,double price) this-name=name;this-num=num;this-price=price;string getName() return name;int getNum() return num;double getPrice()return price;#endif#ifndef _PLATFO

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論