Skip to content

Instantly share code, notes, and snippets.

@corinchen
Created November 21, 2016 16:09
Show Gist options
  • Save corinchen/e838ec93d42815dd9b3f1481bb4402cd to your computer and use it in GitHub Desktop.
Save corinchen/e838ec93d42815dd9b3f1481bb4402cd to your computer and use it in GitHub Desktop.
CPP_AKHIR
//Program untuk menentukan nilai akhir melalui matriks GRADE dan BOBOT
#include <iostream>
using namespace std;
//fungsi nilai akhir
//bobot [k] bagaimana ya??
// Global variable
int soal, siswa;
int bobot[3] = {0, 0, 0 }; // 3 bobot, dari 3 soal
int bobotTotal = 0;
float grade[5][3]; // 2 siswa, 3 soal
float akhir[5] = {0, 0 , 0 , 0 , 0}; // nilai akhir dari 2 siswa
void baca() {
/*
Tentukan banyak soal dan siswa
*/
cout << "Masukkan banyaknya soal : ";
cin >> soal; //i
cout << "Masukkan banyak nya siswa : ";
cin >> siswa; //j
cout << endl;
/*
Masukkan nilai tiap siswa
*/
// Kenapa i dan j = 0?
// ingat, bahwa array itu mulai dari 0
// atau perhitungan dalam pemrograman, semua dimulai dari 0
for(int i = 0; i < soal; i++){
// Inisialisasi bobot[i]
bobot[i] = i + 1;
// supaya muncul 1 di layar, tambahkan saja + 1
cout << "=== BOBOT SOAL ke-" << i + 1 << " ===" << endl;
for(int j = 0; j < siswa; j++){
cout << "Masukkan nilai siswa ke-" << j + 1<< " : ";cin >> grade[j][i];
}
cout << endl;
// Jumlahkan bobot
bobotTotal += bobot[i];
}
}
void hitung() {
cout<<"OUTPUT :"<<endl;
for(int i = 0; i < soal; i++) {
cout<<" "<< bobot[i];
for(int j = 0; j < siswa; j++) {
cout <<" "<< grade[j][i];
akhir[j] += (grade[j][i] * bobot[i]);
}
cout << endl;
}
}
void cetak() {
cout<<endl;
cout<<"AKHIR : "<<endl;
cout<<endl;
for (int n = 0; n < siswa; n++) {
// hasil perkalian dan penjumlahan nilai
// lalu dibagi bobotTotal
akhir[n] /= bobotTotal;
printf(" %.1f " , akhir[n] );
}
}
int main() {
char jawab;
atas:
cout<<endl;
cout<<"====== PROGRAM MENGHITUNG NILAI AKHIR DENGAN OUTPUT MATRIKS======"<<endl;
cout<<endl;
baca();
hitung();
cetak();
cout<<endl;
cout<<endl;
cout<<" Apakah mau mengulang lagi?"<<endl;
cout<<"Tekan [Y]a untuk mengulang "<<endl;
cout<<"Tekan [N]o untuk berhenti "<<endl; cin>>jawab;
if(jawab=='Y'||jawab=='y'){
goto atas;
}
else if(jawab=='N'||jawab=='n'){
cout<<"Terima kasih "<<endl;
cout<<endl;
}
else{
cout<<"Keyword yang anda masukkan salah , coba lagi"<<endl;
cout<<endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment