#include <conio.h>
#include <iostream.h>
#include <stdio.h>
//membuat struct mahasiswa
struct mahasiswa{
char nim[4];
char nama[30];
};
struct nilai{
float mid;
float tugas;
float uas;
char huruf[2];
};
mahasiswa mhs[100];
nilai nil[100];
int jmlMhs=1;
//Menu Utama
void menuUtama(){
clrscr();
cout<<"------------------\n";
cout<<" MENU UTAMA \n";
cout<<"------------------\n\n";
cout<<" [1] Input Data Mahasiswa\n";
cout<<" [2] Tampilkan Data Mahasiswa\n";
cout<<" [3] Keluar\n\n";
cout<<"------------------\n";
cout<<"Pilihan : ";
}
//input data mahasiswa
void inputData(){
char pil;
float tot=0;
clrscr();
cout<<"-------------------------------\n";
cout<<" Input Data Mahasiswa ke ["<<jmlMhs<<"] \n";
cout<<"-------------------------------\n\n";
cout<<" -> NIM : ";
gets(mhs[jmlMhs].nim);
cout<<" -> Nama : ";
gets(mhs[jmlMhs].nama);
cout<<" -> MID : ";
cin>>nil[jmlMhs].mid;
cout<<" -> UAS : ";
cin>>nil[jmlMhs].uas;
cout<<" -> TUGAS : ";
cin>>nil[jmlMhs].tugas;
tot=0.3f*nil[jmlMhs].mid + 0.3f*nil[jmlMhs].uas + 0.4f*nil[jmlMhs].tugas;
if(tot>79){
strcpy(nil[jmlMhs].huruf,"A");
}else if((tot>=60)&&(tot<=79)){
strcpy(nil[jmlMhs].huruf,"B");
}else if((tot>=40)&&(tot<=59)){
strcpy(nil[jmlMhs].huruf,"C");
}else if((tot>=1)&&(tot<=39)){
strcpy(nil[jmlMhs].huruf,"D");
}else {
strcpy(nil[jmlMhs].huruf,"E");
}
cout<<endl<<endl;
jmlMhs++;
cout<<"Input data lagi (Y/N)? :";
cin>>pil;
if (pil=='Y' || pil=='y')
inputData();
else
menuUtama();
}
void tampilData(){
clrscr();
cout<<"-------------------------------\n";
cout<<" Tampil Data Mahasiswa \n";
cout<<"-------------------------------\n\n";
cout<<"---------------------------------------------------------\n";
gotoxy(1,6);
cout<<"| NIM ";
gotoxy(7,6);
cout<<"| Nama ";
gotoxy(30,6);
cout<<"| MID ";
gotoxy(35,6);
cout<<"| UAS ";
gotoxy(40,6);
cout<<"| TUGAS ";
gotoxy(49,6);
cout<<"| HURUF ";
gotoxy(57,6);
cout<<"|";
cout<<endl;
cout<<"-----------------------------"
<<"----------------------------\n";
for (int i=1; i<jmlMhs; i++){
gotoxy(1,i+7);
cout<<"| "<<mhs[i].nim;
gotoxy(7,i+7);
cout<<"| "<<mhs[i].nama;
gotoxy(30,i+7);
cout<<"| "<<nil[i].mid;
gotoxy(35,i+7);
cout<<"| "<<nil[i].uas;
gotoxy(40,i+7);
cout<<"| "<<nil[i].tugas;
gotoxy(49,i+7);
cout<<"| "<<nil[i].huruf;
gotoxy(57,i+7);
cout<<"|";
cout<<endl;
}
cout<<"------------------------------"
<<"---------------------------\n\n";
cout<<"Tekan sembarang tombol untuk "
<<"kembali ke menu utama...";
getch();
}
void main(){
int pil;
do {
menuUtama();
cin>>pil;
switch (pil){
case 1 :
inputData();
break;
case 2 :
tampilData();
break;
case 3 :
break;
}
}while(pil!=3);
getch();
}
Tidak ada komentar:
Posting Komentar