60 lines
1.3 KiB
C++
60 lines
1.3 KiB
C++
/*
|
|
AUTORE: Manuel Vichi
|
|
(WIP) Dato
|
|
*/
|
|
#include <iostream>
|
|
#include <cstdlib>
|
|
#include <ctime>
|
|
#define SIZEARRAY 10
|
|
using namespace std;
|
|
typedef struct {
|
|
int numero;
|
|
float valore;
|
|
char simbolo;
|
|
} Dato;
|
|
|
|
void riempiArray(Dato arr[], size_t size) {
|
|
srand(time(NULL));
|
|
for (size_t i = 0; i < size; i++) {
|
|
arr[i].numero = rand() % 100;
|
|
arr[i].valore = (float)rand();
|
|
arr[i].simbolo = 'A' + rand() % 65;
|
|
}
|
|
}
|
|
|
|
int trovaMassimo(const Dato arr[], size_t size) {
|
|
float valoremax = 0;
|
|
int index;
|
|
for (size_t i = 0; i < size; i++) {
|
|
if (arr[i].valore > valoremax) {
|
|
valoremax = arr[i].valore;
|
|
index = i;
|
|
}
|
|
}
|
|
return index;
|
|
}
|
|
|
|
int contaCar(const Dato arr[], size_t size, char c) {
|
|
int occorrenze = 0;
|
|
for (size_t i = 0; i < size; i++) {
|
|
if (arr[i].simbolo == c) {
|
|
occorrenze++;
|
|
}
|
|
}
|
|
return occorrenze;
|
|
}
|
|
|
|
void stampaArray(const Dato arr[], size_t size) {
|
|
for (size_t i = 0; i < size; i++) {
|
|
cout << "Numero: " << arr[i].numero << ", Valore: " << arr[i].valore << ", Carattere: " << arr[i].simbolo << endl;
|
|
}
|
|
}
|
|
|
|
int main(void) {
|
|
Dato array[SIZEARRAY];
|
|
riempiArray(array,SIZEARRAY);
|
|
stampaArray(array,SIZEARRAY);
|
|
cout << "Occorrenze del carattere A: " << contaCar(array,SIZEARRAY,'A') << endl;
|
|
cout << "Valore massimo: " << trovaMassimo(array,SIZEARRAY);
|
|
return 0;
|
|
} |