mathiaspl20

Untitled

Nov 6th, 2019
92
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ----------------------------------------------
  2. // SEN UE2.3
  3. // ResistorColor.cpp
  4. // xxxxxxxxxxxxxxx
  5. // 5.11.2019
  6. // ----------------------------------------------
  7.  
  8. #include <iostream>
  9. #include <limits>
  10.  
  11. void ResistorColor(unsigned long long resistance);
  12.  
  13. int main()
  14. {
  15.     std::cout << "Geben sie einen Wiederstandswert zwischen 1 Ohm und 5 MOhm dessen Farbcode sie wissen moechten ein:";
  16.     unsigned long long x;
  17.     std::cin >> x;
  18.  
  19.     while (!std::cin) {     //iput valiadtion: if input does not match data type read input again
  20.         std::cout << "Das war keine ganze Zahl! Bitte geben sie eine ganze Zahl ein: ";
  21.         std::cin.clear();
  22.         std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  23.         std::cin >> x;
  24.     }
  25.  
  26.     ResistorColor(x);
  27. }
  28.  
  29. void ResistorColor(unsigned long long resistance)
  30. {
  31.     unsigned long long tmp = resistance;
  32.     char multiplier = 0;
  33.     int Field[3];
  34.     char pointer = 2;
  35.     char digit = 0;
  36.  
  37.     while (tmp % 10 == 0) {
  38.         multiplier++;
  39.         tmp = tmp / 10;
  40.     }
  41.     Field[pointer] = multiplier;        //writes # of zeros to last space of array
  42.     pointer--;
  43.  
  44.     for (char i = 1; i <= 2; i++) {     //writes digit 1, 2 to space pointer of array
  45.         digit = tmp % 10;
  46.         tmp = tmp / 10;
  47.         Field[pointer] = digit;
  48.         pointer--;
  49.     }
  50.     for (char a = 0; a <= 2; a++) {     //outputs color for each space of array
  51.         switch (Field[a]) {
  52.         case 0: std::cout << "schwarz ";
  53.             break;
  54.         case 1: std::cout << "braun ";
  55.             break;
  56.         case 2: std::cout << "rot ";
  57.             break;
  58.         case 3: std::cout << "orange ";
  59.             break;
  60.         case 4: std::cout << "gelb ";
  61.             break;
  62.         case 5: std::cout << "gruen ";
  63.             break;
  64.         case 6: std::cout << "blau ";
  65.             break;
  66.         case 7: std::cout << "violett ";
  67.             break;
  68.         case 8: std::cout << "grau ";
  69.             break;
  70.         case 9: std::cout << "weiss ";
  71.             break;
  72.         default: std::cout << "error - check input ";
  73.             break;
  74.         }
  75.         if (a < 2) {        //add dashes between colors
  76.             std::cout << "- ";
  77.         }
  78.     }
  79.     std::cout << "ist der Farbcode fuer einen " << resistance << " Ohm Wiederstand.";
  80. }
  81.  
  82. // ----------------------------------------------
  83. // SEN UE2.2
  84. // Primfaktorzerlegung.cpp
  85. // xxxxxxxxxxxxxx
  86. // 5.11.2019
  87. // ----------------------------------------------
  88.  
  89. #include <iostream>
  90. #include <limits>
  91. using namespace std;
  92.  
  93. void PrimeFactorization(int number);
  94.  
  95. int main()
  96. {
  97.     cout << "Geben sie eine Zahl ein deren Primfaktoren sie kennen moechten: ";
  98.     int x;
  99.     cin >> x;
  100.  
  101.     while (!cin) {      //inout valiadtion: if input does not match data type read input again
  102.         cout << "Das war keine ganze Zahl! Bitte geben sie eine ganze Zahl ein: ";
  103.         cin.clear();
  104.         cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  105.         cin >> x;
  106.     }
  107.     PrimeFactorization(x);
  108. }
  109.  
  110.  
  111. void PrimeFactorization(int number) {
  112.     unsigned int factor = 2;
  113.     cout << endl << "Eingabe: " << number;
  114.     if (number == 0 || number == 1) {
  115.         cout << endl << "Die Zahl " << number << " besitzt keine Primfaktoren.";
  116.     }
  117.     else {
  118.         cout << endl << "Ausgabe: ";
  119.         while (number != 1) {
  120.             while (number % factor > 0) {
  121.                 factor++;
  122.             }
  123.             if (!(number == factor)) {
  124.                 cout << factor << ", ";     //if is not equal to number add ", " after output
  125.             }
  126.             else {
  127.                 cout << factor;
  128.             }
  129.             number = number / factor;
  130.         }
  131.     }
  132. }
RAW Paste Data