You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			63 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Plaintext
		
	
			
		
		
	
	
			63 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Plaintext
		
	
using System;
 | 
						|
 | 
						|
namespace B_GOP01XX_AG_1
 | 
						|
{
 | 
						|
    // Aufgabenschritt 1 - Klassendefinition
 | 
						|
    class WallisschesProdukt {
 | 
						|
 | 
						|
        public double calcWP(int n) {
 | 
						|
 | 
						|
            double halfPI = 1.0;
 | 
						|
            double step = 1.0;
 | 
						|
 | 
						|
            for(double i = 1; i < Convert.ToDouble(n); i++, step++)
 | 
						|
            {
 | 
						|
              	if(i%2 == 0) halfPI *= (step / (step+1)); else halfPI *= ((step+1) / step);
 | 
						|
            }
 | 
						|
                                                      
 | 
						|
            return halfPI * 2.0;
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    // Aufgabenschritt 2 - Klassendefinition für benötigte Helfer
 | 
						|
    class Helper
 | 
						|
    {
 | 
						|
        public void adjustBuffer()
 | 
						|
        {
 | 
						|
            Console.BufferHeight = 2020;
 | 
						|
            Console.WriteLine("Die \"Pufferhöhe\" der Konsole beträgt nun {0} Zeilen.",Console.BufferHeight);
 | 
						|
        }
 | 
						|
 | 
						|
 | 
						|
        static int tableWidth = 77;
 | 
						|
        public void PrintLine()
 | 
						|
        {
 | 
						|
            Console.WriteLine(new string('-', tableWidth));
 | 
						|
        }
 | 
						|
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    // Aufgabenschritt 3 - Hauptprogramm
 | 
						|
    class Program { 
 | 
						|
 | 
						|
        static void Main(string[] args){
 | 
						|
 | 
						|
            WallisschesProdukt wp = new WallisschesProdukt();
 | 
						|
 | 
						|
            Helper testNow = new Helper();
 | 
						|
            testNow.adjustBuffer();
 | 
						|
 | 
						|
            Console.WriteLine(String.Format("{0, 0}{1,-5}{2, 0}{3, 0}","Faktor:","","","Walissches Produkt:"));
 | 
						|
 | 
						|
            for (int i = 1; i <= 1000; i++) {
 | 
						|
 | 
						|
                testNow.PrintLine();
 | 
						|
                Console.WriteLine(String.Format("|{0, 4} {1, -5}| {2, 5:F14} | {3, -8:F17} |{4, -5}|", " n =" , i , wp.calcWP(i), Math.Abs((wp.calcWP(i) - Math.PI)), "Abweichung in %"));
 | 
						|
            }
 | 
						|
 | 
						|
            testNow.PrintLine();      
 | 
						|
        }
 | 
						|
    }
 | 
						|
} |