Membuat program data mahasiswa menggunakan C++

#include "iostream"

using namespace std;

class Data{
friend ostream& operator << (ostream&, Data&);
friend istream& operator >> (istream&, Data&);

private:
string nama[50];
int i, b[20], x, y,max,min;
float a[20],total, rata;

public:
Rekap()
{
cout<<"=====================\n";
cout<<"Rekap Nilai Mahasiswa\n";
cout<<"=====================\n\n";
}
};

ostream& operator << (ostream& isi, Data& ga){
string nama[50];
int i, b[20], x, y,max,min;
float a[20],total, rata;
isi<<"\n\nHasil Rekap Nilai Mahasiswa";
 isi<<"\n==========================\n";
 isi<<"||Nama || Nilai||\n";
 isi<<"==========================\n";
for(i=1;i<=ga.x;i++){

isi<<"||"<<ga.nama[i]<<" ||  "<< ga.a[i]<<"  ||\n";


}
total=0;
for(i=1;i<=ga.x;i++){

ga.total = ga.total + ga.a[i];
if ( i == 1 ) {
             ga.min = ga.a[i];
             ga.max = ga.a[i];
            }
            else if ( ga.min > ga.a[i] ) {
               ga.min = ga.a[i];
            }
            else if ( ga.max < ga.a[i]) {
               ga.max = ga.a[i];
           }
           else {}
           }

    isi <<"==========================\n";
    ga.rata = ga.total / ga.x;
    isi<<"|| Total ||  "<<ga.total<<" ||";
    isi<<"\n|| Rata - Rata ||  "<<ga.rata<<"  ||\n";
    isi<<"==========================\n";
    isi << "||Nilai Max ||  " <<  ga.max <<"  ||"<< endl;
    isi << "||Nilai Min ||  " <<  ga.min <<"  ||"<< endl;



}
istream& operator >> (istream& input, Data& gg){
string nama[50];
int i, b[20], x, y,max,min;
float a[20],total, rata;

cout<<"Masukan Jumlah Data = ";
input>>gg.x;

for(i=1; i<=gg.x; i++){
cout<<"Mahasiswa "<<i<<endl;
cout<<"Nama Mahasiswa = ";
input>>gg.nama[i];
cout<<"Masukkan Nilai = ";
input>>gg.a[i];
}
}
main(){
Data a;
cin>>a;
cout<<a;


return 0;
}

Posting Komentar

Lebih baru Lebih lama