Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <iomanip>
- using namespace std;
- bool next = true;
- int jmlMhs;
- string mhs[20][2];
- int nilai[20][4];
- void getMhs();
- void display();
- char getGrade(int nilai);
- float getAverage();
- int getMax();
- int getMin();
- int main()
- {
- do{
- system("cls");
- cout << "================================" << endl;
- cout << "========= Hitung Nilai =========" << endl;
- cout << "================================" << endl;
- cout << "Jumlah mahasiswa (max 30) : " ;
- cin >> jmlMhs;
- getMhs();
- display();
- char x;
- cout << endl << "Ulang kembali ? (Y/N)" << endl;
- cin >> x;
- if(x == 'N' || x == 'n')
- next = false;
- }while(next == true);
- return 0;
- }
- void display(){
- system("cls");
- cout << " DAFTAR NILAI" << endl;
- cout << " PRODI TEKNIK INFORMATIKA" << endl;
- cout << "=================================================================" << endl;
- cout << ": No : NIM : NAMA : UTS : UAS : TUGAS : GRADE :" << endl;
- cout << "=================================================================" << endl;
- for(int i = 0; i < jmlMhs; i++){
- nilai[i][3] = (nilai[i][0] + nilai[i][1] + nilai[i][2]) / 3;
- cout << ":" << setw(3) << i+1 << setw(2) << ":"<< setw(8) << mhs[i][0] << setw(4)
- << ":" << setw(15) << mhs[i][1] << setw(4) << ":" << setw(4) << nilai[i][0] << setw(2)
- << ":" << setw(4) << nilai[i][1] << setw(2) << ":" << setw(4) << nilai[i][2] << setw(4)
- << ":" << setw(4) << getGrade(nilai[i][3]) << setw(4) << ":" << endl;
- }
- cout << "=================================================================" << endl;
- cout << "Jumlah data : " << jmlMhs << endl;
- cout << "Rata kelas : " << getAverage() << endl;
- cout << "Nilai tertinggi : " << getMax() << endl;
- cout << "Nilai terendah : " << getMin() << endl;
- }
- void getMhs(){
- system("cls");
- for(int i = 0; i < jmlMhs; i++){
- cout << "===================" << endl;
- cout << "=== Mahasiswa " << i+1 << " ===" << endl;
- cout << "===================" << endl;
- cout << "NIM : ";
- cin >> mhs[i][0];
- cout << "Nama : ";
- cin >> mhs[i][1];
- cout << "UTS : ";
- cin >> nilai[i][0];
- cout << "UAS : ";
- cin >> nilai[i][1];
- cout << "Tugas : ";
- cin >> nilai[i][2];
- cout << endl;
- }
- }
- float getAverage(){
- float jml = 0;
- for(int i = 0; i < jmlMhs; i++){
- jml += nilai[i][3];
- }
- return jml / jmlMhs;
- }
- char getGrade(int nilai){
- if(nilai <= 50)
- return 'E';
- else if(nilai <= 60)
- return 'D';
- else if(nilai <= 70)
- return 'C';
- else if(nilai <= 80)
- return 'B';
- else
- return 'A';
- }
- int getMax(){
- int max = nilai[0][3];
- for(int i = 0; i < jmlMhs; i++){
- if(nilai[i][3] > max)
- max = nilai[i][3];
- }
- return max;
- }
- int getMin(){
- int min = nilai[0][3];
- for(int i = 0; i < jmlMhs; i++){
- if(nilai[i][3] < min)
- min = nilai[i][3];
- }
- return min;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement