Last active
March 6, 2018 08:32
-
-
Save kardoso/8cec628a326267ad96ccf8970be163dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//O único problema que não consegui resolver foi de digitar "FIM DA LISTA" para terminar | |
//Consequentemente o programa também não aceita nomes completos | |
//Apenas o primeiro nome, como; Diego, Karen, Renata... | |
//A média: 80, 100, 70, 90... | |
//Para terminar o programa é preciso digitar "fim" ou "FIM" | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int notaGeral = 0; | |
int totalAlunos = 0; | |
int contadorAltaRecomend = 0; | |
int contadorForteRecomend = 0; | |
int contadorRecomend = 0; | |
int contadorNaoRecomend = 0; | |
//estrutura lista encadeada | |
typedef struct dataNode{ | |
char nome[30]; | |
int media; | |
char recomendacao[30]; | |
} DataNode; | |
typedef struct node{ | |
DataNode data; | |
struct node* next; | |
} Node; | |
typedef struct list{ | |
int size; | |
Node* head; | |
} List; | |
//header | |
List* createList(); | |
void push(List* list, DataNode data); | |
void printList(List* list); | |
//Criar lista | |
List* createList(){ | |
//cria um ponteiro para alocar um espaço de memória | |
List* list = (List*) malloc(sizeof(List)); | |
list->size = 0; | |
list->head = NULL; | |
return list; | |
} | |
//Adicionar dados à lista | |
void push(List* list, DataNode data){ | |
//ponteiro | |
Node* node = (Node*) malloc(sizeof(Node)); | |
node->data = data; | |
node->next = list->head; | |
list->head = node; | |
list->size++; | |
} | |
//Mostrar dados da lista e dados finais | |
void printList(List* list){ | |
system("cls"); | |
Node* pointer = list->head; | |
if(pointer == NULL){ | |
printf("Lista vazia"); | |
} | |
else{ | |
while(pointer != NULL){ | |
notaGeral += pointer->data.media; | |
totalAlunos++; | |
printf("%s - %d - %s\n", &pointer->data.nome, pointer->data.media, &pointer->data.recomendacao); | |
pointer = pointer->next; | |
} | |
printf("\nMedia Geral: %d", notaGeral/totalAlunos); | |
printf("\nAltamente Recomendados: %d", contadorAltaRecomend); | |
printf("\nFortemente Recomendados: %d", contadorForteRecomend); | |
printf("\nRecomendados: %d", contadorRecomend); | |
printf("\nNao Recomendados: %d", contadorNaoRecomend); | |
} | |
printf("\n"); | |
} | |
//Função Principal | |
int main() { | |
List* alunos = createList(); | |
DataNode data; | |
//definir variáveis com inteiros | |
//data.media = 90; | |
//para definir variáveis com strings/char: | |
//char str[90] = "oi"; | |
//sprintf(data.nome, "%s", str); | |
//adicionar dados na lista | |
//push(alunos, data); | |
do{ | |
char _nome[30]; | |
printf("Digite o nome do aluno: "); | |
scanf("%s", &_nome); | |
//stricmp compara duas strings sem case sensitive | |
if(stricmp (_nome, "fim") == 0){ | |
break; | |
} | |
else{ | |
//definir o nome | |
sprintf(data.nome, "%s", _nome); | |
printf("Digite a media do aluno em porcentagem: "); | |
int _media; | |
scanf("%d", &_media); | |
//definir a media | |
data.media = _media; | |
//definir recomendação | |
char _altaRecomend[30] = "Altamente Recomendado"; | |
char _forteRecomend[30] = "Fortemente Recomendado"; | |
char _recomend[30] = "Recomendado"; | |
char _naoRecomend[30] = "Nao Recomendado"; | |
if(_media >= 90){ | |
sprintf(data.recomendacao, "%s", _altaRecomend); | |
contadorAltaRecomend++; | |
} | |
else if(_media < 90 && _media >= 80){ | |
sprintf(data.recomendacao, "%s", _forteRecomend); | |
contadorForteRecomend++; | |
} | |
else if(_media < 80 && _media >= 70){ | |
sprintf(data.recomendacao, "%s", _recomend); | |
contadorRecomend++; | |
} | |
else if(_media < 70){ | |
sprintf(data.recomendacao, "%s", _naoRecomend); | |
contadorNaoRecomend++; | |
} | |
push(alunos, data); | |
} | |
}while(1); | |
printList(alunos); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment