Buch Cover Buch Cover Buch Cover Buch Cover

Web-Code: - Webcode Help

Eisenwarenhändler (Anweisungen und Abfolgen)

Ein Händler verlangt für seine Waren folgende Preise:

7 Cent pro Schraube (engl. screw)

4 Cent pro Mutter (engl. screw nut)

2 Cent pro Unterlegscheibe (engl. grommet)

Schreiben Sie ein Programm namens PriceCalculator, das vom Anwender die Anzahl der Schrauben, Muttern und Unterlegscheiben erfragt und dann den Gesamtbetrag berechnet und ausgibt.

0 Kommentare

Bitte melde dich an um einen Kommentar abzugeben

26 Lösung(en)

package ch.programmieraufgaben.sequenz;

import static eu.gressly.io.utility.Input.*;

public class Eisenwarenhaendler {

	public static void main(String[] args) {
		new Eisenwarenhaendler().top();
	}

	void top() {
		setAddQuestion("Bitte Anzahl %s eingeben: ");
		int anzSchrauben = inputInt("Schrauben"        );
		int anzMuttern   = inputInt("Muttern"          );
		int anzScheiben  = inputInt("Unterlagsscheiben");
		double preisSchrauben = 7 * anzSchrauben;
		double preisMuttern   = 4 * anzMuttern  ;
		double preisScheiben  = 2 * anzScheiben ;
		
		double total = preisSchrauben + preisMuttern + preisScheiben;
		
		System.out.println("Der Einkauf kostet total " + total + " Cent.");
	}
}
 // end of class Eisenwarenhaendler


//////////////////////////////////////////////
// Folgende Hilfsklasse:

package eu.gressly.io.utility;

import java.util.Scanner;

/**
 * Input Methods like the BASIC INPUT (or c's scanf()). 
 * 
 * Because Java has no simple console input, I added this functions to
 * my library.
 * Simply import
 * <code>import static eu.gressly.io.utility.Input.*</code>
 * and then use
 * <code>int x = inputInt("Please enter x: ");</code>
 * 
 * @version 0.1 (Oct 8, 2014)
 * @author Philipp Gressly Freimann 
 *         (philipp.gressly@santis.ch)
 */

public class Input {

	private static Scanner sc = new Scanner(System.in);

	/**
	 * @see setAskAgain();
	 */
	private static boolean askAgain = true;


	/**
	 * @see setAddQuestion()
	 */
	private static String addQuestion = "";


	/**
	 * @see setNumberFormatError()
	 */
	private static String numberFormatErrorMessage = "Error entering a number.";


	/**
	 * If askAgain is false, the user is asked only once.
	 * Entering newlines do not ask the user again showing the "question".
	 * default: true
	 * @param askAgain
	 */
	public static void setAskAgain(boolean askAgain) {
		Input.askAgain = askAgain;
	}


	/**
	 * If the programmer only wants to ask for a "value" instead of a
	 * "question", this text has to be set.
	 * Typically: setAddQuestion("Please enter the value for %s : ");
	 * "%s" is replaced by the programmers question afterwards.
	 * @param addQuestion has to contain a %s, where the parameter name
	 *        sohuld be replaced.
	 */
	public static void setAddQuestion(String addQuestion) {
		if(addQuestion.indexOf("%s") < 0) {
			addQuestion = addQuestion + "%s";
		}

		Input.addQuestion = addQuestion;
	}


	/**
	 * This message is shown to the user, if she/he does not enter a
	 * number while using "intputInt()" or "inputDouble()".
	 * @param errorMessage to show on NumberFormatExceptions.
	 */
	public static void setNumberFormatError(String errorMessage) {
		Input.numberFormatErrorMessage = errorMessage;
	}


	private static void quest(String question) {
		if(null == addQuestion || addQuestion.length() < 1) {
			System.out.println(question);
			return;
		}
		System.out.printf(addQuestion, question);
	}


	public static String inputString(String frage) {
		String eingabe = "";
		if(! askAgain) {
			quest(frage);
		}
		while(eingabe.length() < 1) {
			if(askAgain) {
				quest(frage);
			}
			eingabe = sc.nextLine().trim();
		}
		return eingabe;
	}



