Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.71 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const char BREAK = '.';
  6. const int TRANSACTIONS = 6, CLIENTS = 21, ADDRESS = 21, NAME = 11;
  7. int lastClient = 0, lastTransaction = 0;
  8.  
  9. void StoreAddress(char addresses[ADDRESS], char address[ADDRESS])
  10. {
  11.     for(int a = 0; a<ADDRESS; a++) addresses[a] = address[a];
  12. }
  13.  
  14. void Balances(int id, int lastTransaction, int transactions[CLIENTS][TRANSACTIONS], char transactiontypes[CLIENTS][TRANSACTIONS],int balances[CLIENTS])
  15. {
  16.  
  17.     balances[id] = 0;
  18.     for(int i = 0; i<lastTransaction; i++){
  19.         if(transactiontypes[id][i] == 'w' || transactiontypes[id][i] == 'W'){
  20.         balances[id] -= transactions[id][i];
  21.         }else balances[id] += transactions[id][i];
  22.     }
  23.  
  24. }
  25.  
  26. void Transactions(int id, int lastTransaction, char transactiontypes[CLIENTS][TRANSACTIONS], int transactions[CLIENTS][TRANSACTIONS], int balances[CLIENTS])
  27. {
  28.     char transactiontype;
  29.     int transaction;
  30.  
  31.     for(int transactionNum = lastTransaction; transactionNum<TRANSACTIONS-1; transactionNum++){
  32.         cin>>transactiontype;
  33.         cin>>transaction;
  34.         if(transactiontype == BREAK){
  35.             cout<<lastTransaction<<endl;
  36.             break;
  37.         }else if(transactiontype != 'w' && transactiontype != 'W' && transactiontype != 'd' && transactiontype != 'D'){
  38.             cout<<"Invalid transaction, please try again."<<endl;
  39.             transactionNum--;
  40.             continue;
  41.         }
  42.         if(transaction < 0){
  43.             cout<<"Invalid transaction amount, please try again."<<endl;
  44.             transactionNum--;
  45.             continue;
  46.         }else{
  47.             transactions[id][transactionNum] = transaction;
  48.             transactiontypes[id][transactionNum] = transactiontype;
  49.             }
  50.         lastTransaction++;
  51.     }
  52.     Balances(id, lastTransaction, transactions, transactiontypes, balances);
  53. }
  54.  
  55. void Info(char names[CLIENTS][NAME], int buildings[CLIENTS], char addresses[CLIENTS][3][ADDRESS],
  56.            char transactiontypes[CLIENTS][TRANSACTIONS], int transactions[CLIENTS][TRANSACTIONS],
  57.            int balances[CLIENTS])
  58. {
  59.  
  60.     char name[NAME], street[ADDRESS], neighborhood[ADDRESS], city[ADDRESS];
  61.     int building;
  62.     for(int id = lastClient; id<CLIENTS-1; id++)
  63.     {
  64.         cout<<"Client "<<id+1<<endl;
  65.         cout<<"Name: ";
  66.         cin>>name;
  67.         if(name[0] == BREAK){
  68.             lastClient = id-1;
  69.             break;
  70.         }
  71.         cout<<"Address: "<<endl;
  72.         cout<<"(Number) (Street) (Neighborhood) (City)"<<endl;
  73.         cin>>building>>street>>neighborhood>>city;
  74.         if(building > 0)
  75.         {
  76.             for(int i = 0; i<NAME; i++) names[id][i] = name[i];
  77.             buildings[id] = building;
  78.             StoreAddress(addresses[id][0], street);
  79.             StoreAddress(addresses[id][1], neighborhood);
  80.             StoreAddress(addresses[id][2], city);
  81.  
  82.             cout<<"Please enter your transactions (Maximum "<<TRANSACTIONS-1<<" transactions)"<<endl;
  83.             cout<<"(W for Withdraw/D for Deposit) (Amount)"<<endl;
  84.             Transactions(id, lastTransaction, transactiontypes, transactions, balances);
  85.  
  86.         }else{
  87.             cout<<"Invalid address, please try again."<<endl;
  88.             id--;
  89.             continue;
  90.         }
  91.     }
  92.  
  93. }
  94.  
  95. int main()
  96. {
  97.     char client_names[CLIENTS][NAME];
  98.     int client_buildings[CLIENTS];
  99.     char client_addresses[CLIENTS][3][ADDRESS];
  100.     int client_balances[CLIENTS];
  101.     int client_transactions[CLIENTS][TRANSACTIONS];
  102.     char client_transactiontypes[CLIENTS][TRANSACTIONS];
  103.  
  104.  
  105.     // Test input client info
  106.     Info(client_names, client_buildings, client_addresses, client_transactiontypes, client_transactions, client_balances);
  107.  
  108.  
  109.     return 0;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement