2024-03-13 09:55:11 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2024-03-20 14:57:31 +00:00
|
|
|
#define SIZE 100
|
2024-03-20 14:08:46 +00:00
|
|
|
|
2024-03-20 14:57:31 +00:00
|
|
|
struct student {
|
2024-03-20 15:42:19 +00:00
|
|
|
char name[SIZE];
|
2024-03-20 14:57:31 +00:00
|
|
|
int votes;
|
|
|
|
};
|
2024-03-13 09:55:11 +00:00
|
|
|
|
2024-03-20 16:43:01 +00:00
|
|
|
void initialize_database(struct student* database, int size, char* names[], int* votes) {
|
2024-03-20 16:26:54 +00:00
|
|
|
for (int i = 0; i < size; i++) {
|
2024-03-20 16:43:01 +00:00
|
|
|
strcpy(database[i].name, names[i]);
|
|
|
|
database[i].votes = votes[i];
|
2024-03-20 15:22:08 +00:00
|
|
|
}
|
2024-03-20 14:57:31 +00:00
|
|
|
}
|
2024-03-20 15:22:08 +00:00
|
|
|
|
|
|
|
int main() {
|
2024-03-20 16:26:54 +00:00
|
|
|
struct student database[SIZE];
|
|
|
|
memset(database, 0, SIZE * sizeof(struct student));
|
2024-03-20 16:43:01 +00:00
|
|
|
int size = 8; // Veľkosť databázy mien študentov
|
|
|
|
char* names[8] = {"Bardos Mrtakrys", "Rita Umhi", "Prylenn Alak", "Lak'hi Elavorg", "Prylenn Alak", "Prylenn Alak", "Prylenn Alak", "Rita Umhi"};
|
|
|
|
int votes[8] = {2, 1, 1, 10, 3, 3, 3, 1}; // Počet hlasov pre každého študenta
|
2024-03-20 16:26:54 +00:00
|
|
|
|
2024-03-20 16:43:01 +00:00
|
|
|
initialize_database(database, size, names, votes); // Inicializácia databázy mien študentov
|
2024-03-20 16:31:33 +00:00
|
|
|
|
2024-03-20 16:36:26 +00:00
|
|
|
// Výpis databázy
|
|
|
|
printf("Databaza mien studentov s poctom hlasov:\n");
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
printf("%d %s\n", database[i].votes, database[i].name);
|
2024-03-20 15:22:08 +00:00
|
|
|
}
|
2024-03-20 16:26:54 +00:00
|
|
|
|
2024-03-20 16:43:01 +00:00
|
|
|
// Vypočítanie celkového počtu hlasov v ankete
|
2024-03-20 16:36:26 +00:00
|
|
|
int total_votes = 0;
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
total_votes += database[i].votes;
|
|
|
|
}
|
2024-03-20 16:43:01 +00:00
|
|
|
|
|
|
|
printf("\nCelkovy pocet hlasov v ankete: %d\n", total_votes);
|
2024-03-20 16:26:54 +00:00
|
|
|
|
2024-03-20 15:22:08 +00:00
|
|
|
return 0;
|
2024-03-13 09:55:11 +00:00
|
|
|
}
|
|
|
|
|