Contoh Coding C++ Struct dan Array
#include <iostream.h>#include <stdio.h>
#include <string.h>
#include <conio.h>
struct data_siswa
{
char nis[9],nama[35];
int uts,uas,tugas,kuis,absensi;
float rata_rata;
};
void main()
{
int Lagi;
struct data_siswa sws;
cout<<"______________________________________________________________________________\n";
cout<<"| |\n";
cout<<"|----------------------PROGRAM PENGHITUNG NILAI SISWA------------------------|\n";
cout<<"______________________________________________________________________________\n";
cout<<"\n";
cout<<"masukkan nis : ";gets(sws.nis);
cout<<"masukkan nama : ";gets(sws.nama);
cout<<"masukkan nilai uts : ";cin>>sws.uts;
cout<<"masukkan nilai uas : ";cin>>sws.uas;
cout<<"masukkan nilai tugas : ";cin>>sws.tugas;
cout<<"masukkan nilai kuis : ";cin>>sws.kuis;
cout<<"masukkan nilai absensi : ";cin>>sws.absensi;
sws.rata_rata= (((sws.uts * 20/100) + (sws.uas * 25/100) +
(sws.tugas * 30/100) + (sws.kuis * 15/100) + (sws.absensi * 10/100))*4)/100;
cout<<"\n";
printf("rata rata saudara %s adalah %f dengan nilai huruf ",sws.nama,sws.rata_rata);
if(sws.rata_rata >= 4)
{
cout<<"A";
}
else if(sws.rata_rata >= 3.5)
{
cout<<"A-";
}
else if(sws.rata_rata >= 3)
{
cout<<"B";
}
else if(sws.rata_rata >= 2.5)
{
cout<<"B-";
}
else if(sws.rata_rata >= 2)
{
cout<<"C";
}
else if(sws.rata_rata >= 1.5)
{
cout<<"D";
}
else
{
cout<<"E";
}
getch();}
Tidak ada komentar:
Posting Komentar