1. Input Data Mahasiswa menggunakan Array
Dengan C++
#include <cstdlib>
#include <iostream>
using namespace std;
class mahasiswa {
public:
int i,n;
struct
{
char nim[5];
char nama[15];
string nil1;
string nil2;
string nil3;
char fakultas[40];
char prodi[20];
char alamat[50];
float nilai;
} mhs[80];
void masuk(int n);
void proses(int n);
};
void mahasiswa::masuk( int n){
for(i=1; i<=n; i++)
{
cout<<" Data Ke -"<<i<<" "<<endl;
cout<<" masukan NIM = "; cin>>mhs[i].nim;
cout<<" masukan Nama = "; cin>>mhs[i].nama;
cout<<" masukan fakultas = "; cin>>mhs[i].fakultas;
cout<<" masukan prodi = "; cin>>mhs[i].prodi;
cout<<" masukan alamat = "; cin>>mhs[i].alamat;
cout<<" masukan Nilai Akhir B.indonesia 3 sks (A,B,C,D,E) = "; cin>>mhs[i].nil1;
if(mhs[i].nil1=="A")
mhs[i].nilai=mhs[i].nilai+4*3;
else if(mhs[i].nil1=="B")
mhs[i].nilai=mhs[i].nilai+3*3;
else if(mhs[i].nil1=="C")
mhs[i].nilai=mhs[i].nilai+2*3;
else if(mhs[i].nil1=="D")
mhs[i].nilai=mhs[i].nilai+1*3;
cout<<" masukan Nilai Akhir B.inggris 3 sks (A,B,C,D) = "; cin>>mhs[i].nil2;
if(mhs[i].nil2=="A")
mhs[i].nilai=mhs[i].nilai+4*3;
else if(mhs[i].nil2=="B")
mhs[i].nilai=mhs[i].nilai+3*3;
else if(mhs[i].nil2=="C")
mhs[i].nilai=mhs[i].nilai+2*3;
else if(mhs[i].nil2=="D")
mhs[i].nilai=mhs[i].nilai+1*3;
cout<<" masukan Nilai Akhir kalkullus 3 sks (A,B,C,D) = "; cin>>mhs[i].nil3;
if(mhs[i].nil3=="A")
mhs[i].nilai=mhs[i].nilai+4*3;
else if(mhs[i].nil3=="B")
mhs[i].nilai=mhs[i].nilai+3*3;
else if(mhs[i].nil3=="C")
mhs[i].nilai=mhs[i].nilai+2*3;
else if(mhs[i].nil3=="D")
mhs[i].nilai=mhs[i].nilai+1*3;
cout<<endl;
}
}
void mahasiswa::proses(int n){
for(i=1; i<=n; i++)
{
cout<<" Data Ke -"<<i<<" "<<endl;
cout<<" Nama = "<<mhs[i].nama<<endl;
cout<<" NIM = "<<mhs[i].nim<<endl;
cout<<" fakultas = "<<mhs[i].fakultas<<endl;
cout<<" prodi = "<<mhs[i].prodi<<endl;
cout<<" alamat = "<<mhs[i].alamat<<endl;
cout<<" Nilai IPK = "<<mhs[i].nilai/9<<endl;
}
}
int main(int argc, char *argv[])
{
mahasiswa k;
int n;
cout<<" masukan jumlah siswa=";cin>>n;
k.masuk(n);
k.proses(n);
system("pause");
return 0;
}
Hasil Compile
2. data nilai dalam array semuanya dijumlah dengan terlebih dahulu di kali sks
3. setelah selesai jumlah semua di bagi jumlah sks
4. maka akan tampil Outputnya yaitu data mahasiswa dan nilai IPK..
#include <cstdlib>
#include <iostream>
using namespace std;
class mahasiswa {
public:
int i,n;
struct
{
char nim[5];
char nama[15];
string nil1;
string nil2;
string nil3;
char fakultas[40];
char prodi[20];
char alamat[50];
float nilai;
} mhs[80];
void masuk(int n);
void proses(int n);
};
void mahasiswa::masuk( int n){
for(i=1; i<=n; i++)
{
cout<<" Data Ke -"<<i<<" "<<endl;
cout<<" masukan NIM = "; cin>>mhs[i].nim;
cout<<" masukan Nama = "; cin>>mhs[i].nama;
cout<<" masukan fakultas = "; cin>>mhs[i].fakultas;
cout<<" masukan prodi = "; cin>>mhs[i].prodi;
cout<<" masukan alamat = "; cin>>mhs[i].alamat;
cout<<" masukan Nilai Akhir B.indonesia 3 sks (A,B,C,D,E) = "; cin>>mhs[i].nil1;
if(mhs[i].nil1=="A")
mhs[i].nilai=mhs[i].nilai+4*3;
else if(mhs[i].nil1=="B")
mhs[i].nilai=mhs[i].nilai+3*3;
else if(mhs[i].nil1=="C")
mhs[i].nilai=mhs[i].nilai+2*3;
else if(mhs[i].nil1=="D")
mhs[i].nilai=mhs[i].nilai+1*3;
cout<<" masukan Nilai Akhir B.inggris 3 sks (A,B,C,D) = "; cin>>mhs[i].nil2;
if(mhs[i].nil2=="A")
mhs[i].nilai=mhs[i].nilai+4*3;
else if(mhs[i].nil2=="B")
mhs[i].nilai=mhs[i].nilai+3*3;
else if(mhs[i].nil2=="C")
mhs[i].nilai=mhs[i].nilai+2*3;
else if(mhs[i].nil2=="D")
mhs[i].nilai=mhs[i].nilai+1*3;
cout<<" masukan Nilai Akhir kalkullus 3 sks (A,B,C,D) = "; cin>>mhs[i].nil3;
if(mhs[i].nil3=="A")
mhs[i].nilai=mhs[i].nilai+4*3;
else if(mhs[i].nil3=="B")
mhs[i].nilai=mhs[i].nilai+3*3;
else if(mhs[i].nil3=="C")
mhs[i].nilai=mhs[i].nilai+2*3;
else if(mhs[i].nil3=="D")
mhs[i].nilai=mhs[i].nilai+1*3;
cout<<endl;
}
}
void mahasiswa::proses(int n){
for(i=1; i<=n; i++)
{
cout<<" Data Ke -"<<i<<" "<<endl;
cout<<" Nama = "<<mhs[i].nama<<endl;
cout<<" NIM = "<<mhs[i].nim<<endl;
cout<<" fakultas = "<<mhs[i].fakultas<<endl;
cout<<" prodi = "<<mhs[i].prodi<<endl;
cout<<" alamat = "<<mhs[i].alamat<<endl;
cout<<" Nilai IPK = "<<mhs[i].nilai/9<<endl;
}
}
int main(int argc, char *argv[])
{
mahasiswa k;
int n;
cout<<" masukan jumlah siswa=";cin>>n;
k.masuk(n);
k.proses(n);
system("pause");
return 0;
}
Hasil Compile