Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- class NotSupportedCurrencyException
- {
- private:
- char valuta[4];
- public:
- NotSupportedCurrencyException(char*valuta=""){strcpy(this->valuta,valuta);}
- void showMessage()
- {
- cout<<valuta<<" is not a supported currency"<<endl;
- }
- };
- class InvalidDateException{
- private:
- int den;
- int mesec;
- int godina;
- public:
- InvalidDateException(int den , int mesec , int godina){
- this->den=den;
- this->mesec=mesec;
- this->godina=godina;
- }
- void showMessage(){cout<<"Invalid Date "<<den<<"/"<<mesec<<"/"<<godina<<endl;}
- };
- class Transaction{
- protected:
- int day;
- int month;
- int year;
- double amount;
- static double EUR;
- static double USD;
- public:
- Transaction(int day=0 , int month = 0 , int year = 0 , double amount=0.0)
- {
- if(day<1||day>31 || month<1 ||month>12){
- throw InvalidDateException(day, month , year);
- }
- this->day=day;
- this->month=month;
- this->year=year;
- this->amount=amount;
- }
- Transaction(const Transaction &t)
- {
- this->day=t.day;
- this->month=t.month;
- this->year=t.year;
- this->amount=t.amount;
- }
- static void setEUR(double EUR){Transaction::EUR=EUR;}
- static void setUSD(double USD){Transaction::USD=USD;}
- //static double
- virtual void print()=0;
- virtual double toDenars()=0;
- };
- double Transaction::EUR=61.0;
- double Transaction::USD=50.0;
- class DenarsTransaction : public Transaction{
- public:
- DenarsTransaction(int day=0 , int month = 0 , int year = 0 , double amount=0.0)
- :Transaction(day,month,year,amount){}
- DenarsTransaction(const DenarsTransaction &t) :Transaction (t){};
- void print()
- {
- cout<<day<<"/"<<month<<"/"<<year<<" "<<amount<<" MKD"<<endl;
- }
- double toDenars()
- {
- return this->amount;
- }
- };
- class ForeignCurrencyTransaction : public Transaction{
- char value[4];
- public:
- ForeignCurrencyTransaction(int day=0 , int month = 0 , int year = 0 , double amount=0.0, char *value="")
- :Transaction(day,month,year,amount)
- {
- if(strcmp(value,"EUR")==0 || strcmp(value,"USD")==0){
- strcpy(this->value,value);
- }
- else
- {
- throw NotSupportedCurrencyException(value);
- }
- }
- ForeignCurrencyTransaction(const ForeignCurrencyTransaction &f): Transaction(f)
- {
- strcpy(this->value,f.value);
- }
- void print()
- {
- cout<<day<<"/"<<month<<"/"<<year<<" "<<amount<<" "<<value<<endl;
- }
- double toDenars()
- {
- if(strcmp(value,"EUR")==0)
- {
- return amount *EUR;
- }
- else
- {
- return amount *USD;
- }
- }
- };
- class Account{
- private:
- Transaction**t;
- int n ;
- char account [15];
- double balance;
- public:
- Account(char *account ="", double balance=0.0)
- {
- strcpy(this->account,account);
- this->balance=balance;
- n = 0;
- t=new Transaction *[0];
- }
- Account &operator +=(Transaction *tran)
- {
- Transaction**tmp=new Transaction*[n+1];
- for(int i = 0 ; i < n ; i ++)
- {
- tmp[i]=t[i];
- }
- tmp[n]=tran;
- n++;
- delete[]t;
- t=tmp;
- return *this;
- }
- void reportInDenars()
- {
- double sum=this->balance;
- for(int i = 0 ; i < n ; i ++)
- {
- sum+=t[i]->toDenars();
- }
- cout<<"The user with account number: "<<account<<" has account balance of: "<<sum<<" MKD"<<endl;
- }
- void printTranscations()
- {
- for(int i = 0 ; i < n ; i ++)
- {
- t[i]->print();
- }
- }
- };
- int main () {
- Account s ("300047024112789",1500);
- int n, den, mesec, godina, tip;
- double iznos;
- char valuta [3];
- cin>>n;
- cout<<"===TRANSACTION ADDITION AND EXCEPTION HANDLING==="<<endl;
- for (int i=0;i<n;i++){
- cin>>tip>>den>>mesec>>godina>>iznos;
- // cout<<iznos<<endl;
- try{
- if (tip==2){
- cin>>valuta;
- Transaction * t = new ForeignCurrencyTransaction(den,mesec,godina,iznos,valuta);
- s+=t;
- //delete t;
- }
- else {
- Transaction * t = new DenarsTransaction(den,mesec,godina,iznos);
- s+=t;
- //delete t;
- }
- }
- catch
- (InvalidDateException &e)
- {
- e.showMessage();
- }
- catch (NotSupportedCurrencyException &e)
- {
- e.showMessage();
- }
- }
- cout<<"===TRANSACTIONS LIST==="<<endl;
- s.printTranscations();
- cout<<"===TRANSACTIONS REPORT IN DENARS==="<<endl;
- s.reportInDenars();
- cout<<"\n===CHANGE OF THE COURSE OF THE EUR AND USD===\n"<<endl;
- double newEUR, newUSD;
- cin>>newEUR>>newUSD;
- // cout<<"test"<<newEUR<<newUSD<<endl;
- Transaction::setEUR(newEUR);
- Transaction::setUSD(newUSD);
- cout<<"===TRANSACTIONS REPORT IN DENARS==="<<endl;
- s.reportInDenars();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement