Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LesenSchreiben.cpp: Definiert den Einstiegspunkt für die Konsolenanwendung.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <locale>
- #include <fstream>
- using namespace std;
- void IntEingabe();
- void BoolCheck();
- void CharOutput();
- void WriteData();
- void ReadData();
- int main()
- {
- setlocale(LC_ALL, "German");
- IntEingabe();
- BoolCheck();
- CharOutput();
- WriteData();
- ReadData();
- system("pause");
- return 0;
- }
- void IntEingabe()
- {
- int int1, int2, int3;
- cout << "\n\nGeben Sie 3 Zahlenwerte ein: ";
- cout << "\nZahl 1: ";
- cin >> int1;
- cout << "\nZahl 2: ";
- cin >> int2;
- cout << "\nZahl 3: ";
- cin >> int3;
- const double result = int1 + int2 + int3;
- cout << "\nDas Ergebnis der Addition ist: " << result << endl << endl;
- }
- void BoolCheck()
- {
- bool boollist[3];
- cout << "\n\nGeben Sie 3 verschiedene Bool-Werte ein: [0/1] ";
- cout << "\nWert 1: ";
- cin >> boollist[0];
- cout << "\nWert 2: ";
- cin >> boollist[1];
- cout << "\nWert 3: ";
- cin >> boollist[2];
- int AnzahlTrue = 0, AnzahlFalse = 0;
- for (int i = 0; i < 3; i++)
- {
- if (boollist[i] == true)
- {
- AnzahlTrue++;
- }
- else
- {
- AnzahlFalse++;
- }
- }
- cout << "\nAnzahl True: " << AnzahlTrue;
- cout << "\nAnzahl False: " << AnzahlFalse << endl;
- }
- void CharOutput()
- {
- char charlist[3];
- cout << "\nGeben Sie 3 Zeichen (|, <, >, $ etc.) ein: " << endl;
- for (int i = 0; i <= 2; i++)
- {
- cout << "\nZeichen " << i+1 << ": ";
- cin >> charlist[i];
- }
- for(int j = 0; j < 3; j++)
- {
- cout << "\nDie eingegebenen Zeichen sind: \nZeichen " << j+1 << ": " << charlist[j] << endl << endl;;
- }
- }
- void WriteData()
- {
- ofstream Dat1;
- int intlist[3];
- //const string filepathold = "Datei1.txt";
- const string filepathnew = "C:/Users/timla/Desktop/Labor2/ZweiterVersuch/UnterZweiterVersuch/Datei1.txt";
- //Dat1.open(filepathold);
- Dat1.open(filepathnew);
- cout << "\nGeben Sie 3 Zahlen ein, die in die Datei gespeichert werden sollen.";
- for (int i = 0; i < 3; i++)
- {
- cout << "\nZahl " << i + 1 << ": ";
- cin >> intlist[i];
- }
- for (int j = 0; j < 3; j++)
- {
- Dat1 << intlist[j] << endl;
- }
- Dat1.close();
- }
- void ReadData()
- {
- ifstream Dat1;
- ofstream Dat2;
- int zeilenlaenge;
- int i = 0;
- int EnteredNumbers[3];
- //const string file1old = "Datei1.txt";
- const string file1new = "C:/Users/timla/Desktop/Labor2/ZweiterVersuch/UnterZweiterVersuch/Datei1.txt";
- //Dat1.open(file1old);
- Dat1.open(file1new);
- while (Dat1 >> zeilenlaenge)
- {
- EnteredNumbers[i] = zeilenlaenge;
- i++;
- }
- Dat1.close();
- //const string file2old = "Datei2.txt";
- const string file2new = "C:/Users/timla/Desktop/Labor2/ErsterVersuch/UnterErsterVersuch/Datei2.txt";
- Dat2.open(file2new);
- Dat2 << "Die eingegebenen Zahlen sind: ";
- for (int j = 0; j < 3; j++)
- {
- Dat2 << EnteredNumbers[j] << " ";
- }
- Dat2.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement