18/05/2018, 10:21
void insufficienti(int matriceA[20][N],float media[N]){
int i, j;
cout<<"\nMateria insufficiente - "<<i<<" = ";
for (j=0; j<M ; j++){
if (matriceA[j][i]<(float)media[j]){
matriceA[j][i]=matriceA[j][i];
}
else
matriceA[j][i]==0;
cout<<setw(4)<<"\nStudente "<<j<<" con insufficienza ="<<matriceA[j][i]<<endl;
}
}
int main () {
int matriceA[20][N], v[N];
float media[N];
cout<<"\n Matrice con dimensione massima 20x7 ";
leggi_Matrice(matriceA);
stampa_Matrice(matriceA);
Somma_Colonne(matriceA,v,media);
insufficente(matriceA,media);
}
18/05/2018, 10:34
18/05/2018, 11:47
il quesito:
dopo aver caricato una matrice
che deve mostrare tutti gli elementi, la media e i valori inferiori alla media,
mostra gli elementi , calcola la media ma non i valori inferiori alla media.
18/05/2018, 12:51
#include <iostream>
#include <cstdlib>
#include <iomanip>//manipolatore dell'output stream
using namespace std;
const int N=3;
int M;
void leggi_Matrice(int matriceA[20][N]);
void stampa_Matrice (int matriceA[20][N]);
void Somma_Colonne(int matriceA[20][N], int v[N],float media[N]);
void insufficenti(int matriceA[20][N],float media[N]);
void leggi_Matrice (int matriceA[20][N]){
int i, j;
cout<<"\n\nScelta numero studenti max 20:";
cin>>M;
for (i=0 ; i<N ; i++){
for(j=0 ; j<N ; j++){
cout<<"\nInserisci il voto dello studente "<<i+1<<" nella materia "<<j+1<<" :";
cin >> matriceA[i][j];
}
}
return;
}
void stampa_Matrice (int matriceA[20][N]){
int i, j;
for(i=0;i<N;i++){
cout<<"\n materia - "<<i+1<<" = ";
for(j=0;j<M;j++){
cout<<setw(4)<<matriceA[j][i]<<" ; ";
}
}
return;
}
void Somma_Colonne(int matriceA[20][N], int v[N],float media[N]){
cout<<"\n\nMEDIA dei VOTI per ogni STUDENTE"<<endl;
int i, j;
for (j=0 ; j<M ; j++)
{
v[j]=0;//Azzero il vettore delle somme (v[j])dei voti per ogni studente.
for (i=0; i<N ; i++)
v[j] += matriceA[j][i];//Carico (v[j]):per ogni studente "j" sommo i voti "i" delle materie N
}
for (j=0 ; j<M; j++){
media[j]=v[j]/N;//Media = somma dei voti diviso N (materie)
cout<<"\nLa MEDIA dei voti dello studente "<<j+1<<" = "<< media[j]<<" ";
}
}
void insufficienti(int matriceA[20][N],float media[N]){
int i, j;
cout<<"\nMateria insufficiente - "<<i<<" = ";
for (j=0; j<M ; j++){
if (matriceA[j][i]<(float)media[j]){
matriceA[j][i]=matriceA[j][i];
}
else
matriceA[j][i]==0;
cout<<setw(4)<<"\nStudente "<<j<<" con insufficienza ="<<matriceA[j][i]<<endl;
}
}
int main () {
int matriceA[20][N], v[N];
float media[N];
cout<<"\n Matrice con dimensione massima 20x7 ";
leggi_Matrice(matriceA);
stampa_Matrice(matriceA);
Somma_Colonne(matriceA,v,media);
insufficenti(matriceA,media);
}
18/05/2018, 13:11
18/05/2018, 18:44
18/05/2018, 19:04
18/05/2018, 21:01
void insufficente(int matriceA[20][N],float media[N],int insuff[][N]){
int i, j;
cout<<endl;
for (j=0; j<M ; j++){
if (matriceA[j][i]<media[j]){
insuff[j][i]=matriceA[j][i];
}
for (j=0; j<M ; j++){
cout<<setw(4)<<"\nStudente "<<j+1<<" con insufficenza =";
for (i=0; i<N ; i++)
cout<<insuff[j][i]<<";";
} cout<<endl;
}
}
18/05/2018, 21:42
19/05/2018, 10:20
/*
Simulazione scrutini di una classe di M(da input) studenti con N(costante) materie.
Il programma deve mostrare a video :
i voti di tutta la classe;
la media di ogni studente;
i voti insufficienti di ogni studente;
*/
#include <iostream>
#include <cstdlib>
#include <iomanip>//manipolatore dell'output stream
using namespace std;
const int N=3;//Materie
int M;//studenti
// -- PROTOTIPI -- //
void carica_Matr(int matr_A[20][N]);
void stampa_Matr (int matr_A[20][N]);
void Calc_Med(int matr_A[20][N], int v[N],float med[N]);
void insuff(int matr_A[20][N],float med[N]);
// -- FUNZIONI -- //
void carica_Matr (int matr_A[20][N]){
int i, j;
cout<<"\n\nScelta numero studenti max 20:";
cin>>M;
for (i=0 ; i<M ; i++){
for(j=0 ; j<N ; j++){
cout<<"Inserisci il voto dello studente "<<i+1<<" nella materia "<<j+1<<" :";
cin >> matr_A[i][j];
}
}
return;
}
void stampa_Matr (int matr_A[20][N]){
int i, j;
for(i=0;i<N;i++){
cout<<"\n materia_"<<i+1<<" =";
for(j=0;j<M;j++){
cout<<setw(4)<<matr_A[j][i]<<";";
}
}
return;
}
void Calc_Med(int matr_A[20][N], int v[N],float med[N]){
cout<<"\n\nMEDIA dei VOTI per ogni STUDENTE"<<endl;
int i, j;
for (j=0 ; j<M ; j++)
{
v[j]=0;//Azzero il vettore delle somme (v[j])dei voti per ogni studente.
for (i=0; i<N ; i++)
v[j] += matr_A[j][i];//Carico (v[j]):per ogni studente "j" sommo i voti "i" delle materie N
}
for (j=0 ; j<M; j++){
med[j]=(float)v[j]/N;//Media = somma dei voti diviso N (materie)
cout<<setprecision(3)<<"\nLa MEDIA dei voti dello studente "<<j+1<<" = "<< med[j]<<" ";
}
}
void insuff(int matr_A[20][N],int inf[N]){
int i, j;
for (i=0; i<M ; i++){
int inf[N]={0};
if (matr_A[j][i]<6){
inf[i]==1;
}
for (j=0; j<M ; j++){
cout<<setw(4)<<"\nStudente "<<j+1<<" con insufficenza =";
for (i=0; i<N ; i++)
cout<<inf[i]<<";";
} cout<<endl;
}
}
int main () {
int matr_A[20][N], v[N],inf[N];
float med[N];
cout<<"\n Mat con dimensione massima 20x7 ";
carica_Matr(matr_A);
stampa_Matr(matr_A);
Calc_Med(matr_A,v,med);
insuff(matr_A,inf);
}
Skuola.net News è una testata giornalistica iscritta al Registro degli Operatori della Comunicazione.
Registrazione: n° 20792 del 23/12/2010.
©2000—
Skuola Network s.r.l. Tutti i diritti riservati. — P.I. 10404470014.
Powered by phpBB © phpBB Group - Privacy policy - Cookie privacy
phpBB Mobile / SEO by Artodia.