Advertisement
skb50bd

Lab-6 Problem 2

Jul 1st, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. class table{
  7. private:
  8.     char ch;
  9.     int cents;
  10. public:
  11.     table(): ch(0), cents(0) {}
  12.     char getchar() { return ch;}
  13.     int getcents() { return cents;}
  14.     void read() {
  15.         cin >> ch;
  16.         cin >> cents;
  17.     }
  18. };
  19.  
  20.  
  21.  
  22. int findchar(table *T, int K, char ch){
  23.     for (int i = 0; i < K; i++){
  24.         if (T[i].getchar() == ch)
  25.             return T[i].getcents();
  26.     }
  27.     return 0;
  28. }
  29.  
  30.  
  31.  
  32. int main(){
  33.     cout.setf(ios::fixed);
  34.     string str;
  35.     int pay, N, M, K;
  36.     double payment;
  37.  
  38.     cin >> N;
  39.     while (N--){
  40.         pay = 0;
  41.         payment = 0;
  42.  
  43.         cin >> K;
  44.         table t[K];
  45.         for (int i = 0; i < K; i++)
  46.             t[i].read();
  47.  
  48.         cin >> M;
  49.         for (int i = 0; i < M; i++){
  50.             cin.sync();
  51.             getline(cin, str);
  52.             for (int j = 0; str[j]; j++)
  53.                 pay += findchar(&t[0], K, str[j]);
  54.         }
  55.  
  56.         payment = pay / 100.0;
  57.         cout << setprecision(2) << payment << "$" << endl;
  58.     }
  59.  
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement