0
I have to make a code where you’re asked to develop a program that controls the bimonthly grades of 10 students in a classroom. The programme in question shall perform the following routines::
- Enroll the 10 students and their grades;
- Classify registered students;
- Correct students and/or grades that have been registered with errors;
- Search students by name;
- List approved students (average >7);
- List failed students (mean <7).
I was able to do the registration, the research and the editing, I’m just not able to make it show the approved and failed students. I appreciate your help. At the moment I am tested with 4 names, to facilitate the test.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#define cls system("cls");
int main(){
int i,j,x,proc,flag,alt;
char pesq[90];float media;
struct caderno
{
char nome[80];
float n1,n2,n3,n4;
};
caderno m[5];
//CADASTRO
for (i=0; i<5; i++){
printf ("....Cadastro de alunos e suas notas....\n");
printf ("Nome do aluno:");
fflush(stdin);
fgets (m[i].nome, 80, stdin);
printf ("Nota do primeiro bimestre:");
scanf ("%f",&m[i].n1);
printf ("Nota do segundo bimestre:");
scanf ("%f",&m[i].n2);
printf ("Nota do terceiro bimestre:");
scanf ("%f",&m[i].n3);
printf ("Nota do quarto bimestre:");
scanf ("%f",&m[i].n4);
printf ("\n");
}
int op;
do{
printf ("Digite a opcao desejada:\n\n");
printf ("1 - Listar alunos cadastrados\n");
printf ("2 - Corrigir Dados\n");
printf ("3 - Pesquisar por aluno\n");
printf ("4 - Listar alunos aprovados\n");
printf ("5 - Listar alunos reprovados\n");
printf ("6 - Sair");
scanf ("%d",&op);
switch (op){
//LISTAR
case 1:{
printf ("....Listagem de Alunos....");
for (i=1; i<5; i++)
{
for (j=i+1; j<5; j++)
{
if ( strcmp(m[i].nome, m[j].nome ) > 0 )
{
m[0] = m[i];
m[i] = m[j];
m[j] = m[0];
}
}
}
for (i=1;i<5;i++)
{
printf("Nome: %s\n",m[i].nome);
}
break;
//CORREÇÃO
case 2:{
char nom[30];
float n1,n2,n3,n4;
flag=0;
//cls aqui
printf ("\n....Editar Dado....\n");
for (i=1;i<6;i++)
printf("Nome: %s\n",m[i].nome);
printf( "\nQual nome desejar editar: ");
fflush(stdin);
fgets(nom,29,stdin);
for(i=1;i<6;i++)
if(strcmp(nom,m[i].nome) == 0 )
{
flag = 1;
printf("Novo Nome:");
fgets(nom,29,stdin);
strcpy(m[i].nome,nom);
{
printf ("Nota 1:");
scanf ("%f",&m[i].n1);
{
printf ("Nota 2:");
scanf ("%f",&m[i].n2);
{
printf ("Nota 3:");
scanf ("%f",&m[i].n3);
{
printf ("Nota 4:");
scanf ("%f",&m[i].n4);
}
printf("Edicao realizada com sucesso !\n");
}
if( ! flag )
printf("nNome inesistente!\n");
break;
}
//PESQUISA
case 3:{
//cls aqui
printf ("\n|....Pesquisa....|\n");
printf ("Qual aluno deseja pesquisar: \n");
fflush(stdin);
fgets (pesq,90,stdin);
i=0;
proc=0;
while (i<5 && proc==0)
{
if (strcmp(m[i].nome,pesq)==0)
proc = 1;
else
i=i+1;
}
if (proc==1)
{
printf ("Aluno pesquisado: %s\n",m[i].nome);
printf ("Nota 1: %s\n",m[i].n1);
printf ("Nota 2: %s\n",m[i].n2);
printf ("Nota 3: %s\n",m[i].n3);
printf ("Nota 4: %s\n",m[i].n4);
}
else
printf ("\nNome invalido");
break;
}
//ALUNOS APROVADOS
case 4:{
}
break;
//ALUNOS REPROVADOS
case 5:{
}
break;
//SAIR
case 6:{
printf ("Saindo");
break;
default:
printf ("Opcao invalido");
}
}
}
}
}
}
}while( op!=6 );
return 0;
}
Review the usage of your array. The index of an array varies from 0 to size_do_array-1, just as you stated
caderno m[5];
can’t dofor (i=1;i<6;i++) printf("Nome: %s\n",m[i].nome);
as it will be referencing a memory area outside the allocated area. For what reason you do not declare each student’s grades as well as an array?– anonimo
To show the students/reprobates, you will have to go through the whole vector, and perform the calculation, and if you satisfy the calculation, print on screen.
– sgtcortez