Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- char ambilnilai(int nilai);
- float nilai_huruf(char huruf);
- typedef struct
- {
- int nilai;
- float sks, nip;
- char nmk[20],kode[10];
- char nh;
- }kul;
- typedef struct
- {
- char nim[15], nama[15], kls[1];
- float ipk;
- kul makul[10];
- } data;
- int main ()
- {
- int x,
- y,
- i,
- j,
- jumlah_sks;
- float jumlahnilai;
- cout<<"Masukkan Jumlah Mahasiswa = ";
- cin>>x;
- data mhs[x];
- for (y=0;y<x;y++)
- { jumlahnilai =0;
- jumlah_sks =0;
- cout<<"Mahasiswa ke-"<<y+1;
- cout<<"\nNama\t= ";cin>>mhs[y].nama;
- cout<<"Kelas\t= ";cin>>mhs[y].kls;
- cout<<"NIM\t= ";cin>>mhs[y].nim;
- cout<<"Masukkan Jumlah Matakuliah = ";cin>>i;
- for (j=0;j<i;j++)
- {
- cin.ignore();
- cout<<j+1<<". Nama Matakuliah = ";cin>>mhs[y].makul[j].nmk;
- cout<<" Kode Matakuliah = ";cin>>mhs[y].makul[j].kode;
- cout<<" Nilai = ";cin>>mhs[y].makul[j].nilai;
- mhs[y].makul[j].nh = ambilnilai(mhs[y].makul[j].nilai);
- cout<<" SKS =";cin>>mhs[y].makul[j].sks;
- cout<<endl;
- jumlah_sks+=mhs[y].makul[j].sks;
- jumlahnilai+= nilai_huruf(mhs[y].makul[j].nh);
- }
- mhs[y].ipk =jumlahnilai/jumlah_sks;
- cout<<endl;
- }
- //
- cout<<"\nOUTPUT\n";
- for (y=0;y<x;y++)
- {
- cout<<"\nMahasiswa ke-"<<y+1<<" = ";
- cout<<"\nNama\t= "<<mhs[y].nama;
- cout<<"\nNIM\t= "<<mhs[y].nim;
- cout<<"\nKelas\t= "<<mhs[y].kls;
- cout<<endl;
- 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;
- cout << setfill('=') << setw(63) << "\n" <<setfill(' ');
- cout<<endl;
- for (j=0;j<i;j++)
- {
- 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;
- }
- cout << setfill('=') << setw(63) << "\n" <<setfill(' ');
- cout<<"IPK = "<<setprecision(3)<<mhs[y].ipk;
- cout<<endl;
- }
- }
- char ambilnilai(int nilai){
- char huruf;
- if(nilai<=100&&nilai>=80)
- huruf='A';
- else
- if(nilai<80&&nilai>=60)
- huruf='B';
- else
- if(nilai<60&&nilai>=40)
- huruf='C';
- else
- if(nilai<40&&nilai>20)
- huruf='D';
- else
- huruf = 'E';
- return huruf;
- }
- float nilai_huruf(char huruf){
- float nilai;
- if(huruf=='A')
- nilai = 4.0;
- else
- if(huruf=='B')
- nilai = 3.0;
- else
- if(huruf=='C')
- nilai = 2.0;
- else
- if(huruf=='A')
- nilai = 1.0;
- else
- nilai = 0.0;
- return nilai;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement