sexta-feira, 30 de novembro de 2012

Programa Notas e Idades - Linguagem C

PROGRAMA NOTAS E IDADES, vem mostrando como declarar, inicializar e utilizar Matrizes, Temos uma Matriz Bidimensional do tipo float, e três Matrizes Bidimensional de strings.
O programa começa mostrando uma mensagem, e depois de pressionar em qualquer tecla, vem a tela inicial;
Escolhido continuar, o programa já mostra as colunas: Alunos, Notas, idades e números de chamadas e seus respectivos resultados abaixo de cada coluna.
A função Pesquisa_Alunos(); permite fazer uma eficiente pesquisa dentro da Matriz Idades_Notas, usando o método de pesquisa sequencial.
A função Alunos( ); Imprime tanto a lista dos nomes dos alunos que estão na Matriz de tipo char de nome: Nomes_Alunos, como também,
itens da matriz Idades_Notas, mostrando a coluna das notas, das idades e dos numeros de chamadas. Ainda nesta função temos uma outra eficiete Pesquisa
que é feita dentro da Matriz de sting Nomes_Alunos [ 12 ] [ 21 ];. Temos ainda a função Idades(); Que imprime as notas, idades, e números de chamadas dos alunos, e faz um cálculo da maior e menor nota,
e da maior e menor idade.

Veja abaixo imagens do programa em execução:











Aproveite bem este código que está muito bom; foi criado no eclipse e tá rodando sem nenhum warnings


#include <conio.h>
#include <stdio.h>
#define ENCONTRADO 1
#define NAOENCONTRADO 0
void termina();void Idades();
float Idades_Notas [ 8 ] [ 3 ] =
{{10, 14.8, 10},
{9.5, 15.3, 8},
{8.6, 14, 21},
{9.7, 16.5, 19},
{6.1, 17.4, 27},
{7.7, 16.1, 3},
{8.3, 17, 7},
{7.3, 15.9, 33}};
char  Nomes_Alunos [ 12 ] [ 21 ] = {
{"João Henrique"},
{"Amanda Santos"},
{"Patrícia Gomes"},
{"Ricardo Souza"},
{"Cláudia Ferraz"},
{"Rafaela Silva"},
{"Samuel Júnior"},
{"Sandro Rúbens"},
{"ALUNOS"},
{"NOTAS"},
{"IDADES"},
{"NÚMEROS DE CHAMADAS"}};
char Mensagem [ ] [ 66 ] = {"Um certo Professor resolveu presentear seus oitos melhores alunos",
"pressione qualquer tecla para conhece - los",
"PRESSIONE QUALQUER TECLA"
};
char Narrador [ ] [ 67 ] = {"O Professor é muito responsável, ajude - o, a fazer uma pesquisa",
"para ter certeza que todos os alunos estão presentes",
"Digite o nome de um Aluno que você viu na lista : ",
"Não está entre os selecionados",
"Entre com um número de chamada de um aluno: "
};
void Janela5(){
int lin, col;
for ( lin = 0; lin <= 25; lin++ ){
for ( col = 0; col <= 80; col++ ){
gotoxy( col, lin );
if ( lin == 2 ){textbackground(LIGHTBLUE);printf( " ");}
if ( col == 1 ){textbackground(LIGHTBLUE);printf(" ");}
if ( lin == 25 ){textbackground(LIGHTBLUE);}
if ( col == 80 ){textbackground(LIGHTBLUE);printf(" ");}
}
}textbackground( BLACK);
}void inicio(){Janela5();
int i;void Alunos( );
textbackground(BLACK);
textcolor(LIGHTRED);gotoxy(30,7);printf("PROGRAMA NOTAS E IDADES");
textcolor(WHITE);gotoxy(8,10);printf("%s", Mensagem [ 0 ] );
textcolor(WHITE);gotoxy(8,11);printf("%s", Mensagem [ 1 ] );
getche();system("cls");
do{Janela5();
textcolor(LIGHTRED);gotoxy(30,7);printf("PROGRAMA NOTAS E IDADES");
textcolor(YELLOW);gotoxy(22,10);printf("Programa desenvolvido por:");
textcolor(LIGHTCYAN);gotoxy(49,10);printf("Samuel Lima");
textcolor(LIGHTGREEN);gotoxy(32,12);printf("sa_sp10@hotmail.com");
textcolor(LIGHTBLUE);gotoxy(22,14);printf("DIGITE    PARA SAIR OU   PARA CONTINUAR ");
textcolor(LIGHTRED);gotoxy(30,14);printf("1");textcolor(LIGHTRED);gotoxy(45,14);printf("2");
gotoxy(21,16);scanf("%d",&i);fflush(stdin);
if(i == 1){
textcolor(LIGHTRED);gotoxy(33,20);printf ("MUITO OBRIGADO");Sleep(1800);exit(0);
}
if(i == 2){system("cls");
Alunos( );system("cls");
}else {
textcolor(LIGHTRED);gotoxy(37,20);printf ("\aOPÇÃO ERRADA");Sleep(1800);system("cls");
}
}while(i);
}
void Pesquisa_Alunos(){
float num; int i;
do{system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(30,3);printf("PROGRAMA NOTAS E IDADES");
textcolor(WHITE);gotoxy(10,5);printf ("%s", Narrador [ 0 ] );
textcolor(WHITE);gotoxy(10,6);printf ("%s", Narrador [ 1 ] );
textcolor(YELLOW);gotoxy(22,8);printf ("%s", Narrador [ 4 ]);
textcolor(LIGHTRED);gotoxy(66,8);scanf ("%f", &num ); fflush(stdin);
for ( i = 0; i < 8; i++ ){
if ( Idades_Notas [ i ]  [ 2 ] == num )
break;
}
if ( i == 8 ){
textcolor(LIGHTCYAN);gotoxy(10,10);printf ("Este Aluno de Número    não está entre os selecionados");
textcolor(LIGHTRED);gotoxy(31,10);printf ("%.f", num);gotoxy(10,12);
getche();
}else{
textcolor(LIGHTCYAN);gotoxy(10,10);printf ("Este Aluno de Número    está sentado na cadeira   da sala.");
textcolor(LIGHTRED);gotoxy(31,10);printf ("%.f", num);
textcolor(LIGHTRED);gotoxy(58,10);printf ("%d", i);gotoxy(10,12);
getche();system("cls");termina();
}
}while(1);
}
void Alunos( ){
system("cls");
int  i = 0; int item, a;
char  nomes [ 17 ];Janela5();
textcolor(LIGHTRED);gotoxy(30,3);printf("PROGRAMA NOTAS E IDADES");
textcolor(LIGHTCYAN);gotoxy(21,5);printf ( "Veja abaixo a lista dos Alunos selecionados: " );
textcolor(LIGHTGREEN);gotoxy(10,7);printf ( "%s\t\t%s\t\t%s\t\t%s",  Nomes_Alunos[8], Nomes_Alunos[9], Nomes_Alunos[10], Nomes_Alunos[11]);    // ALUNOS, NOTAS
for ( i = 0; i < 8; i++ ){
textcolor(LIGHTBLUE);gotoxy(5, i + 9);
printf ("%s\t %.1f \t\t%.1f\t\t\t%.f",  Nomes_Alunos [ i ], Idades_Notas [ i ] [ 0 ],
Idades_Notas [ i ] [ 1 ], Idades_Notas [ i ] [ 2 ] );
Sleep(800);
}
textcolor(WHITE);gotoxy(32,21);printf("%s", Mensagem [ 2 ] );
getche( );system("cls");
do{Janela5();
textcolor(LIGHTRED);gotoxy(30,3);printf("PROGRAMA NOTAS E IDADES");
textcolor(WHITE);gotoxy(10,5);printf ( "%s", Narrador [ 0 ] );
textcolor(WHITE);gotoxy(10,6);printf ( "%s", Narrador [ 1 ] ) ;
textcolor(YELLOW);gotoxy(18,8);printf ( "%s", Narrador [ 2 ] ) ;
textcolor(LIGHTRED);gotoxy(10,10);scanf("%[^\n]s", nomes);fflush(stdin); // Usando scanf com espaço.
item = NAOENCONTRADO;
textcolor(LIGHTMAGENTA);gotoxy(10,10);
for ( i = 0; i <= 8; i++ ){
a = strcmp (& Nomes_Alunos [ i ] [ 0 ], nomes );
if ( a == 0 ){
textcolor(LIGHTMAGENTA);gotoxy(26,14);printf ("O Aluno %s está na lista", nomes);
textcolor(LIGHTMAGENTA);gotoxy(10,12);Sleep(1800);Idades();
item = ENCONTRADO;
break;
}
}
if (item == NAOENCONTRADO)
textcolor(LIGHTMAGENTA);gotoxy(18,14);printf ( "O Aluno %s %s", nomes, Narrador [ 3 ] ) ;
Sleep(1800);system("cls");
}while(1);
}
void Idades(){
int i;system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(30,3);printf("PROGRAMA NOTAS E IDADES");
textcolor(LIGHTBLUE);gotoxy(10,5);printf("Estas são as Notas dos Alunos:");
gotoxy(10,7);for(i = 0; i < 8; i++){
textcolor(LIGHTMAGENTA);printf(" %.1f ", Idades_Notas [ i ] [ 0 ] );
}
textcolor(LIGHTBLUE);gotoxy(10,9);printf("Estas são as Idades dos Alunos:");
gotoxy(10,11);for(i = 0; i < 8; i++){
textcolor(LIGHTMAGENTA);printf(" %.1f ", Idades_Notas [ i ] [ 1 ] );
}
textcolor(LIGHTBLUE);gotoxy(10,13);printf("Estes são os Números de chamadas dos Alunos:");
gotoxy(10,15);for(i = 0; i < 8; i++){
textcolor(LIGHTMAGENTA);printf(" %.f ", Idades_Notas [ i ] [ 2 ] );
}
getche();
int  f = 0;
float m = Idades_Notas [ f ] [ 0 ];
float g = Idades_Notas [ f ] [ 0 ];
for ( f = 0; f < 8; f++ ){
if (Idades_Notas [ f ] [ 0 ] > m ){
m = Idades_Notas [ f ] [ 0 ];
}
if (Idades_Notas [ f ] [ 0 ] < g ){
g = Idades_Notas [ f ] [ 0 ];
}
}
textcolor(LIGHTCYAN);gotoxy(8,17);printf("A maior Nota é de: ");
textcolor(LIGHTRED);gotoxy(39,17);printf("%.1f", m);
textcolor(LIGHTCYAN);gotoxy(8,19);printf("A menor Nota é de: ");
textcolor(LIGHTRED);gotoxy(39,19);printf("%.1f", g);
getche();
int  h = 0;
float j = Idades_Notas [ h ] [ 1 ];
float l = Idades_Notas [ h ] [ 1 ];
for ( h = 0; h < 8; h++ ){
if ( Idades_Notas [ h ] [ 1 ] > j ){
j = Idades_Notas [ h ] [ 1 ];
}
if ( Idades_Notas [ h ] [ 1 ] < l ){
l = Idades_Notas [ h ] [ 1 ];
}
}
textcolor(LIGHTCYAN);gotoxy(8,21);printf("A maior Idade é de: ");
textcolor(LIGHTRED);gotoxy(39,21);printf("%1.1f", j);
textcolor(LIGHTCYAN);gotoxy(8,23);printf("A menor Idade é de: ");
textcolor(LIGHTRED);gotoxy(39,23);printf("%1.1f", l);
getche();system("cls");Pesquisa_Alunos();
}
void termina(){
int i;
do{Janela5();
textcolor(LIGHTRED);gotoxy(30,6);printf("PROGRAMA NOTAS E IDADES");
textcolor(YELLOW);gotoxy(29,8);printf ("O QUE DESEJA FAZER AGORA?");
textcolor(LIGHTCYAN);gotoxy(18,10);printf ("OPERAR O PROGRAMA NOVAMENTE OU FINALIZÁ - LO ?");
textcolor(LIGHTBLUE);gotoxy(33,12);printf("DIGITE NO TECLADO");
textcolor(LIGHTRED);gotoxy(26,14);printf("[ 1 ]");
textcolor(LIGHTMAGENTA);gotoxy(32,14);printf("PARA FINALIZAR");
textcolor(LIGHTRED);gotoxy(26,16);printf("[ 2 ]");
textcolor(LIGHTMAGENTA);gotoxy(32,16);printf("PARA UMA NOVA OPERAÇÃO");
textcolor(LIGHTRED);gotoxy(26,18);printf("[ 3 ]");
textcolor(LIGHTMAGENTA);gotoxy(32,18);printf("PARA VOLTAR AO INÍCIO DO PROGRAMA");
gotoxy(26,20); scanf("%d",&i);fflush(stdin);
if(i == 1){
textcolor(LIGHTRED);gotoxy(33,21);printf ("MUITO OBRIGADO");Sleep(1800);exit(0);
}
if(i == 2){system("cls");Alunos( );}
if(i == 3){system("cls");inicio( );}
else {
textcolor(LIGHTBLUE);gotoxy(30,20);printf ("\aOPÇÃO ERRADA");Sleep(1800);system("cls");
}
}while(1);
}
int main(){
system ("title PROGRAMA NOTAS E IDADES");
inicio();
}

Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.