Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <windows.h>
- #include <string>
- #include <math.h>
- #define n 3
- using namespace std;
- double const pes1 = 0.15;
- double const pes2 = 0.5;
- double const pes3 = 0.35;
- int linh = -1, aux = 0;
- typedef struct aluno alu;
- struct aluno{
- string nome[n];
- double p1[n], p2[n], tr[n];
- string sta[n];};
- alu TB1;
- //Inicia funções de leitura
- string lernome(){
- system("cls");
- string N;
- cout << "\nDigite o Nome: ";
- cin >> N;
- return N;}
- double lerp1(){
- system("cls");
- double P1;
- cout << "\nDigite a nota da P1: ";
- cin >> P1;
- return P1;}
- double lerp2(){
- system("cls");
- double P2;
- cout << "\nDigite a nota da P2: ";
- cin >> P2;
- return P2;}
- double lertr(){
- system("cls");
- double TR;
- cout << "\nDigite a nota do trabalho: ";
- cin >> TR;
- return TR;}
- //Inicia funções de cálculo
- string getStatus(double P1, double P2, double TRAB){
- double media = (P1*pes3)+(P2*pes2)+(TRAB*pes1);
- if(media>=6) return "Aprovado";
- else if(media<6) return "Reprovado";}
- void inserirstruct(int linha, string NOM, double N1, double N2, double Ntrab){
- TB1.nome[linha] = NOM;
- TB1.p1[linha] = N1;
- TB1.p2[linha] = N2;
- TB1.tr[linha] = Ntrab;}
- void processarstruct(int linha){
- for(int i=0; i<=linha;i++){
- TB1.sta[i] = getStatus(TB1.p1[i], TB1.p2[i], TB1.tr[i]);
- }
- cout << "\n*** Dados armazenados com sucesso! ***\n\n" << endl;
- system("pause");
- }
- bool remover(string nome, int lin){
- if(TB1.nome[lin]==nome || (lin==0 && TB1.nome[0]==nome)) return true;
- else{
- for(int i=0; i<=lin; i++){
- if(TB1.nome[i]==nome){
- for(int j=i; j<lin; j++){ // atualiza todos os campos
- TB1.nome[j]=TB1.nome[j+1];
- TB1.p1[j]=TB1.p1[j+1];
- TB1.p2[j]=TB1.p2[j+1];
- TB1.tr[j]=TB1.tr[j+1];
- TB1.sta[j]=TB1.sta[j+1];
- }
- return true;
- }else{
- cout << "\n*** Nome não encontrado! ***\n\n" << endl;
- system("pause");
- return false;}
- }
- }
- }
- void exibir(int UL){
- for(int i=0;i<=UL;i++){
- cout << "\nNome: " << TB1.nome[i];
- cout << "\nP1: " << TB1.p1[i];
- cout << "\nP2: " << TB1.p2[i];
- cout << "\nTrabalho: " << TB1.tr[i];
- cout << "\nStatus: " << TB1.sta[i];
- cout << "\n" << endl;}
- system("pause");
- }
- int tela(){
- system("cls");
- int T;
- cout << "\n *** Média de alunos ***\n" << endl;
- cout << "\n1 - Incluir aluno \
- \n2 - Exibir informações\
- \n3 - Excluir aluno\
- \n4 - Sair\
- \n\nItem: ";
- cin >> T;
- return T;}
- void menu(){
- double nota1, nota2, notatr;
- string nomealuno, statusaluno, delnome;
- int tecla = -1;
- bool excluir;
- while(tecla!=4){//Inicio Menu
- tecla = tela();
- if(tecla==1){
- aux++;
- nomealuno = lernome();
- nota1 = lerp1();
- nota2 = lerp2();
- notatr = lertr();
- linh ++;
- inserirstruct(linh, nomealuno, nota1, nota2, notatr);
- Sleep(500);
- system("cls");
- cout << "\nSalvando informações..." << endl;
- processarstruct(linh);
- Sleep(500);
- }
- else if(tecla==2){
- system("cls");
- if (aux == 0) cout << "\n *** Sem registros ***\n" << endl;
- else cout << "\n *** Alunos cadastrados ***\n" << endl;
- exibir(linh);
- }
- else if(tecla==3){
- aux--;
- system("cls");
- cout << "\nDigite o nome que deseja excluir: ";
- cin >> delnome;
- if(remover(delnome, linh)){
- linh--;
- cout << "\n*** Nome excluído com sucesso! ***\n\n" << endl;
- system("pause");
- }
- }
- else if(tecla==4){
- system("cls");
- cout << "\n\n *** Bye Bye ***\n\n" << endl;
- }
- }//Fim Menu
- }
- int main(){
- setlocale(LC_ALL, "Portuguese");
- system("cls");
- cout << "\n *** Média de alunos ***\n" << endl;
- menu();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment