Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. // LesenSchreiben.cpp: Definiert den Einstiegspunkt für die Konsolenanwendung.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <locale>
  7. #include <fstream>
  8.  
  9. using namespace std;
  10.  
  11. void IntEingabe();
  12. void BoolCheck();
  13. void CharOutput();
  14. void WriteData();
  15. void ReadData();
  16.  
  17. int main()
  18. {
  19. setlocale(LC_ALL, "German");
  20.  
  21. IntEingabe();
  22. BoolCheck();
  23. CharOutput();
  24. WriteData();
  25. ReadData();
  26.  
  27. system("pause");
  28. return 0;
  29. }
  30.  
  31. void IntEingabe()
  32. {
  33. int int1, int2, int3;
  34.  
  35. cout << "\n\nGeben Sie 3 Zahlenwerte ein: ";
  36.  
  37. cout << "\nZahl 1: ";
  38. cin >> int1;
  39.  
  40. cout << "\nZahl 2: ";
  41. cin >> int2;
  42.  
  43. cout << "\nZahl 3: ";
  44. cin >> int3;
  45.  
  46. const double result = int1 + int2 + int3;
  47.  
  48. cout << "\nDas Ergebnis der Addition ist: " << result << endl << endl;
  49. }
  50.  
  51. void BoolCheck()
  52. {
  53. bool boollist[3];
  54.  
  55. cout << "\n\nGeben Sie 3 verschiedene Bool-Werte ein: [0/1] ";
  56.  
  57. cout << "\nWert 1: ";
  58. cin >> boollist[0];
  59.  
  60. cout << "\nWert 2: ";
  61. cin >> boollist[1];
  62.  
  63. cout << "\nWert 3: ";
  64. cin >> boollist[2];
  65.  
  66. int AnzahlTrue = 0, AnzahlFalse = 0;
  67.  
  68. for (int i = 0; i < 3; i++)
  69. {
  70. if (boollist[i] == true)
  71. {
  72. AnzahlTrue++;
  73. }
  74. else
  75. {
  76. AnzahlFalse++;
  77. }
  78. }
  79.  
  80.  
  81. cout << "\nAnzahl True: " << AnzahlTrue;
  82. cout << "\nAnzahl False: " << AnzahlFalse << endl;
  83. }
  84.  
  85.  
  86. void CharOutput()
  87. {
  88. char charlist[3];
  89.  
  90. cout << "\nGeben Sie 3 Zeichen (|, <, >, $ etc.) ein: " << endl;
  91.  
  92. for (int i = 0; i <= 2; i++)
  93. {
  94. cout << "\nZeichen " << i+1 << ": ";
  95. cin >> charlist[i];
  96. }
  97.  
  98. for(int j = 0; j < 3; j++)
  99. {
  100. cout << "\nDie eingegebenen Zeichen sind: \nZeichen " << j+1 << ": " << charlist[j] << endl << endl;;
  101. }
  102.  
  103. }
  104.  
  105. void WriteData()
  106. {
  107. ofstream Dat1;
  108. int intlist[3];
  109.  
  110. //const string filepathold = "Datei1.txt";
  111. const string filepathnew = "C:/Users/timla/Desktop/Labor2/ZweiterVersuch/UnterZweiterVersuch/Datei1.txt";
  112.  
  113. //Dat1.open(filepathold);
  114. Dat1.open(filepathnew);
  115.  
  116. cout << "\nGeben Sie 3 Zahlen ein, die in die Datei gespeichert werden sollen.";
  117.  
  118. for (int i = 0; i < 3; i++)
  119. {
  120. cout << "\nZahl " << i + 1 << ": ";
  121. cin >> intlist[i];
  122. }
  123.  
  124. for (int j = 0; j < 3; j++)
  125. {
  126. Dat1 << intlist[j] << endl;
  127. }
  128.  
  129. Dat1.close();
  130. }
  131.  
  132. void ReadData()
  133. {
  134. ifstream Dat1;
  135. ofstream Dat2;
  136. int zeilenlaenge;
  137. int i = 0;
  138. int EnteredNumbers[3];
  139.  
  140. //const string file1old = "Datei1.txt";
  141. const string file1new = "C:/Users/timla/Desktop/Labor2/ZweiterVersuch/UnterZweiterVersuch/Datei1.txt";
  142.  
  143. //Dat1.open(file1old);
  144. Dat1.open(file1new);
  145.  
  146. while (Dat1 >> zeilenlaenge)
  147. {
  148. EnteredNumbers[i] = zeilenlaenge;
  149. i++;
  150. }
  151.  
  152. Dat1.close();
  153.  
  154. //const string file2old = "Datei2.txt";
  155. const string file2new = "C:/Users/timla/Desktop/Labor2/ErsterVersuch/UnterErsterVersuch/Datei2.txt";
  156.  
  157. Dat2.open(file2new);
  158.  
  159. Dat2 << "Die eingegebenen Zahlen sind: ";
  160.  
  161. for (int j = 0; j < 3; j++)
  162. {
  163. Dat2 << EnteredNumbers[j] << " ";
  164. }
  165.  
  166. Dat2.close();
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement