Namespace

Files at this revision

API Documentation at this revision

Comitter:
stefanblack
Date:
Sun Apr 12 23:58:05 2020 +0000
Commit message:
1

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Apr 12 23:58:05 2020 +0000
@@ -0,0 +1,76 @@
+/*
+
+C++ Kurs 6ABELI  SM
+Aufgabe 1 Namespace
+Stefan Schwarz
+
+*/
+#include <stdio.h>
+#define _USE_MATH_DEFINES 
+#include <cmath>
+#include <iostream>
+
+using namespace std;
+
+namespace Schwarz {                 //namespace created 
+    enum angular { y, n };
+
+    class Circle {                  //new class named "Circle"
+    private:                        //Private variables listed below
+        float m_radius;             //radius
+        angular is_angular;         // enumaration "yes" or "no"
+
+    public:                         //public vaariables listed below
+        float getscope();           //calculating circle's scope
+        float getsurface();         //calculating circle's surface
+        string status_angular();    //declare if it is anfular or not
+        Circle(float radius);
+        Circle(bool angular);
+    };
+
+    //constructor for radius
+    Circle::Circle(float radius) {
+        m_radius = radius;
+    }
+
+    //constructor for radius
+    Circle::Circle(bool angular) {
+        is_angular = (angular == false) ? n : y;
+    }
+    //calculating circle's scope   
+    float Circle::getscope()
+    {
+        return (2 * m_radius * M_PI);
+    }
+    //calculating circle's surface           
+    float Circle::getsurface()
+    {
+        return(m_radius * m_radius * M_PI);
+    }
+
+    //angular or not 
+    string Circle::status_angular() {
+        string output;
+        output = (is_angular == n) ? "no" : " yes";
+        return output;
+    }
+}
+
+
+
+/*
+
+Main-program:
+
+*/
+int main()
+{
+    Schwarz::Circle newCircle(1.2f); //Initialising Circle with given float-parameters
+    Schwarz::Circle Corners(false);  //Initialising Circle with given bool-parameters 
+
+    cout << "Calculated scope is: " << newCircle.getscope() << "cm" << endl;        //output scope 
+    cout << "Calculated surface is: " << newCircle.getsurface() << "cm^2" << endl;  //output surface
+    cout << "Corners? " << Corners.status_angular() << endl;                        //output angular or not
+
+    return 0;
+}
\ No newline at end of file