Advertisement
Randomsurpriseguy

Präsenz4

Dec 7th, 2020 (edited)
774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6.  
  7.  
  8.  
  9. struct Baum{
  10.   string Baumart;
  11.   double height;
  12.   int age;
  13.  
  14.   Baum(string artIn, double heightIn, int ageIn):Baumart(artIn),height(heightIn),age(ageIn){
  15.  
  16.  
  17.   }
  18.  
  19.   void print(){
  20.     cout << Baumart << "; " << height << "; " << age << ";" << endl;
  21.  
  22.   }
  23.  
  24.  
  25.  
  26. };
  27.  
  28. Baum pflanzen(){
  29.   string t;
  30.   double h;
  31.   int a;
  32.   cout << "Gebe Baumart an:";
  33.   cin >> t;
  34.   cout << "Gebe Baumhoehe an:";
  35.   cin >> h;
  36.   cout << "Gebe Baumalter an:";
  37.   cin >> a;
  38.   return Baum(t,h,a);
  39.  
  40. }
  41.  
  42.  
  43. void fibersteller(int n,int *azero, int a, int b){//Spielerei
  44.     *(azero)=a;
  45.     *(azero+1)=b;
  46.     for(int i=2;i<n;i++){
  47.       *(azero+i)=*(azero+i-1)+*(azero+i-2);
  48.     }
  49.     return;
  50. }
  51.  
  52.  
  53. bool fibonacciSequence(int length, int arr[]){
  54.   if(length<2) return true;
  55.   int i=2;
  56.   while(i<length){
  57.     if(arr[i-2]+arr[i-1]!=arr[i]) return false;
  58.     i++;
  59.   }
  60.   return true;
  61. }
  62.  
  63. void Aufgabe1(){
  64.   pflanzen().print();
  65. }
  66.  
  67. void Aufgabe2(){
  68.   char arr[9]={'.','.','.','.','.','.','.','.','.'};
  69.   int i=1;
  70.   int input=5;
  71.   while(true){
  72.     do{
  73.       cout << i++ << " ";
  74.     }while(i<10);
  75.     cout << endl;
  76.     i=0;
  77.     do{
  78.       cout << arr[i++] << " ";
  79.     }while(i<9);
  80.     i=1;
  81.     cout << endl;
  82.     cout << "Enter new x Position:";
  83.     cin >> input;
  84.     if(input >9 || input <1 ) break;
  85.     if(arr[input-1]=='x') arr[input-1]='.';
  86.     else arr[input-1]='x';
  87.   }
  88. }
  89.  
  90. void Aufgabe3(){
  91.   const static int n=5;
  92.   int arr[n]={1,2,3,5,7};
  93.   //fibersteller(n,&arr[0],1,1);
  94.  
  95.   if(fibonacciSequence(5, arr)) cout << "Fibonacci Sequenz" << endl;
  96.   else cout << "Nicht Fibonacci Sequenz" << endl;
  97. }
  98.  
  99. int main(){
  100.   Aufgabe3();
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement