Advertisement
agusbd

wulan

Mar 12th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. char ambilnilai(int nilai);
  7. float nilai_huruf(char huruf);
  8.  
  9. typedef struct
  10. {
  11.     int nilai;
  12.     float sks, nip;
  13.     char nmk[20],kode[10];
  14.     char nh;
  15. }kul;
  16. typedef struct
  17. {
  18.     char nim[15], nama[15], kls[1];
  19.     float ipk;
  20.     kul makul[10];
  21. } data;
  22.  
  23. int main ()
  24. {
  25.     int x,
  26.         y,
  27.         i,
  28.         j,
  29.         jumlah_sks;
  30.     float jumlahnilai;
  31.  
  32.     cout<<"Masukkan Jumlah Mahasiswa = ";
  33.     cin>>x;
  34.     data mhs[x];
  35.     for (y=0;y<x;y++)
  36.     {   jumlahnilai =0;
  37.         jumlah_sks =0;
  38.         cout<<"Mahasiswa ke-"<<y+1;
  39.         cout<<"\nNama\t= ";cin>>mhs[y].nama;
  40.         cout<<"Kelas\t= ";cin>>mhs[y].kls;
  41.         cout<<"NIM\t= ";cin>>mhs[y].nim;
  42.         cout<<"Masukkan Jumlah Matakuliah = ";cin>>i;
  43.         for (j=0;j<i;j++)
  44.         {
  45.             cin.ignore();
  46.             cout<<j+1<<". Nama Matakuliah = ";cin>>mhs[y].makul[j].nmk;
  47.             cout<<"   Kode Matakuliah = ";cin>>mhs[y].makul[j].kode;
  48.             cout<<"   Nilai = ";cin>>mhs[y].makul[j].nilai;
  49.             mhs[y].makul[j].nh = ambilnilai(mhs[y].makul[j].nilai);
  50.             cout<<"   SKS   =";cin>>mhs[y].makul[j].sks;
  51.             cout<<endl;
  52.             jumlah_sks+=mhs[y].makul[j].sks;
  53.             jumlahnilai+= nilai_huruf(mhs[y].makul[j].nh);
  54.         }
  55.         mhs[y].ipk =jumlahnilai/jumlah_sks;
  56.          cout<<endl;
  57.     }
  58.  
  59.  
  60.     //
  61.  
  62.     cout<<"\nOUTPUT\n";
  63.     for (y=0;y<x;y++)
  64.     {
  65.         cout<<"\nMahasiswa ke-"<<y+1<<" = ";
  66.         cout<<"\nNama\t= "<<mhs[y].nama;
  67.         cout<<"\nNIM\t= "<<mhs[y].nim;
  68.         cout<<"\nKelas\t= "<<mhs[y].kls;
  69.  
  70.         cout<<endl;
  71.         cout << "\n Kode Makul " << setw(2) << "|" << setw(2) << " Nama Makul " << setw(2) << "|" << setw(2) << " Nilai Angka " << setw(1) << "|" << setw(2) << " Nilai Huruf " << setw (1) << "|" << setw(2) << " SKS " << setw(1) << "|" << endl;
  72.         cout << setfill('=') << setw(63) << "\n" <<setfill(' ');
  73.         cout<<endl;
  74.         for (j=0;j<i;j++)
  75.         {
  76.  
  77.             cout<<"  "<<mhs[y].makul[j].kode<<setw(6)<<"|"<<setw(6)<<mhs[y].makul[j].nmk<<setw(5)<<"|"<<setw(7)<<mhs[y].makul[j].nilai<<setw(7)<<"|"<<setw(6)<<mhs[y].makul[j].nh<<setw(8)<<"|"<<setw(3)<<mhs[y].makul[j].sks<<setw(3)<<"|"<<endl;
  78.  
  79.  
  80.         }
  81.  
  82.         cout << setfill('=') << setw(63) << "\n" <<setfill(' ');
  83.         cout<<"IPK = "<<setprecision(3)<<mhs[y].ipk;
  84.         cout<<endl;
  85.     }
  86. }
  87.  
  88. char ambilnilai(int nilai){
  89.  
  90.     char huruf;
  91.  
  92.     if(nilai<=100&&nilai>=80)
  93.         huruf='A';
  94.     else
  95.     if(nilai<80&&nilai>=60)
  96.         huruf='B';
  97.     else
  98.     if(nilai<60&&nilai>=40)
  99.         huruf='C';
  100.     else
  101.     if(nilai<40&&nilai>20)
  102.         huruf='D';
  103.     else
  104.         huruf = 'E';
  105.  
  106.     return huruf;
  107.  
  108. }
  109.  
  110. float nilai_huruf(char huruf){
  111.  
  112.     float nilai;
  113.     if(huruf=='A')
  114.         nilai = 4.0;
  115.     else
  116.     if(huruf=='B')
  117.         nilai = 3.0;
  118.     else
  119.     if(huruf=='C')
  120.         nilai = 2.0;
  121.     else
  122.     if(huruf=='A')
  123.         nilai = 1.0;
  124.     else
  125.         nilai = 0.0;
  126.     return nilai;
  127. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement