Buch Cover Buch Cover Buch Cover Buch Cover

Web-Code: - Webcode Help

Notenberechnung ab Klausur- und Bonuspunkten (Unterprogramme)

Implementieren Sie eine Funktion Berechnenote, die als Eingaben zwei Dezimalzahlen Klausurpunkte und Bonuspunkte erhält und zunächst prüft, ob nicht mehr als 100 Klausurpunkte und nicht mehr als 20 Bonuspunkte übergeben wurden. Sollte einer der Tests fehlschlagen, geben Sie eine Fehlermeldung aus z. B. "Mehr als 20 Bonuspunkte können nicht angerechnet werden".

Sollte beide Teste erfüllt sein, so soll Berechnenote die beiden Punktezahlen addieren und die Note wie folgt berechnen:

0 Punkte = Minimalnote

100 Punkte = Maximalnote

Zwischen 0 und 100 Punkten ist die Verteilung linear.

Alles über 100 Punkte = Maximalnote

0 Kommentare

Bitte melde dich an um einen Kommentar abzugeben

11 Lösung(en)

package ch.programmieraufgaben.sequenz;

import java.util.Scanner;

/**
 * Programmieraufgbaen Web-Code: 25gzjfjo
 * @version 0.1 (Apr 25, 2017)
 * @author Philipp Gressly Freimann 
 *         (philipp.gressly@santis.ch)
 */
public class Klausurnoten {
	int  MINIMALNOTE        =   1;
	int  MAXIMALNOTE        =   6;
	int  MAXIMALPUNKTE      = 100;
	int  MAXIMALBONUSPUNKTE =  20;
	char ZAHLTRENNZEICHEN   = ' ';

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


	void top() {
		String eingabeString = einlesen("Eingabe");
		float punkte = extrahiereErsteZahl(eingabeString);
		float bonus  = extrahiereZweiteZahl(eingabeString);
		if(punkte > MAXIMALPUNKTE) {
			System.out.println("Maximal nur " + MAXIMALPUNKTE + " Punkte möglich");
			System.exit(1);
		}
		if(bonus > MAXIMALBONUSPUNKTE) {
			System.out.println("Maximal nur " + MAXIMALBONUSPUNKTE + " Bonuspunkte möglich");
			System.exit(1);
		}
		float endPunkte = punkte + bonus;
		if(endPunkte > MAXIMALPUNKTE) {
			endPunkte = MAXIMALPUNKTE;
		}
		float note = endPunkte * 1f / MAXIMALPUNKTE * (MAXIMALNOTE - MINIMALNOTE) + MINIMALNOTE;
		System.out.println("Klausurnote : " + note);
	}


	/**
	 * @param eingabeString
	 * @return
	 */
	private float extrahiereErsteZahl(String eingabeString) {
		int trennpos = eingabeString.indexOf(ZAHLTRENNZEICHEN);
		String ersteZahl = eingabeString.substring(0, trennpos);
		return Float.parseFloat(ersteZahl);
	}
	private float extrahiereZweiteZahl(String eingabeString) {
		int trennpos = eingabeString.indexOf(ZAHLTRENNZEICHEN);
		String zweiteZahl = eingabeString.substring(trennpos);
		return Float.parseFloat(zweiteZahl);
	}


	/**
	 * Java String einlesen
	 * @param string
	 * @return
	 */
	Scanner sc = new Scanner(System.in);
	 String einlesen(String anfrage) {
		System.out.println(anfrage + ": ");
		return sc.nextLine().trim();
	}

} // end of class Klausurnoten
                

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

package übungen;

import java.util.Scanner;

public class noten_berechnen {

    private static double bonuspunkte;
    private static double punkte;
    private static double maxpunkte = 100;
    public static void main(String[] args) {
        Berechnenote();
    }
    public static void Berechnenote(){
        Scanner sc = new Scanner(System.in);
        System.out.println("Bitte geben sie ihre Prüfungspunkte ein.");
        
        
        boolean wiederholung = false;
        while(wiederholung == false){
            System.out.print("Punkte: ");
            punkte = sc.nextDouble();
                if(punkte > 100 || punkte < 0){
                    System.out.println("Ungültige Eingabe, bitte Wiederholen");
                    wiederholung = false;
                }
                else{
                    wiederholung = true;
                    
                }
        }
        
        boolean wiederholung2 = false;
        while(wiederholung2 == false){
            System.out.print("Bonuspunkte: ");
                bonuspunkte = sc.nextDouble();
                if(bonuspunkte > 20 || bonuspunkte < 0){
                    System.out.println("Ungültige Eingabe, bitte Wiederholen");
                    wiederholung2 = false;
                }
                else{
                    wiederholung2 = true;
                }
        }
        if(wiederholung == true && wiederholung2 == true){
            System.out.println("Notenberchnung: Punktzahl * 5 / 100 + 1");
            double notenpunkte = punkte + bonuspunkte;
            if(notenpunkte > maxpunkte){
                notenpunkte = 6.0;
            }
            else{
                notenpunkte = (((notenpunkte) * 5) / 100) + 1;
            }
            System.out.println("Ihre Note: " + notenpunkte);
            
        }   
        
    }
    
}

                

