Tuesday, 30 May 2023

Program Nilai

 #include <iostream>

#include <iomanip>

using namespace std;


int main (){

string nama[10];

float fisika[4],mtk[4],kimia[4],biologi[4], rata[4];

float  t_fisika, t_mtk, t_kimia, t_biologi;

int jml;

cout<<"-----------------------------\n";

cout<<"Masukan Jumlah Mahasiswa : ";

cin>>jml;

cout<<"-----------------------------\n";

cout<<endl;

for ( int i = 1; i <= jml; i++ ){

cout<<endl;

cout<<"Data ke-"<<i<<endl;

cout<<"Masukan Nama               : ";

cin>>nama[i];

cout<<"Masukan Nilai Fisika       : ";

cin>>fisika[i];

t_fisika += fisika[i]; 

cout<<"Masukan Nilai Matematika   : ";

cin>>mtk[i];

t_mtk+= mtk[i];

cout<<"Masukan Nilai Kimia        : ";

cin>>kimia[i];

t_kimia += kimia[i];

cout<<"Masukan Nilai Biologi      : ";

cin>>biologi[i];

t_biologi += biologi[i];

rata[i] = (fisika[i] + mtk[i] + kimia[i] + biologi[i] ) / 4 ;

}


t_fisika /= jml;

t_mtk /= jml;

t_kimia /= jml;

t_biologi /= jml;


cout<<endl;

cout<<"---------------------------------------------------------------------------------------------------------------\n";

cout<<"|      Nama       |  Nilai Fisika  |  Nilai matematika  |  Nilai Kimia  |  Nlai Biologi  |  Nilai rata - rata  |\n";

cout<<"---------------------------------------------------------------------------------------------------------------\n";

for ( int k = 1; k <= jml; k++ ){

cout<<setw(12)<<nama[k]<<setw(17)<<fisika[k]<<setw(16)<<mtk[k]<<setw(19)<<kimia[k]<<setw(19)<<biologi[k]<<setw(16)<<setprecision(2)<<rata[k]<<endl;

}

cout<<"---------------------------------------------------------------------------------------------------------------\n";

cout<<"|    rata_rata    |"<<setprecision(2)<<setw(11)<<t_fisika<<setprecision(2)<<setw(15)<<setprecision(2)<<t_mtk<<setprecision(2)<<setw(19)<<t_kimia<<setprecision(2)<<setw(19)<<t_biologi<<endl;

cout<<"---------------------------------------------------------------------------------------------------------------\n";

No comments:

Post a Comment