mirror of
https://inf-git.fh-rosenheim.de/studavrije7683/cplusplus-training.git
synced 2025-04-18 13:09:56 +00:00
completet chapter 5
This commit is contained in:
parent
d6287d6002
commit
d76e6b7ffc
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"iterator": "cpp"
|
"iterator": "cpp",
|
||||||
|
"iostream": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,7 +19,7 @@ int* ret_array2(){
|
|||||||
int main(){
|
int main(){
|
||||||
|
|
||||||
int new_array[10];
|
int new_array[10];
|
||||||
ret_array(new_array,10); //Array is already a pointer, pointing to the first element;
|
ret_array(new_array,10); // But handled as a normal pointer we loose the array size
|
||||||
for(int i:new_array)
|
for(int i:new_array)
|
||||||
cout <<"Number "<<i<<endl;
|
cout <<"Number "<<i<<endl;
|
||||||
|
|
||||||
|
41
Teil_1/5. Felder/Uebung 2 - Fahrenheit in Celsius.cpp
Normal file
41
Teil_1/5. Felder/Uebung 2 - Fahrenheit in Celsius.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
const int kEauationVal = 32;
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void getVal(const char text[], T *val);
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
float fahrenheit = 0, schritt_weite = 0, maximal_wert = 0;
|
||||||
|
float celsiusBuf[10];
|
||||||
|
cout << "Eingabe\n\n";
|
||||||
|
getVal("Fahrenheit", &fahrenheit);
|
||||||
|
cout << "\nAusgabe\n\n";
|
||||||
|
|
||||||
|
for (int i = 0; i <10; i++)
|
||||||
|
{
|
||||||
|
celsiusBuf[i] = ((fahrenheit+i*10 - kEauationVal) * 5) / 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i <10; i++){
|
||||||
|
cout<<"Fahrenheit: "<<(fahrenheit+10*i)<<" --> Celsius: "<< celsiusBuf[i]<<endl;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void getVal(const char text[], T *val)
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
cout << "\t" << text << " = ";
|
||||||
|
if (cin.fail())
|
||||||
|
{
|
||||||
|
cin.clear();
|
||||||
|
cin.ignore();
|
||||||
|
}
|
||||||
|
cin >> *val;
|
||||||
|
} while (cin.fail() || *val <= 0);
|
||||||
|
}
|
BIN
Teil_1/5. Felder/Uebung 2 - Fahrenheit in Celsius.exe
Normal file
BIN
Teil_1/5. Felder/Uebung 2 - Fahrenheit in Celsius.exe
Normal file
Binary file not shown.
34
Teil_1/5. Felder/Uebung 3 - Sortieren.cpp
Normal file
34
Teil_1/5. Felder/Uebung 3 - Sortieren.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
void sortieren(string *namen, int size);
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
string namen[5];
|
||||||
|
cout << "Bitte geben Sie 5 Namen ein:" << endl;
|
||||||
|
for (int i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
cout << "Name " << i + 1 << ": ";
|
||||||
|
cin >> namen[i];
|
||||||
|
}
|
||||||
|
sortieren(namen, 5);
|
||||||
|
for(string name:namen)
|
||||||
|
cout<<name<<endl;
|
||||||
|
system("PAUSE");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sortieren(string *namen, int size)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < size - 1; i++)
|
||||||
|
{
|
||||||
|
for (int j = i + 1; j < size; j++)
|
||||||
|
if (namen[i] > namen[j])
|
||||||
|
{
|
||||||
|
string tempName = namen[i];
|
||||||
|
namen[i] = namen[j];
|
||||||
|
namen[j] = tempName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
Teil_1/5. Felder/Uebung 3 - Sortieren.exe
Normal file
BIN
Teil_1/5. Felder/Uebung 3 - Sortieren.exe
Normal file
Binary file not shown.
35
Teil_1/5. Felder/Uebung 4 - Bubble Sort.cpp
Normal file
35
Teil_1/5. Felder/Uebung 4 - Bubble Sort.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
void bubbleSort(int *array, int size)
|
||||||
|
{
|
||||||
|
for (int n = size; n > 1; n--)
|
||||||
|
for (int i = 0; i < n - 1; i++)
|
||||||
|
if (array[i] > array[i + 1])
|
||||||
|
{
|
||||||
|
int swap = array[i];
|
||||||
|
array[i] = array[i + 1];
|
||||||
|
array[i + 1] = swap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void printArray(int *array, int size)
|
||||||
|
{
|
||||||
|
cout << "->";
|
||||||
|
for (int i = 0; i < size; i++)
|
||||||
|
cout << array[i] << (i == size - 1 ? "" : ";");
|
||||||
|
cout<<"\n\n";
|
||||||
|
}
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
srand(time(NULL));
|
||||||
|
int numbers[100];
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
numbers[i] = rand() % 100 + 1;
|
||||||
|
}
|
||||||
|
printArray(numbers, 100);
|
||||||
|
bubbleSort(numbers, 100);
|
||||||
|
printArray(numbers, 100);
|
||||||
|
}
|
BIN
Teil_1/5. Felder/Uebung 4 - Bubble Sort.exe
Normal file
BIN
Teil_1/5. Felder/Uebung 4 - Bubble Sort.exe
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user