分享
 
 
 

解答C++作业04

王朝c/c++·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

//ChkgAcct.h

//ChkgAcct classes

#ifndef CHKGACCT_H

#define CHKGACCT_H

class ChkgAcct {

public:

ChkgAcct();

void deposit(double amt);

bool checkWithdraw(double amt);

bool atmWithdraw(double amt);

double getBalance();

int setTrack(int type ,double amt);

//push the type and amt into track

void getTrack(int i,int &cTracktype,double &cTrackamt);

//pop type and amount of number i transaction

private:

double balance;

int Tracktype[51];

//store the type of transaction

double Trackamt[51];

//store the amount

};

#endif

//ChkgAcct.cpp

#include "ChkgAcct.h"

#include<iostream>

ChkgAcct::ChkgAcct(){

balance = 100.0;

for(int i=1;i<=50;i++)

{

Tracktype[i]=0;

Trackamt[i]=0;

}

//initialize the track

}

void ChkgAcct::deposit(double amt){

balance=balance+amt;

}

bool ChkgAcct::checkWithdraw(double amt){

if (amt<=balance) {

balance=balance-amt;

return true;

}

else{

balance=balance-10;

return false;

}

}

bool ChkgAcct::atmWithdraw(double amt){

if (amt<=balance) {

balance=balance-amt-1;

return true;

}

else

return false;

}

double ChkgAcct::getBalance(){

return balance;

}

int ChkgAcct::setTrack(int type ,double amt)

{

static int i=0;

//store the total times of the transaction

i++;

if(i<=50)

{

Tracktype[i]=type;

Trackamt[i]=amt;

}

//if the times of the transaction is less than 50

else

///if is more than 50,ie 51, using push

{

i=50;

for(int j=1;j<50;j++)

{

Tracktype[j]=Tracktype[j+1];

Trackamt[j]=Trackamt[j+1];

}

Tracktype[50]=type;

Trackamt[50]=amt;

}

return i;

}

void ChkgAcct::getTrack(int i,int &cTracktype,double &cTrackamt)

{

cTracktype=Tracktype[i];

cTrackamt=Trackamt[i];

}

//client.cpp

//create 10 account to test

#include "ChkgAcct.h"

#include <iostream>

#include <stdlib.h>//use system() to clear screem

#include <conio.h>//use getch(),putchar()

#include <string>

using namespace std;

int main(){

ChkgAcct client[10];

int accountID; //the ID of account

int type; //type of transaction

double amount=0; //amount of transaction

int typeGet; //type of transaction got from every account

double amountGet; //amount of transaction got from every account

char ch,flag;

string str; //store input as the string type of amount

///////do start loop

do{

str="";

system("cls"); //function to clear the screem

cout<<"***********************************************"<<endl;

cout<<"Please input your account ID,from 0 to 9 :"<<endl;

cout<<"input:";

//////1 make sure the input is 0 to 9

int i=0;

do{

ch=getch();

if(ch>='0'&&ch<='9')

{

putchar(ch);

i++;

}

}while(i<1);

accountID=ch-'0';

cout<<endl;

//////~1

if(accountID>=0&&accountID<=9)

cout<<"Account "<<accountID<<" ,you have: "

<<client[accountID].getBalance()<<" left."<<endl;

flag='n'; //set the flag to test if the client want to quit

do{

cout<<"***********************************************"<<endl;

cout<<"please choose the type of your transaction: \n"

<<"1、Deposit\n"

<<"2、Checkwithdrawal\n"

<<"3、ATMwithdrawal \n"

<<"4、Check Account\n"

<<"5、Recent 50 transactions"<<endl;

cout<<"6-9、 to logout"<<endl;

cout<<"input:";

//////~2 make sure the input is number

int i=0;

do{

ch=getch();

if(ch>='0'&&ch<='9')

{

putchar(ch);

i++;

}

}while(i<1);

type=ch-'0';

cout<<endl;

//////~2

if(type>=1&&type<=3) {

cout<<"***********************************************"<<endl;

cout<<"input the amount(positive value): "<<endl;

cout<<"input:";

//////3 make sure the first number is not zero

do{

ch=getch();

}while(ch=='0'||ch<='0'||ch>'9');

str=ch;

putchar(ch);

i=1;

/////~3

//////4 make sure input is number ,and enter means finish

do

{

ch=getch();

if(ch>='0'&&ch<='9'&&ch!=13)

{

putchar(ch);

str=str+ch;

i++;

} //ignore other input

}while(ch!=13);

cout<<endl;

//////~4

//////5 translate string to double

amount=0;

for(int j=0;j<i;j++)

amount=amount*10+(str[j]-'0');

///////~5

/////6 check if the client want to cancel

///// and the input is y/n

cout<<endl<<"are you sure?y/n:"<<endl;

i=0;

do{

ch=getch();

if(ch=='y'||ch=='n')

{

putchar(ch);

i++;

}

}while(i<1);

cout<<endl;

/////~6

if(ch=='n') {

system("cls");

cout<<"you cancel the transaction "<<endl;

continue;

}

} //end of if

system("cls");

cout<<"***********************************************"<<endl;

switch(type){

case 1:{

client[accountID].deposit(amount);

cout<<"succeed!"<<endl;

cout<<"you Deposit "<<amount<<" $."<<endl;

client[accountID].setTrack(1,amount);

///set the track with type and amount

}

break;

case 2:{

if(!client[accountID].checkWithdraw(amount))

{

cout<<"fail!"<<endl;

cout<<"your account do not have enough money!"<<endl;

cout<<"$10.00 service charge is deducted! "<<endl;

client[accountID].setTrack(4,amount);

}

else

{

cout<<"succeed!"<<endl;

cout<<"you withdraw "<<amount<<" $."<<endl;

client[accountID].setTrack(2,amount);

}

}

break;

case 3:{

if(!client[accountID].atmWithdraw(amount))

{

cout<<"fail!"<<endl;

cout<<"your account do not have enough money!"<<endl;

client[accountID].setTrack(5,amount);

}

else

{

cout<<"succeed!"<<endl;

cout<<"you withdraw "<<amount<<" $."<<endl;

cout<<"a $1 service charge is deducted "<<endl;

client[accountID].setTrack(3,amount);

}

}

break;

case 4:{

cout<<"you have: "

<<client[accountID].getBalance()<<" $ "

<<" left."<<endl;

}

break;

case 5:{

//////7 output the resent transaction

for(int i=50;i>=1;i--)

{

client[accountID].getTrack(i,typeGet,amountGet);

if(typeGet>0&&typeGet<6)

{

switch (typeGet){

case 1:cout<<i<<"、deposite:";break;

case 2:cout<<i<<"、checkWithdraw:";break;

case 3:cout<<i<<"、amtWithdraw:";break;

case 4:cout<<i<<"、fail checkWithdraw:";break;

case 5:cout<<i<<"、fail atmWithdraw:";break;

}

cout<<amountGet<<" $."<<endl;

}

}

//////~ 7

}

break;

default:{

//////8 check if the client want to logout

///// make sure the input is y/n

cout<<endl<<"do you want to logout? y/n"<<endl;

int i=0;

do{

ch=getch();

if(ch=='y'||ch=='n')

{

putchar(ch);

i++;

}

}while(i<1);

flag=ch;

cout<<endl;

/////~ 8

}

break;

} //end of switch

}while(flag!='y');

////yes means that the client is to logout

}while(true);

///////~do continue loop

return 0;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有