C++ :: Aufgabe #311 :: Lösung #2

5 Lösungen Lösungen öffentlich
#311

Mobilfunkanbieter (Monatsabrechnung)

Anfänger - C++ von JKooP - 07.11.2020 um 09:42 Uhr
Ein Mobilfunkanbieter stellt folgende Pakete zur Verfügung:

Paket-Typ....Basispreis....Freiminuten....Minutenpreis
P_Basis........2,95€..............0...................0,10€
P_100..........3.95€.............100................0,12€
P_300..........7,95€.............300................0,15€
P_600..........12,95€...........600................0,20€
P_Flat..........29,95€...........unbegrenzt.....0,00€

Schreibe eine Funktion/Methode, bei der sowohl der Paket-Typ als auch die telefonierten Minuten übergeben werden.
Als Ergebnis soll der Gesamtpreis inklusive Basispreis für den Monat ausgegeben werden.

Viel Spaß


#2
vote_ok
von Mahlnycdir (100 Punkte) - 09.11.2020 um 21:08 Uhr
Quellcode ausblenden C-Code
void Mobile_Price(std::string Type, double Minutes)
{
	double Base_Price;
	double All_Price;
	int i;
	if (Type == "P_Base") i = 1;
	else if (Type == "P_100") i = 2;
	else if (Type == "P_300") i = 3;
	else if (Type == "P_600") i = 4;
	else if (Type == "P_Flat") i = 5;

	switch(i)
	{
		
	case 1:
		Base_Price = 2.95;
		All_Price = Base_Price * Minutes;
		std::cout << "Base Price: " << Base_Price << " Euro" << std::endl;
		std::cout << "All_Price: " << All_Price << " Euro" << std::endl;
		break;

	case 2:
		Base_Price = 2.95;
		All_Price = Base_Price * (Minutes - 100);
		std::cout << "Base Price: " << Base_Price << " Euro" << std::endl;
		if (All_Price >= 0) std::cout << "All_Price: " << All_Price << " Euro" << std::endl;
		break;

	case 3:
		Base_Price = 2.95;
		All_Price = Base_Price * (Minutes - 300);
		std::cout << "Base Price: " << Base_Price << " Euro" << std::endl;
		if (All_Price >= 0) std::cout << "All_Price: " << All_Price << " Euro" << std::endl;
		break;

	case 4:
		Base_Price = 2.95;
		All_Price = Base_Price * (Minutes - 600);
		std::cout << "Base Price: " << Base_Price << " Euro" << std::endl;
		if (All_Price >= 0) std::cout << "All_Price: " << All_Price << " Euro" << std::endl;
		break;

	case 5:
		Base_Price = 29.95;
		std::cout << "Base Price: " << Base_Price << " Euro" << std::endl;
		break;
	}
}

Kommentare:

Für diese Lösung gibt es noch keinen Kommentar

Bitte melden Sie sich an um eine Kommentar zu schreiben.
Kommentar schreiben