Advertisement
Guest User

shillings

a guest
Dec 12th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. using namespace std;
  4. //английские деньги
  5.  
  6. struct eng_money
  7. {
  8. public:
  9. //0123456
  10. //  0)Ввод
  11.     void enter(eng_money,unsigned &i)
  12.     {
  13.         cout<<"Введите данные денежной суммы №"<<i<<'\n';
  14.         cout<<"Фунты: ";
  15.         cin>>pounds;
  16.         cout<<"Шиллинги: ";
  17.         cin>>shillings;
  18.         cout<<"Пенсы: ";
  19.         cin>>pence;
  20.     };
  21. //  6)Вывод
  22.     void output(eng_money,unsigned &i)
  23.     {
  24.         cout<<"Денежная сумма №"<<i<<": <<"<<pounds<<'-'<<shillings<<'-'<<pence<<">>\n";
  25.     };
  26. //  1)Проверка корректности значения
  27.     void correct_value(eng_money)
  28.     {
  29.         if(pence>=12)
  30.         {
  31.             shillings+=(pence/12);
  32.             pence%=12;
  33.         }
  34.         if(shillings>=20)
  35.         {
  36.             pounds+=(shillings/20);
  37.             shillings%=20;
  38.         }
  39.     };
  40. //  2)Увеличение заданной суммы
  41.     void increase(eng_money,unsigned &i)
  42.     {
  43.         unsigned pounds_increment, shillings_increment, pence_increment;
  44.         cout<<"На сколько хотите увеличить денежную сумму №"<<i<<"? \nФунты: ";
  45.         cin>>pounds_increment;
  46.         cout<<"Шиллинги: ";
  47.         cin>>shillings_increment;
  48.         cout<<"Пенсы: ";
  49.         cin>>pence_increment;
  50.         if(pounds_increment!=0)
  51.         {
  52.             shillings_increment+=(pounds_increment*20);
  53.             pounds_increment=0;
  54.         }
  55.         if(shillings_increment!=0)
  56.         {
  57.             pence_increment+=(shillings_increment*12);
  58.             shillings_increment=0;
  59.         }
  60.         if(pounds!=0)
  61.         {
  62.             shillings+=(pounds*20);
  63.             pounds=0;
  64.         }
  65.         if(shillings!=0)
  66.         {
  67.             pence+=(shillings*12);
  68.             shillings=0;
  69.         }
  70.         pence+=pence_increment;
  71.     };
  72. //  3)Сумма двух структур
  73.     eng_money summary(eng_money &money1,eng_money &money2)
  74.     {
  75.         eng_money money_sum;
  76.         money_sum.pence=money1.pence+money2.pence;
  77.         money_sum.shillings=money1.shillings+money2.shillings;
  78.         money_sum.pounds=money1.pounds+money2.pounds;
  79.         return money_sum;
  80.     };
  81. //  4)Разность двух структур
  82.     eng_money difference(eng_money &money1,eng_money &money2)
  83.     {
  84.         eng_money money_dif;
  85.         money_dif.pence=money1.pence-money2.pence;
  86.         money_dif.shillings=money1.shillings-money2.shillings;
  87.         money_dif.pounds=money1.pounds-money2.pounds;
  88.         while(money_dif.shillings<0 && money_dif.pounds>0)
  89.         {
  90.             money_dif.shillings+=20;
  91.             money_dif.pounds-=1;
  92.         }
  93.         while(money_dif.pence<0 && money_dif.shillings>0)
  94.         {
  95.             money_dif.pence+=12;
  96.             money_dif.shillings-=1;
  97.         }
  98.         return money_dif;
  99.     }
  100. //  5)Перевод суммы в пенсы
  101.     void to_pence(eng_money &money)
  102.     {
  103.         money.shillings+=money.pounds*20;
  104.         money.pounds=0;
  105.         money.pence+=money.shillings*12;
  106.         money.shillings=0;
  107.     };
  108. private:
  109.     unsigned pounds;    //фунты
  110.     unsigned shillings; //шиллинги
  111.     unsigned pence;     //пенсы
  112. };
  113. int main()
  114. {
  115.     unsigned N; //количество денежных сумм
  116.     map<string,eng_money>purse;
  117.     eng_money purse_dif,purse_sum;
  118.     cout<<"Введите количество денежных сумм: ";
  119.     cin>>N;
  120.     const size_t NN = 512;
  121.     char s[NN];
  122.     unsigned short enter=10;
  123.     bool Acount=0;
  124.     unsigned del=10;
  125.     //istringstream ss;
  126.     for(unsigned i=1;i<N+1;i++)
  127.     {
  128.         purse[to_string(i)].enter(purse[to_string(i)],i);       //ввод
  129.         purse[to_string(i)].correct_value(purse[to_string(i)]); //проверка и перевод
  130.         purse[to_string(i)].increase(purse[to_string(i)],i);    //увеличение
  131.         purse[to_string(i)].correct_value(purse[to_string(i)]); //проверка и перевод
  132.         purse[to_string(i)].output(purse[to_string(i)],i);
  133.         if(i>1) {purse_dif=purse[to_string(i)].difference(purse[to_string(i)],purse[to_string(i-1)]);//разница 2 и 1 структур
  134.         purse_dif.output(purse_dif,i);}      //вывод
  135.        
  136.     }
  137.         cout<<"1)Среднее значение, выраженное в том же виде\n2)Пары сумм,наиболее близких и наиболее далеких по значению\n0)Завершить программу\n";
  138.     do
  139.     {
  140.         Acount=0;
  141.         while (!(Acount==0)!=1)
  142.     {
  143.         cout << "Введите число: ";
  144.         fgets( s, NN, stdin );
  145.         for(int i=0;i<NN;i++)
  146.         {
  147.             del=10;
  148.             if(s[i]>='0' && s[i]<='9')
  149.             {
  150.               if(Acount==1) continue;
  151.               if(enter%del==0)
  152.               {
  153.                 del*=10;if(del==10000000) break;
  154.               }
  155.               else
  156.               {
  157.                 enter=(s[i]+'0')*del/10;
  158.               }
  159.             }
  160.         }
  161.     }
  162.         if(enter==1)
  163.         {
  164.             //прога номер 1
  165.         }
  166.         if(enter==2)
  167.         {
  168.             //прога номер 2
  169.         }
  170.     } while (enter!=0);
  171.    
  172.     return 0;
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement