Advertisement
Narzew

25-11-16 program backup

Nov 25th, 2016
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3.  
  4. using namespace std;
  5.  
  6. void simple_math_int();
  7. void simple_math_double();
  8. void many_expressions();
  9. void point_coords();
  10. void point_coords_old();
  11. void english_name();
  12. void plural_word();
  13. void min_max();
  14. void duplicates();
  15.  
  16. int main()
  17. {
  18.     int mode;
  19.     cout << "Select program:\n1 - simple math int\n2 - simple math double\n3 - many expressions\n4 - point coords\n5 - english name\n6 - plural word\n7 - min/max\n8 - has duplicates" << endl;
  20.     cin >> mode;
  21.     switch(mode){
  22.     case 1:
  23.         simple_math_int();
  24.         break;
  25.     case 2:
  26.         simple_math_double();
  27.         break;
  28.     case 3:
  29.         many_expressions();
  30.         break;
  31.     case 4:
  32.         point_coords();
  33.         break;
  34.     case 5:
  35.         english_name();
  36.         break;
  37.     case 6:
  38.         plural_word();
  39.         break;
  40.     case 7:
  41.         min_max();
  42.         break;
  43.     case 8:
  44.         duplicates();
  45.         break;
  46.     default:
  47.         cout << "Enter valid value idiot!";
  48.         break;
  49.     }
  50.     return 0;
  51. }
  52.  
  53. void simple_math_int(){
  54.     int num1, num2;
  55.     int addition, substraction, multiplication, division, modulo;
  56.     cout << "Enter two numbers: ";
  57.     cin >> num1 >> num2;
  58.     addition = num1+num2;
  59.     substraction = num1-num2;
  60.     multiplication = num1*num2;
  61.     cout << "Addition: " << addition << endl;
  62.     cout << "Substraction: " << substraction << endl;
  63.     cout << "Multiplication: " << multiplication << endl;
  64.     if(num2 != 0){
  65.         division = num1/num2;
  66.         modulo = num1%num2;
  67.         cout << "Division: " << division << endl;
  68.         cout << "Modulo: " << modulo << endl;
  69.     } else {
  70.         cout << "Only idiots try to divide by zero!" << endl;
  71.     }
  72. }
  73.  
  74. void simple_math_double(){
  75.     double num1, num2;
  76.     double addition, substraction, multiplication, division, modulo;
  77.     cout << "Enter two numbers: ";
  78.     cin >> num1 >> num2;
  79.     addition = num1+num2;
  80.     substraction = num1-num2;
  81.     multiplication = num1*num2;
  82.     cout << "Addition: " << addition << endl;
  83.     cout << "Substraction: " << substraction << endl;
  84.     cout << "Multiplication: " << multiplication << endl;
  85.     if(num2 != 0.0){
  86.         division = num1/num2;
  87.         cout << "Division: " << division << endl;
  88.     } else {
  89.         cout << "Only idiots try to divide by zero!" << endl;
  90.     }
  91. }
  92.  
  93. void many_expressions(){
  94.     int i1 = 2, i2 = 5, i3 = -3;
  95.     double d1 = 2.0, d2 = 5.0, d3 = -0.5;
  96.     cout << "i1 + i2 = " << i1 + i2 << endl;
  97.     cout << "i1 / i2 = " << i1 / i2 << endl;
  98.     cout << "i2 / i1 = " << i2 / i1 << endl;
  99.     cout << "i1 * i3 = " << i1 * i3 << endl;
  100.     cout << "d1 / d2 = " << d1 / d2 << endl;
  101.     cout << "d2 / d1 = " << d2 / d1 << endl;
  102.     cout << "d3 * d1 = " << d3 * d1 << endl;
  103.     cout << "d1 + i2 = " << d1 + i2 << endl;
  104.     cout << "i1 / d2 = " << i1 / d2 << endl;
  105.     cout << "d2 / i1 = " << d2 / i1 << endl;
  106.     cout << "i2 / d1 = " << i2 / d1 << endl;
  107.     cout << "i1 / i2 * d1 = " << i1 / i2 * d1 << endl;
  108.     cout << "d1 * i1 / i2 = " << d1 * i1 / i2 << endl;
  109.     cout << "d1 / d2 * i1 = " << d1/d2 * i1 << endl;
  110.     cout << "i1 * d1 / d2 = " << i1 * d1/d2 << endl;
  111.     cout << "i2 / i1 * d1 = " << i2/i1 * d1 << endl;
  112.     cout << "d1 * i2 / i1 = " << d1 * i2 / i1 << endl;
  113.     cout << "d2 / d1 * i1 = " << d2 / d1 * i1 << endl;
  114.     cout << "i1 * d2 / d1 = " << i1 * d2/d1 << endl;
  115. }
  116.  
  117. void point_coords_old(){
  118.     int x1, y1, x2, y2;
  119.     int mid_x,mid_y;
  120.     cout << "Enter first point: ";
  121.     cin >> x1 >> y1;
  122.     cout << "Enter second point: ";
  123.     cin >> x2 >> y2;
  124.     mid_x = (x1+x2)/2;
  125.     mid_y = (y1+y2)/2;
  126.     printf("New coords: (%d,%d)\n",mid_x,mid_y);
  127. }
  128.  
  129. void point_coords(){
  130.     char nawias, przecinek;
  131.     int x1, y1, x2, y2;
  132.     int mid_x,mid_y;
  133.     cout << "Enter first point: ";
  134.     cin >> nawias >> x1 >> przecinek >> y1 >> nawias;
  135.     cout << "Enter second point: ";
  136.     cin >> nawias >> x2 >> przecinek >> y2 >> nawias;
  137.     mid_x = (x1+x2)/2;
  138.     mid_y = (y1+y2)/2;
  139.     printf("New coords: (%d,%d)\n",mid_x,mid_y);
  140. }
  141.  
  142. void english_name(){
  143.     int number;
  144.     cout << "Enter number (1-5): ";
  145.     cin >> number;
  146.     if(number>5||number<0){
  147.         cout << "Enter valid number idiot!" << endl;
  148.     }
  149.     switch(number){
  150.         case 0: cout << "Zero\n"; break;
  151.         case 1: cout << "One\n"; break;
  152.         case 2: cout << "Two\n"; break;
  153.         case 3: cout << "Three\n"; break;
  154.         case 4: cout << "Four\n"; break;
  155.         case 5: cout << "Five\n"; break;
  156.         default: cout << "Unsupported number\n"; break;
  157.     }
  158. }
  159.  
  160. void plural_word(){
  161.     int number, number2;
  162.     cout << "Enter number: ";
  163.     cin >> number;
  164.     number2 = number%10;
  165.     if(number == 1){
  166.         cout << number << " tomato - " << number << " pomidor\n";
  167.     } else if(number2 >= 2 && number2 <= 4){
  168.         cout << number << " tomatoes - " << number << " pomidory\n";
  169.     } else {
  170.         cout << number << " tomatoes - " << number << " pomidorow\n";
  171.     }
  172. }
  173.  
  174. void min_max(){
  175.     int curnr, minnr, maxnr;
  176.     cout << "Enter five numbers:\n";
  177.     for(int i=0;i<5;i++){
  178.         cin >> curnr;
  179.         if(curnr > maxnr){
  180.             maxnr = curnr;
  181.         }
  182.         if(curnr < minnr){
  183.             minnr = curnr;
  184.         }
  185.     }
  186.     cout << "Min: " << minnr << "\nMax: " << maxnr << "\n";
  187. }
  188.  
  189. bool in_array(int* ary, int element, int elements){
  190.     for(int i=0;i<elements;i++){
  191.         if(ary[i] == element){
  192.             return true;
  193.         }
  194.     }
  195.     return false;
  196. }
  197.  
  198. void duplicates(){
  199.     int numbers[5];
  200.     int number;
  201.     bool has_duplicates = false;
  202.     cout << "Enter five numbers:\n";
  203.     for(int i=0;i<5;i++){
  204.         cin >> number;
  205.         if(in_array(numbers, number, 5)){
  206.             has_duplicates = true;
  207.         }
  208.         numbers[i] = number;
  209.     }
  210.     if(has_duplicates){
  211.         cout << "Has duplicates!\n";
  212.     } else {
  213.         cout << "No duplicates!\n";
  214.     }
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement