Upload files to "struct"
This commit is contained in:
parent
271a16128e
commit
e7f8063692
|
@ -3,9 +3,8 @@ AUTORE: Manuel Vichi
|
||||||
(WIP) Dato
|
(WIP) Dato
|
||||||
*/
|
*/
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <array>
|
|
||||||
#include <vector>
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <ctime>
|
||||||
#define SIZEARRAY 10
|
#define SIZEARRAY 10
|
||||||
using namespace std;
|
using namespace std;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -14,15 +13,48 @@ typedef struct {
|
||||||
char simbolo;
|
char simbolo;
|
||||||
} Dato;
|
} Dato;
|
||||||
|
|
||||||
Dato riempiArray(Dato arr[], size_t size) {
|
void riempiArray(Dato arr[], size_t size) {
|
||||||
|
srand(time(NULL));
|
||||||
for (size_t i = 0; i < size; i++) {
|
for (size_t i = 0; i < size; i++) {
|
||||||
arr[i].numero = rand() % 100;
|
arr[i].numero = rand() % 100;
|
||||||
arr[i].valore = rand() % 1.5f;
|
arr[i].valore = (float)rand();
|
||||||
arr[i].simbolo = 'A' + rand() % 65;
|
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) {
|
int main(void) {
|
||||||
Dato array[SIZEARRAY];
|
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;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue