0% found this document useful (0 votes)
25 views5 pages

Adi Nugraha (065.13.016) Tugas 2 - Program Hitung IPS: 1. Source Code Program (Tanpapenggunaanfungsi)

This document contains the source code for a C++ program that calculates a student's GPA (IPS in Indonesian). It includes code both with and without using functions. The program defines a struct to store course data like code, name, credits, and grade. It has functions to read in the course data, calculate the grade points and credits for each course, sum the total grade points and credits, and calculate the GPA. The output prints the course details and calculated GPA. The code with functions separates the input, calculation, and output logic into different functions.

Uploaded by

adi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views5 pages

Adi Nugraha (065.13.016) Tugas 2 - Program Hitung IPS: 1. Source Code Program (Tanpapenggunaanfungsi)

This document contains the source code for a C++ program that calculates a student's GPA (IPS in Indonesian). It includes code both with and without using functions. The program defines a struct to store course data like code, name, credits, and grade. It has functions to read in the course data, calculate the grade points and credits for each course, sum the total grade points and credits, and calculate the GPA. The output prints the course details and calculated GPA. The code with functions separates the input, calculation, and output logic into different functions.

Uploaded by

adi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Adi Nugraha (065.13.

016)
Tugas 2 Program Hitung IPS
1. Source code program (tanpapenggunaanfungsi) :
#include <iostream>
#include <cstring>
using namespace std;

struct Matakuliah{
char kodeMK[7];
char namaMK[10];
int sks;
char nilai[3];
};

int i;
void bacaInput(Matakuliah data[], int jumlahMK){
for(i=0; i<jumlahMK; i++){
cout<< "Data Matakuliah #" << i+1 <<endl;
cout<< "KodeMatakuliah ? ";
cin>> data[i].kodeMK;
cout<< "NamaMatakuliah ? " ;
cin>> data[i].namaMK;
cout<< "SKS ? ";
cin>> data[i].sks;
cout<< "Nilai ? ";
cin>> data[i].nilai;
cout<<endl;
}
}
void hitungNilai(Matakuliah data[], int jumlahMK){

int totalSKS;
float ips, bobotNilai, totalTambah, bobotHuruf;
totalSKS = 0;
totalTambah = 0;
i = 0;
while(i <jumlahMK){
if (strcmp(data[i].nilai, "A") == 0){
bobotHuruf = 4;
}else if(strcmp(data[i].nilai, "A-") == 0){
bobotHuruf = 3.75;
}else if(strcmp(data[i].nilai, "B+") == 0){
bobotHuruf = 3.50;
}else if(strcmp(data[i].nilai, "B") == 0){
bobotHuruf = 3;
}else if(strcmp(data[i].nilai, "B-") == 0){
bobotHuruf = 2.75;
}else if(strcmp(data[i].nilai, "C+") == 0){
bobotHuruf = 2.50;
}else if(strcmp(data[i].nilai, "C") == 0){
bobotHuruf = 2;
}else if(strcmp(data[i].nilai, "D") == 0){
bobotHuruf = 1;
}else if(strcmp(data[i].nilai, "E") == 0){
bobotHuruf = 0;
}

bobotNilai = data[i].sks * bobotHuruf;


totalTambah += bobotNilai;
totalSKS += data[i].sks;

cout<< data[i].kodeMK<< ", " << data[i].namaMK<< ", " <<


data[i].nilai<< "(" <<bobotHuruf<< ")" << ", " <<bobotHuruf<<" x " <<
data[i].sks<< " = " <<bobotNilai<<endl;
i++ ;
}
ips = totalTambah/totalSKS;
cout<< "\nIPSAnda : " <<ips<<endl;
}

int main(){
Matakuliah matkul[9];
int n;

cout<< "JumlahMatakuliah ? ";


cin>> n;
cout<<endl;

bacaInput(matkul, n);
hitungNilai(matkul, n);

return 0;
}
2. Output program :

3. Source code program (dengan penggunaan fungsi) :


#include <iostream>
#include <cstring>
using namespace std;
struct Matakuliah{
char kodeMK[7];
char namaMK[10];
int sks;
char nilai[3];
};
int i;
void bacaInput(Matakuliah data[], int jumlahMK){
for(i=0; i<jumlahMK; i++){
cout<< "Data Matakuliah #" << i+1 <<endl;
cout<< "KodeMatakuliah ? ";
cin>> data[i].kodeMK;
cout<< "NamaMatakuliah ? " ;
cin>> data[i].namaMK;
cout<< "SKS ? ";
cin>> data[i].sks;
cout<< "Nilai ? ";
cin>> data[i].nilai;
cout<<endl;
}
}
void hitungNilai(Matakuliah data[], int jumlahMK){
int totalSKS;
float ips, bobotNilai, totalTambah, bobotHuruf;
totalSKS = 0;
totalTambah = 0;
i = 0;
while(i <jumlahMK){
if (strcmp(data[i].nilai, "A") == 0){
bobotHuruf = 4;
}else if(strcmp(data[i].nilai, "A-") == 0){
bobotHuruf = 3.75;
}else if(strcmp(data[i].nilai, "B+") == 0){
bobotHuruf = 3.50;
}else if(strcmp(data[i].nilai, "B") == 0){
bobotHuruf = 3;
}else if(strcmp(data[i].nilai, "B-") == 0){
bobotHuruf = 2.75;
}else if(strcmp(data[i].nilai, "C+") == 0){
bobotHuruf = 2.50;
}else if(strcmp(data[i].nilai, "C") == 0){
bobotHuruf = 2;
}else if(strcmp(data[i].nilai, "D") == 0){
bobotHuruf = 1;
}else if(strcmp(data[i].nilai, "E") == 0){
bobotHuruf = 0;
}

bobotNilai = data[i].sks * bobotHuruf;


totalTambah += bobotNilai;
totalSKS += data[i].sks;
cout<< data[i].kodeMK<< ", " << data[i].namaMK<< ", " << data[i].nilai<< "("
<<bobotHuruf<< ")" << ", " <<bobotHuruf<<" x " << data[i].sks<< " = " <<bobotNilai<<endl;
i++ ;
}
ips = totalTambah/totalSKS;
cout<< "\nIPSAnda : " <<ips<<endl;
}
int main(){
Matakuliah matkul[9];
int n;
cout<< "JumlahMatakuliah ? ";
cin>> n;
cout<<endl;
bacaInput(matkul, n);
hitungNilai(matkul, n);
return 0;
}
4. Output program :

You might also like