Assalmu'alaikum w.w.,
1. Menyusun Algoritma,
2. Struct, dan
3. Pogram C++.
1. ALGORITMA :
.
2. STRUCT :
class informatika{
public:
int inputdata();
int element();
private:
int jum;
};
struct mahasiswa{
char nama[20];
char nim[10];
char fak[25];
char pro[20];
};
class matakuliah{
public:
int inputan();
private:
int kode[5];
string matkul[50];
// char wp[5];//
int sks[10];
string nil[5];
};
3. PROGRAM C++ :
#include <iostream>
#include <cstdlib>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
class informatika{
public:
int inputdata();
int element();
private:
int jum;
};
struct mahasiswa{
char nama[20];
char nim[10];
char fak[25];
char pro[20];
};
class matakuliah{
public:
int inputan();
private:
int kode[5];
string matkul[50];
// char wp[5];//
int sks[10];
string nil[5];
};
//--------------- data diri--------------------//
int informatika::inputdata(){
mahasiswa daftar;
cout<<"Nama : "; cin>>daftar.nama;
cout<<"Nim : "; cin>>daftar.nim;
cout<<"Fakultas : "; cin>>daftar.fak;
cout<<"Prodi : "; cin>>daftar.pro;
}
int matakuliah::inputan(){
cout<<endl;
cout<<"---------------MENGHITUNG IPK-----------------"<<endl<<endl;
int jum;
cout<<"Jumlah Matakuliah Yang Di Ambil: "; cin>>jum;
string A,a,B,b,C,c,D,d,E,e;
int kali,jumlah=0,jumsks=0;
//----perulangan mengunakan do while---//
int i=0;
while(i<jum){
cout<<"Kode : "; cin>>kode[i];
cout<<"Matakuliah : "; cin>>matkul[i];
// cout<<"W/P : "; cin>>wp[i]; //
cout<<"SKS : "; cin>>sks[i];
cout<<"Nilai : "; cin>>nil[i];
cout<<endl;
cout<<"---------------------------"<<endl;
//-----proses konversi nilai Angka ke nomer -----//
if(nil[i]=="A"||nil[i]=="a"){
kali=4*sks[i];
}else if(nil[i]=="B"||nil[i]=="b"){
kali=3*sks[i];
}else if(nil[i]=="C"||nil[i]=="c"){
kali=2*sks[i];
}else if(nil[i]=="D"||nil[i]=="d"){
kali=1*sks[i];
}else
kali=0*sks[i];
//----proses mencari rata-rata----//
kali=kali+kali;
jumsks=jumsks+sks[i];
i++;
}
//---OUTPUT HASIL ----//
float ipk=kali/jumsks;
cout<<endl<<endl;
cout<<"-------------------------"<<endl;
cout<<"Jumlah SKS : "<<jumsks<<endl;
cout<<"Jumlah Matakuliah Diambil : "<<jum<<endl;
cout<<"IPK : "<<ipk<<endl;
cout<<"---------=========---------";
}
int main(int argc, char** argv) {
//---deklarasi class informatika ---//
informatika panggil;
panggil.inputdata();
//---deklarasi class matakuliah---//
matakuliah data;
data.inputan();
return 0;
}
Outputnya :
Semoga Bermanfaat.
Wasslamu'alaikum w.w.
Tidak ada komentar:
Posting Komentar