Lösung von: Nadim Ritter ()

'''
Created on 05.05.2017

@author: Tobias Widner
'''
# -*- coding: UTF-8 -*-

# G L O B A L   C O N S T A N T S #
MAX_MARK = 6
MIN_MARK = 1
MAX_TEST_POINTS = 100
MAX_BONUS_POINTS = 20

# G L O B A L   F U N C T I O N S #
def calculateMark(testPoints, bonusPoints):
    if (testPoints > MAX_TEST_POINTS):
        print("Given test points %1.1f are higher than the maximum allowed: %1.1f" \
              % (testPoints, MAX_TEST_POINTS))
        return
    if (bonusPoints > MAX_BONUS_POINTS):
        print("Given bonus points %1.1f are higher than the maximum allowed: %1.1f" \
              % (bonusPoints, MAX_BONUS_POINTS))
        return
    
    sum_points = testPoints + bonusPoints
    mark = MAX_MARK / MAX_TEST_POINTS * sum_points + MIN_MARK  
    # linear function: f(x) = ax + b -> a = (max)y/(max)x
    return 6 if sum_points > MAX_TEST_POINTS else mark

# M A I N L I N E #
markAchieved = None
while markAchieved is None:
    testPoints = float(input("Insert test points achieved: "))
    bonusPoints = float(input("Insert bonus points achieved: "))
    markAchieved = calculateMark(testPoints, bonusPoints)

print("The mark that you achieved is a %1.2f" % markAchieved)

                

Lösung von: Tobias Widner (ex. SANTIS Training AG Besucher)

/* 
 * File:   Notenberechnung
 * Author: Manuel Stolze
 * Created on 23. Juni 2017, 10:02
 */

#include <cstdlib>
#include <iostream>
using namespace std;

class Klausurnoten {
    
public:
    void Berechne_Note(int, int);
    void einlesen();
private:
    int  minimalnote        =   1;
    int  maximalnote        =   6;
    int  maximalpunkte      = 100;
    int  maximalbonuspunkte =  20;    
};


void Klausurnoten::einlesen(){
    
    int punkte;
    int bonuspunkte;
    
    cout << "Bitte Punktzahl eingeben: ";
    cin >> punkte;
    if (punkte > maximalpunkte){
        cout << "Error: Die Maximalpunktzahl beträgt " << maximalpunkte << "Punkte!";
        exit(0);
    }
    
    cout << "Bitte Bonuspunkte eingeben: ";
    cin >> bonuspunkte;
    if ( bonuspunkte > maximalbonuspunkte){
        cout << "Error: Die Maximalanzahl der Bonuspunkte beträgt " << maximalbonuspunkte <<"Punkte!";
        exit(0);
    }
    Berechne_Note(punkte, bonuspunkte);
}


void Klausurnoten::Berechne_Note(int punkte, int bonuspunkte){
    
    int gesamtpunkte, note;
    
    // Punkteberechnung //
    gesamtpunkte = punkte + bonuspunkte;
    if(gesamtpunkte > maximalpunkte){
        gesamtpunkte = punkte;
    }
    
    // Notenbrechenung //
    note = ((gesamtpunkte) * (maximalnote - minimalnote) / maximalpunkte) + minimalnote;
    cout << "Endnote: " << note;
}


int main(int argc, char** argv) {
    
    // Objekterzeugung //
    Klausurnoten neueKlausurnote;
    neueKlausurnote.einlesen();

    return 0;
}


                

Lösung von: Manuel Stolze (Hochschule Darmstadt)

#Eingabe
Klausurpunkte = int(input ("ihre Klausurpunkte:"))
Bonuspunkte = int(input ("ihre Bonuspunkte:"))


#Notenbereich
max_Klausurpunkte = 100
max_Bonuspunkte = 20

#Überprüfung
if (Klausurpunkte / max_Klausurpunkte > 1):
    print ("Mehr als 100 Klausurpunkte können nicht erreicht werden.")