	public static byte inputByte(String question) {
		return (byte) inputNumber(question, byte.class);
	}


	public static short inputShort(String question) {
		return (short) inputNumber(question, short.class);
	}


	public static int inputInt(String question) {
		return (int) inputNumber(question, int.class);
	}


	public static long inputLong(String question) {
		return (long) inputNumber(question, long.class);
	}


	public static float inputFloat(String question) {
		return (float) inputNumber(question, float.class);
	}


	public static double inputDouble(String question) {
		return (double) inputNumber(question, double.class);
	}



	/**
	 * Input a single char.
	 * Any further chars on the same line are ignored.
	 */
	public static char inputChar(String question) {
		return inputString(question).trim().charAt(0);
	}


	/**
	 * Returns true, if the users input does not start with the letter 'n'.
	 * @param question any Question having "yes" or "no" as answer.
	 * @return true iff the users answer does not start with an "n".
	 */
	public static boolean inputBoolean(String question) {
		return 'n' != inputString(question).trim().toLowerCase().charAt(0);
	}


	private static String inputString() {
		String eingabe = "";
		while(eingabe.length() < 1) {
			eingabe = sc.nextLine().trim();
		}
		return eingabe;
	}


	private static Number inputNumber(String question, Object numberClass) {
		String answer = "";
		if(! askAgain) {
			answer = inputString(question);
		}
		while (true) {
			try {	
				if(askAgain) {
					answer = inputString(question);
				} 
				Number zahl = 0; // will be chaged soon...
				if(numberClass == byte.class) {
					zahl = Byte.parseByte(answer);
				}
				if(numberClass == short.class) {
					zahl = Short.parseShort(answer);
				}
				if(numberClass == int.class) {
					zahl = Integer.parseInt(answer);
				}
				if(numberClass == long.class) {
					zahl = Long.parseLong(answer);
				}
				if(numberClass == float.class) {
					zahl = Float.parseFloat(answer);
				}
				if(numberClass == double.class) {
					zahl = Double.parseDouble(answer);
				}
				return zahl;
			} catch (Exception ex) {
				System.out.println(numberFormatErrorMessage);
				if(!askAgain) {
					answer = inputString();
				}
			}
		}
	}

} // end of class Input
                

Lösung von: Philipp G. Freimann (BBW (Berufsbildungsschule Winterthur) https://www.bbw.ch)

<?php
class cEisenwarenhaendler {
	private $anzScrew;
	private $anzScrewnut;
	private $anzGrommet;
	private $priceScrew = 7; // in Cent
	private $priceScrewnut = 4; // in Cent
	private $priceGrommet = 2; // in Cent
	private $priceAll = 0;
		
	// Constructor
	function cEisenwarenhaendler($s, $sn, $g) {
		
		if(is_int($s)) { 
			$this->setAnzScrew($s);
		}else {
			$this->setAnzScrew(0);
		}	
		
		if(is_int($sn)) {
			$this->setAnzScrewnut($sn);
		}else {
			$this->setAnzScrewnut(0);
		}
		
		if(is_int($g)) {
			$this->setAnzGrommet($g);
		}else {
			$this->setAnzGrommet(0);
		}	
		
		// Calculation spend
		$this->Calculation_spend();
	}
	
	//Getter and Setter
	private function setAnzScrew($s) {
		$this->anzScrew = $s;
	}
	public function getAnzScrew() {
		return $this->anzScrew;
	}
	private function setAnzScrewnut($sn) {
		$this->anzScrewnut = $sn;
	}
	public function getAnzScrewnut() {
		return $this->anzScrewnut;
	}
	private function setAnzGrommet($g) {
		$this->anzGrommet = $g;
	}
	public function getAnzGrommet() {
		return $this->anzGrommet;
	}
	
	// Calculation
	private function getPriceScrew() {
		return $this->anzScrew * $this->priceScrew;
	}
	private function getPriceScrewnut() {
		return $this->anzScrewnut * $this->priceScrewnut;
	}
	private function getPriceGrommet() {
		return $this->anzGrommet * $this->priceGrommet;
	}
	private function getPriceAll() {
		return $this->getPriceScrew() + $this->getPriceScrewnut() + $this->getPriceGrommet();
	}
	
	// Calculation spend
	private function Calculation_spend() {
		echo '<table style="border: 1px dotted black; border-collapse:collapse">';
		echo '<tr>
				<th>Product</th>
				<th>Quantity</th>
				<th>Single price</th>
				<th>Whole price</th>
				</tr>
		';
		echo '<tr>
				<td>Screw</td>
				<td>'.$this->getAnzScrew().'</td>
				<td>'.$this->priceScrew.'&nbsp;Cent</td>
				<td>'.$this->getPriceScrew().'&nbsp;Cent</td>
				</tr>
		';
		echo '<tr>
				<td>Screw Nut</td>
				<td>'.$this->getAnzScrewnut().'</td>
				<td>'.$this->priceScrewnut.'&nbsp;Cent</td>
				<td>'.$this->getPriceScrewnut().'&nbsp;Cent</td>
				</tr>
		';
		echo '<tr>
				<td>Screw Nut</td>
				<td>'.$this->getAnzGrommet().'</td>
				<td>'.$this->priceGrommet.'&nbsp;Cent</td>
				<td>'.$this->getPriceGrommet().'&nbsp;Cent</td>
				</tr>
		';
		echo '<tr>
				<td colspan="3" >total sum:</td>
				<td>'.$this->getPriceAll().'&nbspCent</td>
				</tr>
		';
		echo '</table>';
	}
}

$eh = new cEisenwarenhaendler(50, 50, 50);
?>
                

Lösung von: Name nicht veröffentlicht

"""author= Cromewell """


def PriceCalculator(schrauben, muttern, unterlegscheiben):
    Schraube= 7
    Mutter= 4
    Unterlegscheibe= 2
    gesamt= schrauben*Schraube+muttern*Mutter+unterlegscheiben*Unterlegscheibe
    print(gesamt)

"""Beispiel:"""

PriceCalculator(5, 5, 5)

"""Ausgabe: 65  (5*7=35, 5*4=20, 5*2=10: 35+20+10=65)"""
                

Lösung von: Name nicht veröffentlicht

import java.util.Scanner;

public class EisenHaendler {
	public static void main (String[]args) {
		 Scanner in = new Scanner(System.in);
		 
		 double n1;
		 double n2;
		 double n3;
		
		 System.out.println("Gib die Anzahl der gewünschten Schrauben ein: ");
		 n1 = in.nextInt();
		 
		 System.out.println("Gib die Anzahl der gewünschten Muttern ein: ");
		 n2 = in.nextInt();
		 
		 System.out.println("Gib die Anzahl der gewünschten Unterlegscheiben ein: ");
		 n3 = in.nextInt();
		 
		 double pSchraube = 0.07*n1;
		 double pMutter = 0.04*n2;
		 double pUnterlegscheibe = 0.02*n3;
		 double Gesamtbetrag = pSchraube + pMutter + pUnterlegscheibe;
		 
		 System.out.println("Ihr Gesamtbetrag: " +(float)Gesamtbetrag +"€");
		 
	}
}

                

Lösung von: Butrint Pacolli ()

#Schraubenprogramm mit GUI

import tkinter as tk


def rechne():
    
    summe = int(schrauben_entry.get()) * int(preis_schraube.get())+int(muttern_entry.get())*int(preis_mutter.get())+int(unterleg_entry.get())*int(preis_unterleg.get())
    ergebnis_in_euro = summe/100
    ergebnis = str(str(summe)+ str(" Cent") +str ("\n")+str(ergebnis_in_euro)+str(" Euro"))
    summe_label.config(text = ergebnis)

    
main = tk.Tk()

frame1 = tk.Frame(main, relief = "groove", bg = "blue", border = 2, padx = 5, pady= 5)
frame1.grid(padx = 5, pady = 5, sticky = "w")
frame2 = tk.Frame(main,relief = "groove", bg = "red", border = 2, padx = 5, pady = 5)
frame2.grid(padx = 5, pady = 5, sticky = "w")
frame3 = tk.Frame(main, relief = "groove", bg = "green", border = 2, padx = 5, pady = 5)
frame3.grid(padx = 5, pady = 5, sticky = "w")

schrauben = tk.LabelFrame(frame1, text = "Anzahl der Schrauben")
schrauben.grid(padx = 5, pady = 5, sticky = "w")
schrauben_entry = tk.Entry(schrauben,width = 5)
schrauben_entry.grid(padx = 5, pady = 5, sticky = "w")


preis_schraube_label = tk.LabelFrame(frame1, text = "Preis in Cent")
preis_schraube_label.grid(padx = 5, pady = 5, sticky = "w")
preis_schraube = tk.Entry(preis_schraube_label, width = 5)
preis_schraube.grid(padx = 5, pady = 5, sticky = "w")
preis_schraube.insert(0,7)

muttern = tk.LabelFrame(frame2, text = "Anzahl der Muttern")
muttern.grid()
muttern_entry = tk.Entry(muttern, width = 5)
muttern_entry.grid(padx = 5, pady = 5, sticky = "w")
preis_mutter_label = tk.LabelFrame(frame2, text = "Preis in Cent")
preis_mutter_label.grid(padx = 5, pady = 5, sticky = "w")
preis_mutter = tk.Entry(preis_mutter_label, width = 5)
preis_mutter.grid(padx = 5, pady = 5, sticky = "w")
preis_mutter.insert(0, 4)

unterleg = tk.LabelFrame(frame3, text =  "Anzahl der Unterlegscheiben")
unterleg.grid(padx = 5, pady = 5, sticky = "w")
unterleg_entry = tk.Entry(unterleg, width = 5)
unterleg_entry.grid(padx = 5, pady = 5, sticky = "w")

preis_unterleg_label = tk.LabelFrame(frame3, text = "Preis in Cent")
preis_unterleg_label.grid(padx = 5, pady = 5, sticky = "w")
preis_unterleg = tk.Entry(preis_unterleg_label, width = 5)
preis_unterleg.grid(padx = 5, pady = 5, sticky = "w")
preis_unterleg.insert(0,2)


summe_label = tk.Label(frame3, text = "              ")
summe_label.grid(padx = 5, pady = 5)


rechner_button = tk.Button(frame3, text = "Berechne", command = rechne)
rechner_button.grid(padx = 5, pady = 5)





main.mainloop()

                

Lösung von: Py Thon ()

#include <iostream>


int main(int argc, char** argv) {
	int schraube;
	int mutter;
	int unterlegscheibe;
	int schraube2;
	int mutter2;
	int unterlegscheibe2;
	int preis;
	{
	
	printf ("Preise:\n schraube 7 cent\n mutter 4 cent\n unterlegscheibe 2 cent\n ");
	printf ("wie viele schrauben moechtest du haben?");
	scanf("%d",&schraube);
	fflush(stdin);
	printf ("wie viele Muttern moechtest du haben?");
	scanf(("%d"),&mutter);
	printf ("wie viele Unterlegscheiben moechten sie haben");
	scanf("%d",&unterlegscheibe);
	fflush(stdin);
	schraube2=schraube*7;
	mutter2=mutter*4;
	unterlegscheibe2=unterlegscheibe*2;
	preis=schraube2+mutter2+unterlegscheibe2;
	}
	printf ("der Preis ist %d cent",preis);
	return 0;
	
}
                

Lösung von: Name nicht veröffentlicht

<script type="text/javascript">
	var screw = prompt('Wieviele Schrauben?');
	var screw_nut = prompt('Wieviele Muttern?');
	var grommet = prompt('Wieviele Unterlegsscheiben?');
	screw = screw * 0.07;
	screw_nut = screw_nut * 0.04;
	grommet = grommet * 0.02;

	var alles = screw + screw_nut + grommet;
	document.write(alles.toFixed(2));
</script>
                

Lösung von: MSM Programming ()

screw_price = int(7)
screw_nut_price = int(4)
grommet_price = int(2)

print ("Wilkommen beim Eisenhaendler-Rechner!")
screw_count = int(input ("Anzahl Schrauben: "))
screw_nut_count = int(input ("Anzahl Muttern: "))
grommet_count = int(input ("Anzahl Unterlegscheiben: "))

price = screw_count * screw_price + screw_nut_count * screw_nut_price + grommet_count * grommet_price
print ("Gesamtpreis: ", float(price)/100, "Euro")
                

Lösung von: Name nicht veröffentlicht

#!/usr/bin/perl -w 
use strict;
use warnings;

my ( $screw, $nut, $grommet );

print "How many Screws do you need? "; 
chomp( $screw = <STDIN> );

print "How many Nuts do you need? ";
chomp( $nut = <STDIN> );

print "How many Grommets do you need? "; 
chomp( $grommet = <STDIN> );

my $priceScrew = 0.07;
my $priceNut = 0.04;
my $priceGrommet = 0.02;

# Falls nichts eingegeben wird
$screw = 0 if $screw eq "";
$nut = 0 if $nut eq "";
$grommet = 0 if $grommet eq "";

my $total = ( $screw * $priceScrew ) + ( $nut * $priceNut ) + 
( $grommet * $priceGrommet );

print "---" x 15 . "\n";
print "Your total is: " .  $total . "€ \n";
print "---" x 15 . "\n";

                

Lösung von: Mister iC ()

#Currency: Cent
price_screw = 7
price_nut = 4
price_grommet = 2
#Calculator
def calc(s,n,g):
    global price_screw
    global price_nut
    global price_grommet
    price = int(price_screw)*int(amount_screw)+int(price_nut)*int(amount_nut)+int(price_grommet)*int(amount_grommet)
    print("Es kostet insgesamt "+str(price)+" Cent")
#main
print("PriceCalcutlator\n\n")
amount_screw = input("Anzahl Schrauben: ")
amount_nut = input("Anzahl Muttern: ")
amount_grommet = input("Anzahl Unterlegscheiben: ")
calc(amount_screw,amount_nut,amount_grommet)

                

Lösung von: Tim-Luca L. (Gesamtschule H. )

console.log((
   prompt("Anzahl der Schrauben:") * 0.07 + 
   prompt("Anzahl der Muttern:") * 0.04 +
   prompt("Anzahl der Unterlegscheiben:") * 0.02).toFixed(2)
);
                

Lösung von: Lisa Salander (Heidi-Klum-Gymnasium Bottrop)

using System;
using System.Collections.Generic;
using System.Linq;

namespace Price_Calculator {
	class Program {
		static void Main() {
			try {
				Dictionary<string, double> Produkte = new Dictionary<string, double>(){
					{"Schrauben", 0.07},
					{"Muttern", 0.04},
					{"Unterlegscheiben", 0.02}
				};

				for (int i = 0; i < Produkte.Count; i++) {
					Console.Write("Anzahl {0}>", Produkte.ElementAt(i).Key);
					Produkte[Produkte.ElementAt(i).Key] *= Convert.ToUInt32(Console.ReadLine());
				}

				Console.WriteLine("\nGesamt: {0:C}", Produkte.Values.Sum());
			}
			catch (Exception) {
				Console.Clear();
				Main();
			}

			Console.ReadKey(true);
		}
	}
}
                

Lösung von: Marcel Kapma ()

object EisenWahrenHaendler extends App {
/*
 * Funktion zum berechnen des Gesamt Preises 
 */
def Calc(screw : Int , screwNut : Int , grommets:Int) : Int = {
  var sum:Int = screw * 7 + screwNut * 4 + grommets * 2
  return sum
}
do{ 
  println("PriceCalculator 2015 Scala")
  println("How many screws do you want to buy?")
    var screw = scala.io.StdIn.readInt()
  println("How many screw nuts do you want to buy?")
    var screwNut = scala.io.StdIn.readInt()
  println("How many grommets do you want to buy?")
    var grommets = scala.io.StdIn.readInt()
    var sum = Calc(screw,screwNut,grommets)
  println("You have to pay " + sum + "ct")
}while(true)
}
                

Lösung von: Name nicht veröffentlicht

if (numericUpDown1.Text != "" && numericUpDown2.Text != "" && numericUpDown3.Text != "")
            {
                double Schrauben, Mutter, Scheibe, Ergebnis;
                Schrauben = Convert.ToDouble(numericUpDown1.Value);
                Mutter = Convert.ToDouble(numericUpDown2.Value);
                Scheibe = Convert.ToDouble(numericUpDown3.Value);

                Ergebnis = Schrauben * 0.07 + Mutter * 0.04 + Scheibe * 0.02;

                richTextBox1.Text = Ergebnis + "€";
            }
            else
            {
                MessageBox.Show("Bitte geben sie einen gültigen Wert von 0-999 ein!", "Ungültiger Wert", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
                

Lösung von: D. Larisch ()

#include <stdio.h>

/*
Ein Händler verlangt für seine Waren folgende Preise:
7 Cent pro Schraube (engl. screw)
4 Cent pro Mutter (engl. screw nut)
2 Cent pro Unterlegscheibe (engl. grommet)
Schreiben Sie ein Programm namens PriceCalculator, das vom Anwender die Anzahl der Schrauben, Muttern und Unterlegscheiben erfragt und dann den Gesamtbetrag berechnet und ausgibt.
*/

int main(void)
{
    int screwCost = 7;
    int screwNutCost = 4;
    int grommetCost = 2;
    
    printf("\t\tCOST OF THE SCREW-COMPONENTS\n");
    printf("\t\t----------------------------\n\n");
    
    printf("screw = %ic\nscrew nut=%ic\ngrommet = %ic\n\n", screwCost, screwNutCost, grommetCost);
    printf("How many screws do you want = ");
    int screwAmount;
    scanf("%i", &screwAmount);
    
    printf("How many screw nuts do you want = ");
    int screwNutsAmount;
    scanf("%i", &screwNutsAmount);
    
    printf("How many grommets do you want = ");
    int gommetsAmount;
    scanf("%i", &gommetsAmount);
    
    float totalCost = ((screwCost * screwAmount) + (screwNutCost * screwNutsAmount) + (grommetCost * gommetsAmount)) / 100.00f;
    
    printf("TOTAL COST = %.2f EURO\n\n", totalCost);
    
    getchar();
    return 0;
}

                

Lösung von: Name nicht veröffentlicht

/**
 * 2016-02-29
 * @author Sam Yiming Miao
 */
package ch.toastgott.programmieraufgaben;

import javax.swing.JOptionPane;

public class Eisenwarenhändler {
	public static void main(String[] args) {
		int quantity_screw, quantity_screwnut, quantity_grommet, totalprice;
		int screw = 7, screwnut = 4, grommet = 2;
		quantity_screw =Integer.parseInt(JOptionPane.showInputDialog(
				"Geben Sie die Anzahl der Schrauben ein: "));
		quantity_screwnut =Integer.parseInt(JOptionPane.showInputDialog(
				"Geben Sie die Anzahl der Schraubenmuttern ein: "));
		quantity_grommet =Integer.parseInt(JOptionPane.showInputDialog(
				"Geben Sie die Anzahl der Unterlegscheiben ein: "));
		totalprice = screw * quantity_screw + screwnut * quantity_screwnut + grommet * quantity_grommet;
		JOptionPane.showMessageDialog(null,
				"Der Gesamtbetrag beträgt " + totalprice + " Cent.");
	}
}
                

Lösung von: Sam Yiming Miao (Schule ist gut genug)

Module Module1
    Sub Main()
        Dim schrauben As Integer
        Dim muttern As Integer
        Dim unterlegScheiben As Integer

        Console.WriteLine("Gib die Anzahl Schrauben, Muttern und Unterlegscheiben an: ")
        Console.WriteLine("Schrauben (7 Cent): ")
        schrauben = Console.ReadLine()
        Console.WriteLine("Muttern (4 Cent): ")
        muttern = Console.ReadLine()
        Console.WriteLine("Unterlegscheiben (2 Cent): ")
        unterlegScheiben = Console.ReadLine()

        Dim summe As Integer = schrauben * 7 + muttern * 4 + unterlegScheiben * 2
        Console.WriteLine("Es kostet: " & summe & " Cent")
        Console.ReadLine()
    End Sub
End Module
                

Lösung von: Elias Zech (Optics Balzers)

Abfrage:

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

Bitte geben Sie die Anzahl Ihrer verlangten Waren ein:

<form action="eisenwarenhändler.php" method="post">
    <input type="number" min="0" id="screw" name="screw">Anzahl an Schrauben<br></input>
    <input type="number" min="0" id="screwnut" name="screwnut">Anzahl an Muttern<br></input>
    <input type="number" min="0" id="grommet" name="grommet">Anzahl an Unterlegscheiben<br></input>
    <input type="submit" value="Abschicken" /><input type="reset" value="Zurücksetzen" />
</form>

</body>
</html>




Und Berechnung:


<?php

$x = ($_POST["screw"] * 7) / 100;
$y = ($_POST["screwnut"] * 4) / 100;
$z = ($_POST["grommet"] * 2) / 100;

$gesamtpreis = $x + $y + $z;

echo "Sie haben " . $_POST["screw"] . " Schrauben, " . $_POST["screwnut"] . " Muttern und " . $_POST["grommet"] . " Unterlegscheiben bestellt.<br>";
echo "Gesamtpreis: " . $gesamtpreis . "€";

?>
                

Lösung von: Maik Scheiermann (Powercloud GmbH)

puts "Wieviele Schrauben?"
screw = gets.chomp.to_i * 0.07
puts "Wieviele Muttern?"
screw_nut = gets.chomp.to_i * 0.04
puts "Wieviele Unterlegsscheiben?"
grommet = gets.chomp.to_i * 0.02

sum = screw + screw_nut + grommet

puts "Das kostet #{sum.to_f} €"
                

Lösung von: Name nicht veröffentlicht

#include "stdafx.h"
#include <iostream>

using namespace std;
//Funktionsprototyp
double berechnung(int, int, int);

double berechnung(int x, int y, int z)
{
	double screw = 0.07, screwnut = 0.04, grommet = 0.02, ergebnis;
	ergebnis = (x*screw) + (y*screwnut) + (z*grommet);
	return ergebnis;
}

int main()
{
	int anzahl_screw, anzahl_screwnut, anzahl_grommet;
	double preis = 0;
	
	cout << "Wie viele Schrauben wollen Sie?" << endl;
	cin >> anzahl_screw;
	cout << "Wie viele Muttern wollen Sie?" << endl;
	cin >> anzahl_screwnut;
	cout << "Wie viele Unterlegscheiben wollen Sie?" << endl;
	cin >> anzahl_grommet;
	
	preis = berechnung(anzahl_screw, anzahl_screwnut, anzahl_grommet);

	cout << "Die Kosten belaufen sich auf " << preis << " Euro." << endl;
	system("PAUSE");
}
                

Lösung von: Name nicht veröffentlicht

def price_calculator(screws, screws_nuts, grommets):
    try:
        if screws > 0 and screws_nuts > 0 and grommets > 0:
            screws *= 0.07
            screws_nuts *= 0.04
            grommets *= 0.02
            final = screws + screws_nuts + grommets
            print(final)
        else:
            print("Please type a positive number")
    except ValueError:
        print("Please type a number")


screw = int(input("How many screws? "))
screw_nut = int(input("How many screws nuts? "))
grommet = int(input("How many grommets? "))
price_calculator(screw, screw_nut, grommet)

                

Lösung von: Infinit Loop ()

import java.util.Scanner;

import javax.swing.JOptionPane;

public class PriceCalculator {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		long schrauben, mutter, unterlegscheibe ;
		
		Scanner sc = new Scanner(System.in);
		schrauben =Long.parseLong(JOptionPane.showInputDialog("Wie viel Schrauben brauchen Sie?"));
		mutter = Long.parseLong(JOptionPane.showInputDialog("Wie viel Mutter Brauchen Sie? "));
		unterlegscheibe = Long.parseLong(JOptionPane.showInputDialog("Wie viel unterlegscheibhe brauchen Sie?"));
		long sum = 0;
		sum += schrauben + mutter + unterlegscheibe;
		System.out.println("eingegeben Schrauben Nummer ist:" + schrauben + "\n" + "Eingegeben Mutter Nummer ist:" + mutter + "\n" + "Eingegeben Unterlegscheibe Nummer ist: " + unterlegscheibe  + "\n" + "Gesamtbetrag ist:" + sum);

	}

}

                

Lösung von: Name nicht veröffentlicht

*Definition der Auswahlfelder.
PARAMETERS: z_screw TYPE p DECIMALS 2,
            z_nut   TYPE p DECIMALS 2,
            z_gromm TYPE p DECIMALS 2.

*Definition Parameters - Gepackte Zahl mit 2 Nachkommastellen.
DATA: z_prize        TYPE p DECIMALS 2,
      z_summes       TYPE p DECIMALS 2,
      z_summen       TYPE p DECIMALS 2,
      z_summeg       TYPE p DECIMALS 2,
      formatted_text TYPE c LENGTH 50.

* Preise der einzelnen Artikel werden vordefiniert.
z_summes = z_screw * 7 / 100.
z_summen = z_nut * 4 / 100.
z_summeg = z_gromm * 2 / 100.
z_prize = z_summes + z_summen + z_summes.

* Ausgabe der Werte
WRITE: /  'Preis Schrauben:', 30 z_summes && '€'.
SKIP.
WRITE: /  'Preis Muttern:',30 z_summen && '€'.
SKIP.
WRITE: /  'Preis Unterlagsscheiben:', 30 z_summeg && '€'.
SKIP.
ULINE.
WRITE: /  'Preis Total', 30 z_prize && '€' COLOR 5.
                

Lösung von: Name nicht veröffentlicht

using System;

namespace PriceCalculator
{
    class Program
    {
        static double Rechnen(uint[] sng)
        {
            double sPrice = 0.07, nPrice = 0.04, gPrice = 0.02;
            return (sng[0] * sPrice) + (sng[1] * nPrice) + (sng[2] * gPrice);
        }
        static void Main()
        {
            uint[] sng = { 0, 0, 0 }; // Screw, Nut, Grommet
            string HowMuchText = "Wie viele {0} wollen sie kaufen? ";
            string[] textContent = { "Schrauben", "Schraubenmütter", "Unterlegscheiben" };


            for(byte i = 0; i < sng.Length; i++) {
                do {
                    Console.Write(HowMuchText, textContent[i]);
                } while (uint.TryParse(Console.ReadLine(), out sng[i]) == false);
            }

            double total = Rechnen(sng);
            Console.WriteLine("Alles zusammen kostet {0} Euro.", total);

            Console.ReadKey();  // endl
        }
    }
}

                

Lösung von: Name nicht veröffentlicht

// NET 6.x | C# 10.x | VS-2022
var sum = 0.0;
foreach (var (type, price) in new List<(string, double)> { ("screws", 7), ("nuts", 4), ("grommets", 2) }) {
    Console.Write($"amount {type}: ");
    _ = int.TryParse(Console.ReadLine(), out var amount);
    sum += amount * price / 100;
}
Console.WriteLine($"total price: {sum:f2}");
                

Lösung von: Jens Kelm (@JKooP)

// C++ 20 | VS-2022
#include <iostream>
#include <vector>
#include <tuple>

int main() {
    auto sum{ 0.0 };
    const std::vector<std::tuple<std::string, double>>v{ { "screws", 7 }, { "nuts", 4 }, { "grommets", 2 } };
    for (const auto& [type, price] : v) {
        auto amount{ 0 };
        std::cout << "amount (" << type << "): ";
        std::cin >> amount;
        sum += amount * price / 100;
    }
    std::cout << "total price: " << sum << "\n";
}
                

Lösung von: Jens Kelm (@JKooP)

Verifikation/Checksumme:

3 Schrauben, 8 Muttern und 11 Unterlagsscheiben => Preis: 75 Cent

Aktionen

Bewertung

Durchschnittliche Bewertung:

Eigene Bewertung:
Bitte zuerst anmelden

Meta

Zeit: 0.25
Schwierigkeit: Leicht
Webcode: ranc-fuh0
Autor: ()

Download PDF

Download ZIP

Zu Aufgabenblatt hinzufügen