sources:


website:
more info here
studies/bauelemente/Softwarebauelemente-CodeM1/M01_1/M01_1.cpp
download file

  1 ///////////////////////////////////////////////////////////
  2 // Softwarebauelemente I, Aufgabe M1.1
  3 //
  4 // author: Stephan Brumme
  5 // last changes: October 14, 2000
  6
  7
  8 // include I/O-streams and math library (we use sin())
  9 #include <iostream.h>
 10 #include <math.h>
 11
 12 // define pi (11 digits should be enough)
 13 const double pi = 3.1415926535;
 14
 15
 16 // calculate the area of a n-angled surface
 17 void AreaNEdges()
 18 {
 19     // amount of edges
 20     unsigned int nEdges;
 21     // radius
 22     double dRadius;
 23     // surface area
 24     double dArea;
 25
 26     // read edges
 27     cout<<"Ecken: ";
 28     cin>>nEdges;
 29
 30     // read radius
 31     cout<<"Umkreisradius: ";
 32     cin>>dRadius;
 33
 34     // calculate surface area using the given formula
 35     dArea = (double)nEdges*0.5 * dRadius*dRadius * sin(2*pi/(double)nEdges);
 36
 37     // print result
 38     cout<<"Ein "<<nEdges<<"-Eck mit einem Umkreisradius von "<<dRadius         <<" hat einen Flaecheninhalt von "<<dArea<<".\n\n";
 39 }
 40
 41
 42 // calculate the volume of a cone stub
 43 void VolumeConeStub()
 44 {
 45     // height of the stub
 46     double dHeight;
 47     // radius'
 48     double dRadius1;
 49     double dRadius2;
 50     // volume
 51     double dVolume;
 52
 53     // get height
 54     cout<<"Height of the cone stub: ";
 55     cin>>dHeight;
 56
 57     // get both radius'
 58     cout<<"Radius 1: ";
 59     cin>>dRadius1;
 60     cout<<"Radius 2: ";
 61     cin>>dRadius2;
 62
 63     // calculate volume using the given formula
 64     dVolume = (pi*dHeight/3.0) * (dRadius1*dRadius1 + dRadius1*dRadius2 + dRadius2*dRadius2);
 65
 66     // print result
 67     cout<<"Ein gerader Kreiskegelstumpf der Hoehe "<<dHeight<<" mit den Radien "<<dRadius1         <<" und "<<dRadius2<<" hat ein Volumen von "<<dVolume<<".\n\n";
 68 }
 69
 70
 71 // calculate the arithmetic average of a data set
 72 void ArithmeticAverage()
 73 {
 74     // size of data set
 75     unsigned int nAmount;
 76     // data set
 77     double *arData;
 78     // result
 79     double  dAverage;
 80
 81     // get size of data set
 82     cout<<"Von wievielen Zahlen soll das arithmetische Mittel berechnet werden: ";
 83     cin>>nAmount;
 84
 85     // allocate memory on heap to store the data set
 86     arData = new double[nAmount];
 87
 88     // read data set
 89     for (unsigned int nLoop=0; nLoop<nAmount; nLoop++)
 90     {
 91         cout<<"Wert "<<nLoop+1<<": ";
 92         cin>>arData[nLoop];
 93     }
 94
 95     // sum up the data
 96     dAverage = 0;
 97     for (nLoop=0; nLoop<nAmount; nLoop++)
 98         dAverage += arData[nLoop];
 99     // divide by size of data set
100     dAverage /= nAmount;
101
102     // print result
103     cout<<"Das arithmetische Mittel dieser Werte ist "<<dAverage<<".\n\n";   
104 }
105
106
107 // main function
108 void main()
109 {
110     AreaNEdges();
111     VolumeConeStub();
112     ArithmeticAverage();
113 }
114