Skip to content

Instantly share code, notes, and snippets.

@d8ta
Last active December 25, 2015 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save d8ta/7013675 to your computer and use it in GitHub Desktop.
Save d8ta/7013675 to your computer and use it in GitHub Desktop.
using System;
namespace bsp11
{
class MainClass
{
public static void Main (string[] args)
{
/* 1.(2P) Schreibe ein Programm, das die Fü̈llmenge eines liegenden Kreiszylinders berechnet (Formel siehe Wikipedia, Tank-Problem).
* Eingabe: L (Länge) in mm, r (Radius) in mm, h (Füllhöhe) in mm, jeweils als Fließkommazahl.
*
* • Verwende die Methoden Math.Acos und Math.Sqrt.
* • Verwende jeweils Schleifen, um jeweils eine ungültige Eingabe (z.B. 0 oder negative Werte) abzuweisen, und vom Benutzer eine neue Eingabe dieser Zahl einzufordern.
* • Teste das Programm mit den Werten einer Limonaden-, Energydrink-, Bierdose, etc. Ausgabe in Milliliter (ml).
* • Protokolliere deine Tests, indem du die Konsolenausgabe als Kommentar im Quellcode speicherst. Verwendegroßzü̈gig Hilfsvariablen für Zwischenergebnisse, um
* die Übersicht zu bewahren.
*/
/* 330- und 500-ml-Getränkedosen haben einen Durchmesser von 67 mm. Die Höhe der 330-ml-Variante beträgt 115 mm, die der 500-ml-Variante 168 mm
* Energy-Drinks: 250 ml; Durchmesser von 57 mm und eine Höhe von 135 mm.
* und seit 2009 in 473 ml (63 mm x 180 mm). Seit 2006 wird in Deutschland jedoch, hauptsächlich von Coca-Cola, vermehrt die sogenannte 330 ml Sleek Can angeboten.
* Sie ist schmaler und höher als die klassische 330-ml-Dose, hat einen Durchmesser von 58 mm und eine Höhe von 146 mm.
*/
// let the user choose a cantype
Console.WriteLine ("type in the length, radius an filling height (all in millimeter). \n" +
"The programm will tell you the volum of the can! \n\n");
Console.WriteLine ("length of the can:");
String userLength = Console.ReadLine ();
double length = double.Parse(userLength);
Console.WriteLine ("radius of the can:");
String userRadius = Console.ReadLine ();
double radius = double.Parse(userRadius);
Console.WriteLine ("filling heigth of the can:");
String userFillingHeight = Console.ReadLine ();
double fillingHeight = double.Parse(userFillingHeight);
// Calculation for the can with the following formula:
// V = r^2 * L (arccos (r-h / r) - (r-h) wurzel 2rh-h^2 / r^2)
double root = Math.Sqrt(((2 * radius * fillingHeight) - (fillingHeight * fillingHeight)) / (radius * radius));
double volume = (radius * radius * length) * ((Math.Acos((radius - fillingHeight) / radius) - (radius - fillingHeight) * root));
volume = volume / 1000;
// print the volume to the console
Console.WriteLine("Volume of the can: {0:####.##}",volume);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment