Advertisement
Guest User

alkomacik

a guest
Jan 25th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.75 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <math.h>
  5.  
  6. float zao(float a)  {
  7.     return round(a*100)/100;
  8. }
  9.  
  10.  
  11.  
  12. int main()
  13. {
  14.     system("color F8");
  15.     float vol;
  16.     float per;
  17.     float wgh;
  18.     float hgh;
  19.     float hours = 0;
  20.     double var0m = 2.447;
  21.     double var1m = 0.09156;
  22.     double var2m = 0.1074;
  23.     double var3m = 0.3362;
  24.     double var0fm = -2.097;
  25.     double var1fm = 0.1069;
  26.     double var2fm = 0.2466;
  27.     double token;
  28.     float safebac;
  29.     float safebacm;
  30.     float sd;
  31.     float bac;
  32.     float mr = 0.017;
  33.     float water = 0.806;
  34.     float alh;
  35.     float alm;
  36.     float reaction;
  37.     int age;
  38.     int sex;
  39.     std::cout << "Input your weight (in kg): ";
  40.     std::cin >> wgh;
  41.     if (wgh > 150)
  42.     {
  43.         std::cout << "NOTE: Weight input exceeded 150kg, proceeding...\n";
  44.     }
  45.     std::cout << "Input your height (in cm): ";
  46.     std::cin >> hgh;
  47.     if (hgh > 250)
  48.     {
  49.         std::cout << "NOTE: Height input exceeded 250cm, prooceding...\n";
  50.     }
  51.     std::cout << "Provide your age: ";
  52.     std::cin >> age;
  53.     if (age > 120)
  54.     {
  55.         std::cout << "NOTE: Age input exceeded 120, proceeding...\n";
  56.     }
  57.     if (((wgh)/(hgh*hgh))*1000>= 50)
  58.     {
  59.         std::cout << "WARNING: Unable to handle BMI (unnatural input: " << zao((((wgh)/(hgh*hgh))*10000)) << ")\n";
  60.     }
  61.     std::cout << "Provide your gender (1 for female, 0 for male): ";
  62.     std::cin >> sex;
  63.     std::cout << "Input volume of alcohol drink you have consumed (in ml): ";
  64.     std::cin >> vol;
  65.     std::cout << "Input alcohol volume in alcohol drink you have consumed (in %): ";
  66.     std::cin >> per;
  67.     std::cout << "Provide drinking period in hours: ";
  68.     std::cin >> hours;
  69.     if (hours == 0)
  70.     {
  71.         std::cout << "WARNING: 0 drinking hours. Token set: 1";
  72.         hours = 1;
  73.     }
  74.     system("CLS");
  75.     std::cout << "We have provided specified informations: \n";
  76.     std::cout << "Your weight is: " << wgh << "kg\n";
  77.     std::cout << "Your height is: " << hgh/100 << "m\n";
  78.     if (sex == 1)
  79.     {
  80.         token=(var0fm + (var1fm * hgh) + (var2fm * wgh))/wgh;
  81.         std::cout << "You're " << age << " female (token set: " << token << ")\n";
  82.     } else if (sex == 0) {
  83.         token=(var0m - (var1m * age) + (var2m * hgh) + (var3m * wgh))/wgh;
  84.         std::cout << "You're " << age << " male (token set: " << token << ")\n";
  85.    
  86.     } else if (sex != 1 && sex != 0) {
  87.         std::cout << "Cannot recognize gender (token set: 6,615)\n";
  88.         token=6.615;
  89.     }
  90.    
  91.     sd = ((vol*(per/100))/10);
  92.     bac = (((water*sd*1.2)/(token*wgh))-mr*hours)*10;
  93.     safebac = round(zao(bac-0.2)/0.15);
  94.     safebacm = zao(bac-0.2)/0.15 - safebac;
  95.     alh = round(zao(bac/0.15));
  96.     alm = zao(bac/0.15) - alh;
  97.     reaction = ((bac*130)/0.2)-bac;
  98.    
  99.  
  100.    
  101.     if (bac <= 0)
  102.     {
  103.         bac = 0.00;
  104.     }
  105.    
  106.     std::cout << "\n" << "You've consumed " << vol << "ml of alcoholic drink. (alc. vol. " << per << "%)\n";
  107.     std::cout << "Alcohol you've consumed in grams: " << vol*(per/100) << "g. (" << sd << " standard portions)\n";
  108.     std::cout << "Estimated values:\n";
  109.     std::cout << "- peak alcohol concentration: " << zao(bac) << "%\n";
  110.     if (bac > 0)
  111.     {
  112.    
  113.         std::cout << "- alcohol metabolism in hours: " << alh << "h " << round(alm*60)*-1 << "m\n";
  114.     }
  115.     else
  116.     {
  117.         std::cout << "- alcohol metabolism in hours: sober (since: " << alh*-1 << "h " << round(alm*60) << "m)\n";
  118.     }
  119.  
  120.     if (bac <=0.2 )
  121.     {
  122.         std::cout << "- visible direct alcohol effect in hours: none\n";
  123.     }
  124.     else
  125.     {
  126.     if (safebacm < 0)
  127.     {
  128.         safebacm = 0;
  129.     }
  130.         std::cout << "- visible direct alcohol effect in hours: " << safebac << "h " << round(safebacm*60) << "m\n";
  131.     }
  132.    
  133.     if (reaction > 0)
  134.     {
  135.         if (reaction >= 1000)
  136.         {
  137.             std::cout << "- possible reaction time delay: " << round(reaction/1000) << "s (increased by: " << zao(bac*13)/0.2 << "%)\n";
  138.         }
  139.         else if (reaction <= 1000)
  140.         {
  141.             std::cout << "- possible reaction time delay: " << round(reaction) << "ms (increased by: " << zao(bac*13)/0.2 << "%)\n";
  142.         }
  143.     }
  144.     else
  145.     {
  146.         std::cout << "- possible reaction time delay: none\n";
  147.     }
  148.    
  149.     if (bac >= 0.4)
  150.     {
  151.         std::cout << "- possibility of alcohol poisoning: " << zao(bac*100/3.5) << "%\n";
  152.     }
  153.     else
  154.     {
  155.         std::cout << "- possibility of alcohol poisoning: 0%\n";
  156.     }
  157.    
  158.     std::cout << "\n\nNOTE: You SHOULD not fully trust provided informations ought these may be lowered or the opposite.\n";
  159.     std::cout << "This application is recommended for self draft-test purposes only. For the most proximate outcome\n";
  160.     std::cout << "please use breath analyzer.\n";
  161.     std::cout << "Driving ANY kind of vehicle after alcohol intake is highly not recommended when unsure of\n";
  162.     std::cout << "the actual BAC.";
  163.     return 0;
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement