64,637
社区成员
发帖
与我相关
我的任务
分享
#ifndef HEADER_ACCOUNT
#define HEADER_ACCOUNT
#include<string>
using namespace std;
class Account{
string acntNumber;
public:
double balance;
Account(string acntNo,double balan=0);
virtual void display()const;
virtual void withdrawal1();
};
#endif
#ifndef HEADER_CHECKING
#define HEADER_CHECKING
#include<iostream>
#include"account.h"
using namespace std;
class Checking:public Account{
public:
Checking(string acntNo,double balan=0.0);
void withdrawal1();
void display()const;
};
#endif
#ifndef HEADER_SAVING
#define HEADER_SAVING
#include<iostream>
#include"account.h"
class Savings:public Account{
static int minBalance;
public:
Savings(string acntNo,double balan=0.0):Account(acntNo,balan){}
void display()const;
void withdrawal1();
};
#endif
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
#include"account.h"
Account::Account(string acntNo,double balan):acntNumber(acntNo),balance(balan){}
void Account::display()const{
cout<<"Account:"+acntNumber+"="<<balance<<"\n" ;
}
void Account::withdrawal1(){
ifstream inwithdrawal1("c:\\withdrawal.txt",ios::in);
string acntNo1;int amount1;
for(;inwithdrawal1>>acntNo1>>amount1; )
if(!((acntNo1=="x")&&(amount1==0))){
if(acntNumber==acntNo1){
balance-=amount1;
}
}
}
#include"checkings.h"
#include <iostream>
using namespace std;
Checking::Checking(string acntNo,double balan):Account(acntNo,balan){}//,remittance(other)
void Checking::display()const{
cout<<"Checking ";
Account::display();
}
void Checking::withdrawal1(){
Account::withdrawal1();
}
#include"checkings.h"
#include"savings.h"
//#include<iostream>
#include<fstream>
#include<string>
#include<vector>
using namespace std;
int main(){
vector<Savings*> sav;
vector<Checking*> chec;
ifstream in("c:\\p4421.txt",ios::in);
string acntNo;double amount;
for(;in>>acntNo>>amount;)//
{
if(!(acntNo=="x"&&amount==0))
if(!((static_cast<int>(acntNo.find("savings"))==-1)))
{ (sav.push_back(new Savings(acntNo,amount)));}
else
{
(chec.push_back(new Checking(acntNo,amount)));
}
}
for(vector<Savings*>::iterator it=sav.begin();it!=sav.end();++it){
(*it)->display();
(*it)->withdrawal1();
(*it)->display();
}
for(vector<Checking*>::iterator it=chec.begin();it!=chec.end();it++){
(*it)->display();
(*it)->withdrawal1();
(*it)->display();
}
for(vector<Savings*>::iterator it=sav.begin();it!=sav.end();it++)
delete *it;
for(vector<Checking*>::iterator it=chec.begin();it!=chec.end();it++)
delete *it;
system("pause");
}
#include"savings.h"
int Savings::minBalance=0;
void Savings::display()const{
cout<<"Savings ";
Account::display();
}
void Savings::withdrawal1(){
Account::withdrawal1();
}