Unsere Programme 3

Prog: Sterne ohne Parameter

#include <iostream> // Standardbibliothek zur Ein- und Ausgabe wird eingebunden.
#include <conio.h>  //Zusätzliche Funktionen zur Ein- und Ausgabe auf der 
                    //Konsole werden eingebunden.
 
using namespace std; //Vereinfacht den Aufruf einer Funktion aus einer Bibliothek.
 
void sterne(){
 cout<< "\n**********\n";
}
 
 
int main(){
 sterne();
 cout<< "Einleitung:";
 sterne();
 cout<< "Hauptteil:";
 sterne();
 cout<< "Schluss:";
 sterne();
 
 getch();
 return 0;
}

Prog: Sterne mit Parameter

#include <iostream> // Standardbibliothek zur Ein- und Ausgabe wird eingebunden.
#include <conio.h>  //Zusätzliche Funktionen zur Ein- und Ausgabe auf der 
                    //Konsole werden eingebunden.
 
using namespace std; //Vereinfacht den Aufruf einer Funktion aus einer Bibliothek.
 
void sterne(int n){
 cout << endl;
 for (int i=1;i<=n;i++) cout << "*";
 cout << endl;
}
 
 
int main(){
 int anzahl;
 sterne(30);
 cout<< "Einleitung:";
 sterne(10);
 cout<< "Hauptteil:";
 sterne(10); 
 cout<< "Wieviele Sterne soll die letzte Zeile haben? "; cin >> anzahl; 
 cout<< "Schluss:";
 sterne(anzahl);
 
 getch();
 return 0;
}

Prog: Kreisfunktionen

#include <iostream> // Standardbibliothek zur Ein- und Ausgabe wird eingebunden.
#include <conio.h>  //Zusätzliche Funktionen zur Ein- und Ausgabe auf der 
                    //Konsole werden eingebunden.
#include <math.h>
 
using namespace std; //Vereinfacht den Aufruf einer Funktion aus einer Bibliothek.
 
void umfang(float r);
void inhalt(float r);
 
int main(){
 float radius;
 cout<<"Gib einen Radius ein! "; cin>>radius;
 umfang(radius); cout<<endl;
 inhalt(radius);
 
 getch();
 return 0;
}     
 
void umfang(float r){    
 cout << 2*r*M_PI;
}
 
void inhalt(float r){    
 cout << r*r*M_PI;
}

Prog: Winkelumrechnung

#include <iostream>    
#include <conio.h>     
using namespace std;   
 
void umwandeln(float ein, int &grad, int &min, int &sek);
 
int main()
{ float eingabe;
  int grad, minuten, sekunden;
  cout << "Dieses Programm rechnet Dezimalgrad in Grad, Minuten und Sekunden um!\n";
  cout << "Bitte geben Sie die Anzahl der Sekunden an: ";
  cin >> eingabe;
  umwandeln(eingabe, grad, minuten, sekunden);
  cout <<endl <<eingabe<<" Dezimalgrad sind "<<grad<<" Grad, "<<minuten<<" Minuten und "<<sekunden<<" Sekunden!";
 
  getch();
  return 0;
}
 
void umwandeln(float dezgrad, int &grad, int &min, int &sek)
{ float help;
  grad=(int)dezgrad;
  help=(dezgrad-grad)*60;
  min=(int)help;
  help=(help-min)*60;
  sek=(int)help;    
}

Prog: Quadratfunktion

#include <iostream>
#include <conio.h>
using namespace std;
 
 
float quadrat(float x);
 
int main() {
 float x,y;
 cout << "Dieses Programm berechnet dir die Quadrate einer Zahl!\n\n";
 cout << "x = "; cin >> x;
 y = quadrat(x); 
 cout << endl << "y = " << y ; 
 
 getch();
 return 0;
}
 
 
float quadrat(float x){
  float ergebnis;
  ergebnis = x*x;    
  return ergebnis;  
}

Prog: Tangensfunktion

#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;
 
 
float tangens(float w);
 
int main() {
 float winkel;
 cout << "Dieses Programm berechnet dir den Tangens  eines Winkels!\n\n";
 cout << "Winkel = "; cin >> winkel;
 if (((int)winkel%90 == 0) && ((int)winkel%180 != 0))
    cout << "Tangens nicht definiert!";
 else    
   if ((int)winkel%180 == 0) 
       cout << endl << "y = " << 0;
   else    
      cout << endl << "y = " << tangens(winkel) ; 
 
 getch();
 return 0;
}
 
 
float tangens(float w){
  float x = w*M_PI/180;
  // float ergebnis;
  // ergebnis = sin(x)/cos(x);
  // return ergebnis;  
 
  return sin(x)/cos(x);
}

Prog: Reichweite

#include <iostream>    
#include <conio.h>    
 
#include <math.h>                       
using namespace std;   
 
 
 
float gesamtverbrauch(float verbrauch, float strecke);
 
 
int main()  
{    system("COLOR F2");
    float s, v;
    cout<<"Dieses Programm berechnet die Gesamtmenge des Treibstoffverbrauchs.\n";
    cout<<"\nFahrstrecke ( in km ): ";cin>>s;
    cout<<"\nVerbrauch ( Liter / 100 km ): "; cin>>v;
    cout<<"\nDie Gesamtmenge des Treibstoffverbrauchs betraegt " <<gesamtverbrauch(v, s) <<" Liter"; 
 
 
    getch();         
}		       
 
 
float gesamtverbrauch(float verbrauch, float strecke)
{ float gv, help;
  help=verbrauch/100;
  gv=help*strecke;
  return gv;
}