Sitzung: Jeden Freitag ab 14:30 s.t. online. Falls ihr den Link haben wollt, schreibt uns.

C-Kurs/Autohaus/Musterlösung

< C-Kurs‎ | Autohaus(Weitergeleitet von Ckurs/Autohaus/Musterlösung)
#include <stdio.h>
#include <stdlib.h>

typedef enum brand_name{
	VW,
	PORSCHE,
	LAMBORGHINI
}brand_name_t;

typedef struct car{
	brand_name_t brand;
	int max_velocity;
	int abs;
	unsigned char doors;
}car_t;

car_t new_car(brand_name_t brand, int max_velocity, int abs, unsigned char doors)
{
	car_t car;
	car.brand = brand;
	car.max_velocity = max_velocity;
	car.abs = abs;
	car.doors = doors;
	return car;
}

int estimate_prize(car_t car)
{
	int preis;
	preis = car.max_velocity*50;
	preis *= car.doors;	
	if(car.abs)
		preis += 5000;
	switch(car.brand)
	{
		case VW: 
			break;
		case PORSCHE: 
			preis *= 2;
			break;
		case LAMBORGHINI: 
			preis *= 20;
			break;
	}
	return preis;
}

int main()
{
	car_t cars[3];
	cars[0] = new_car(VW,190,1,5);
	cars[1] = new_car(PORSCHE,210,1,4);
	cars[2] = new_car(LAMBORGHINI,260,350,2);
	
	int sum = 0;
	int i;	
	for(i=0; i<3; i++)
	{
		int prize = estimate_prize(cars[i]);
		printf("Preis%d: %d\n",i,prize);
		sum += prize;
	}
	printf("GESAMTPREIS: %d\n",sum);

	return 0;
}