115 lines
2.2 KiB
C
115 lines
2.2 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#define ANZ_SCHUELER 30
|
|
|
|
typedef struct
|
|
{
|
|
char name[10];
|
|
char vorname[10];
|
|
unsigned note;
|
|
} Person;
|
|
|
|
int eingabe(Person *p, int i)
|
|
{
|
|
printf("---Eingabe des %d. Schuelers----\n", i);
|
|
printf("Name: ");
|
|
fgets(p->name, sizeof(p->name), stdin);
|
|
if (p->name[strlen(p->name) - 1] == '\n')
|
|
{
|
|
p->name[strlen(p->name) - 1] = '\0';
|
|
}
|
|
|
|
if (strlen(p->name) == 0)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
printf("Vorname: ");
|
|
fgets(p->vorname, sizeof(p->vorname), stdin);
|
|
if (p->vorname[strlen(p->vorname) - 1] == '\n')
|
|
{
|
|
p->vorname[strlen(p->vorname) - 1] = '\0';
|
|
}
|
|
|
|
if (strlen(p->vorname) == 0)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
printf("Note: ");
|
|
if (scanf("%u", &p->note) != 1 || p->note < 0 || p->note > 6)
|
|
{
|
|
return 0;
|
|
}
|
|
while (getchar() != '\n');
|
|
|
|
return 1;
|
|
}
|
|
|
|
float durchschnittsnote(Person *n, int anzahl)
|
|
{
|
|
float sum = 0;
|
|
float durchschnitt;
|
|
for (int i = 0; i < anzahl; ++i)
|
|
{
|
|
sum += n[i].note;
|
|
}
|
|
durchschnitt = sum / anzahl;
|
|
return durchschnitt;
|
|
|
|
}
|
|
|
|
void notenspiegel(Person *n, int anzahl)
|
|
{
|
|
int notenHaeufigkeit[6] = {0};
|
|
|
|
for (int i = 0; i < anzahl; ++i)
|
|
{
|
|
notenHaeufigkeit[n[i].note - 1]++;
|
|
}
|
|
|
|
printf("\nNotenspiegel:\n");
|
|
for (int i = 0; i < 6; ++i)
|
|
{
|
|
printf("Note %d: ", i + 1);
|
|
for (int j = 0; j < notenHaeufigkeit[i]; ++j)
|
|
{
|
|
printf("*");
|
|
}
|
|
printf("\n");
|
|
}
|
|
}
|
|
|
|
void printListe(Person *liste, int anzahl)
|
|
{
|
|
printf("Name \t\t ,Vorname \t\t ,Note ");
|
|
printf("\n------------------------------------------------------------------------\n");
|
|
for (int i = 0; i < anzahl; ++i)
|
|
{
|
|
if (strlen(liste[i].name) > 0)
|
|
{
|
|
printf("%s \t\t ,%s \t\t ,%u\n", liste[i].name, liste[i].vorname, liste[i].note);
|
|
}
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
Person schueler[ANZ_SCHUELER];
|
|
int i;
|
|
|
|
for (i = 0; i < ANZ_SCHUELER; ++i)
|
|
{
|
|
if (!eingabe(&schueler[i], i + 1))
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
printListe(schueler, i);
|
|
printf("Durchschnittsnote = %2.f ", durchschnittsnote(schueler, i));
|
|
notenspiegel(schueler,i);
|
|
return 0;
|
|
}
|