if (Klausurpunkte < 0):
    print ("Negative Werte dürfen nicht verwendet werden.")

if (Bonuspunkte / max_Bonuspunkte > 1) :
    print ("Mehr als 20 Bonuspunkte können nicht angerechnet werden.")

if (Bonuspunkte < 0) :
    print ("Negative Werte dürfen nicht verwendet werden!.")

#Berechnung
if (Klausurpunkte / max_Klausurpunkte <= 1) and (Bonuspunkte / max_Bonuspunkte <= 1) and (Klausurpunkte > 0) and (Bonuspunkte > 0):
    Note = Klausurpunkte + Bonuspunkte
    if Note / 100 >=1:
        print ("Herzlichen Glückwunsch, sie haben die Maximalnote mit", Note, "erreicht.")
    else:
        print ("Ihre Note Lautet:",Note)
else:
    print ("Ihre Note kann nicht berechnet werden.")

                

Lösung von: Kevin S. (Johanney-Gymnasium)

import java.util.Scanner;

/**
 * Created by linus on 17.10.17.
 */
public class Main {

    private final double MIN_MARK = 1;
    private final double MAX_MARK = 6;
    private final double MAX_POINTS = 100;
    private final double MAX_BONUS_POINTS = 20;

    public static void main(String[] args) {
        new Main().init();
    }

    private void init() {
        double[] points = readPoints();
        checkPoints(points);
        double result = result(points);
        System.out.println("Note: " + result);
    }

    private double[] readPoints() {
        Scanner scanner = new Scanner(System.in);
        double[] points = new double[2];

        System.out.print("Punkte: ");
        points[0] = scanner.nextDouble();

        System.out.print("Bonuspunkte: ");
        points[1] = scanner.nextDouble();

        System.out.println();

        return points;
    }

    private void checkPoints(double[] points) {
        if(points[0] < 0 || points[1] < 0) {
            System.out.println("Bitte keine negativen Eingaben!");
            System.exit(0);
        } else if(points[0] > MAX_POINTS || points[1] > MAX_BONUS_POINTS) {
            System.out.println("Der Wert ist zu groß!");
            System.exit(0);
        }
    }

    private double result(double[] points) {
        double total = points[0] + points[1];

        if(total > 100) {
            total = 100;
        }

        double m = (MAX_MARK - MIN_MARK) / MAX_POINTS;
        
        return Math.round(((m * total) + MIN_MARK) * 100) / 100D;
    }
}

                

Lösung von: Name nicht veröffentlicht

import java.util.Scanner;

public class minitest {


		public static void main(String[] args) {
			double Klausurpunkte, Bonuspunkte;
			Scanner notenscanner = new Scanner(System.in);
			
			//Klausurnoteneingabe und Prüfung, bei ungültiger Eingabe erneut fragen.
			System.out.println("Bitte geben sie die Klausurpunkte ein.");
			Klausurpunkte=notenscanner.nextInt();
			
			while(Klausurpunkte<0 || Klausurpunkte>100) {
				System.out.println("UngültigeEingabe. Bitte geben sie die Klausurpunkte erneut ein.");
				Klausurpunkte=notenscanner.nextInt();}
			
			
			//Selbiges für die Bonuspunkte
			System.out.println("Bitte geben sie die Bonuspunkte ein.");
			Bonuspunkte=notenscanner.nextInt();
			
			while(Bonuspunkte>20 || Bonuspunkte<0) {
				System.out.println("Ungültige Eingabe. Bitte geben sie die Bonuspunkte erneut ein.");
				Bonuspunkte=notenscanner.nextInt();}
			
			//Berechnen der Gesamtpunkte
			double summe = Klausurpunkte+Bonuspunkte;
			//Wert mit Inkrementoperator auf max 100 bringen falls höher da mehr Punkte nicht möglich.
			while(summe>100) {summe--;}
		
			System.out.println("Die Gesamtwertung beträgt" + summe + "von 100 möglichen Punkten.");	
			//Umrechnung in klassische Note(1-6)
			double klassischenote = ((((summe) * 5) / 100) -6)*-1; 
			//Runden der klassischen Note auf eine Nachkommastelle
			klassischenote = Math.round(klassischenote*10)/10.0;
		
			System.out.println("Dies entspricht einer Note von:" + klassischenote);	
			notenscanner.close();
		}
		}


                

Lösung von: Name nicht veröffentlicht

using System;
using System.Linq;

namespace Notenberechnung
{
    class Program
    {
        static void Main(string[] args)
        {
            //User Eingabe
            Console.WriteLine("Gebe die Punktzahl sowie Bonuspunkte mit Leerzeichen getrennt ein (Punkte Bonus):");
            string[] Punkte = Console.ReadLine().Split(' ');

            //Prüfen auf maximale Punkte
            if(Int32.Parse(Punkte[0]) > 100 || Int32.Parse(Punkte[1]) > 20)
            {
                Console.WriteLine("Es dürfen maximal 100 Punkte und 20 Bonuspunkte verteilt werden.");
                Console.ReadLine();
                return;
            }

            //Errechnung der Note & Runden auf eine Stelle
            double Gesamt = Int32.Parse(Punkte[0]) + Int32.Parse(Punkte[1]);
            double Note = Math.Round(Gesamt / (100 / 5), 1) + 1;

            //Verhindern, dass die Note größer als 6 ist (durch Bonuspunkte)
            if (Note > 6) Note = 6;

            Console.WriteLine("Die Note ist: " + Note);
            Console.ReadLine();
        }
    }
}

                

Lösung von: Tobias Golz (Wilhelm Büchner Hochschule)

function judge(examPoints, bonusPoints) {
  if (examPoints > 100) examPoints = 100;
  if (bonusPoints > 20) bonusPoints = 20;
  let total = examPoints + bonusPoints;
  if (total > 100) total = 100;
  return (total * 5 /100 + 1).toFixed(1);
}

console.log(judge(  0,  0));
console.log(judge(100, 20));
console.log(judge( 80, 20));
console.log(judge(100,  0));
console.log(judge( 40, 10));
console.log(judge( 71, 15));                                // lissalanda@gmx.at
                

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

// NET Core 3.x
// In Anlehnung an die deutschen Abiturnoten(punkte):

using System;
using System.Text.RegularExpressions;

namespace Notenberechnung
{
    class Program
    {
        private enum Noten
        {
            Sechs,
            Fuenf_Minus, Fuenf, Fuenf_Plus,
            Vier_Minus, Vier, Vier_Plus,
            Drei_Minus, Drei, Drei_Plus,
            Zwei_Minus, Zwei, Zwei_Plus,
            Eins_Minus, Eins, Eins_Plus
        }

        static void Main(string[] args)
        {
            Match m;

            while (true)
            {
                Console.Write("Punktzahl (0-100) und Bonus-Punkte (0-20) getrennt eingeben: ");
                m = new Regex(@"([0-9]|[1-9][0-9]?|100)[\s\D]+\b([1-9]|[0-1][0-9]?|20)$").Match(Console.ReadLine());
                if (m.Groups.Count == 3) break;
                Console.WriteLine("Fehlerhafte Eingaben!");
            }

            var p = int.Parse(m.Groups[1].ToString());
            var b = int.Parse(m.Groups[2].ToString());
            var n = (int)Math.Round(((p + b) > 100 ? 100 : (p + b)) * 15 / 100.0, 0);

            Console.WriteLine($"Notenpunkte: {n} ({Enum.GetName(typeof(Noten), n)})");
        }
    }
}
                

Lösung von: Jens Kelm (@JKooP)

// C++ 14 | VS-2022
#include <iostream>

int main() {
    const std::string grades[]{ "6", "5-", "5", "5+", "4-", "4", "4+", "3-", "3", "3+", "2-", "2", "2+", "1-", "1", "1+" };
    std::cout << "Punktzahl (0-100) und Bonus-Punkte (0-20) leerzeichengetrennt eingeben: ";
    int pts, bon;
    std::cin >> pts >> bon;
    pts = std::min(abs(pts), 100);
    bon = std::min(abs(bon), 20);
    const auto sum{ std::min(pts + bon, 100) };
    const auto grd{ (int)floor(sum * 15 / 100.0 + 0.5) };
    std::cout << "Punkte: " << sum <<  " -> Notenpunkte: " << grd << " (" << grades[grd] << ")\n";
}
                

Lösung von: Jens Kelm (@JKooP)

Verifikation/Checksumme:

0 0 → Note 1 (schlechteste)

100 20 → Note 6 (Bestnote)

80 20 → Note 6 (Bestnote)

100 0 → Note 6 (Bestnote)

40 10 → Note 3.5 (Mittlerer Notenwert)

71 15 → Note 5.3

Aktionen

Bewertung

Durchschnittliche Bewertung:

Eigene Bewertung:
Bitte zuerst anmelden

Meta

Zeit: 0.25
Schwierigkeit: Leicht
Webcode: 25gz-jfjo
Autor: ()

Download PDF

Download ZIP

Zu Aufgabenblatt hinzufügen