Membuat Program Record Dalam C++

Dengan tipe data record,dapat dikumpulkan beberapa item data masing-masing mempunyai tipe data yang berbeda beda.masing-masing item tersebut field.record terdiri dari kumpulan field yang dapat mengandung beberapa tipe.
Berikut ini merupakan contoh program record
#include <conio.h>
#include <iostream.h>
#define DATAMAX 50
typedef int bulat;
struct nilaiMHS
{             
                char nim[11];
                bulat hadir, tugas, quiz, nts, nas;
};
int main()
{             
                cout<<"Tugas Kelompok 1\n";
                cout<<"Struktur Data\n";
                cout<<"Record (struct) \n";
                ulang:
               
                nilaiMHS recNilaiMHS[DATAMAX];
                bulat jmlData, i;
                float rataRata;  
                char grade, play;
                printf("\n");       printf("Berapa jumlah data = "); scanf("%d",&jmlData);
                for (i=0; i<jmlData; i++)
                {             
                                cout << "\nData Nilai Mahasiswa ke-" << (i+1) << endl;
                                printf("Nomor Induk Mahasiswa = "); cin >> recNilaiMHS[i].nim;
                                printf("Persentase Kehadiran  = "); scanf("%i",&recNilaiMHS[i].hadir);
                                printf("Nilai Tugas           = "); scanf("%d",&recNilaiMHS[i].tugas);
                                printf("Nilai Quiz            = "); scanf("%d",&recNilaiMHS[i].quiz);
                                printf("Nilai Tengah Semester = "); scanf("%i",&recNilaiMHS[i].nts);
                                printf("Nilai Akhir Semester  = "); scanf("%i",&recNilaiMHS[i].nas);}
                cout << "\n" << endl;
//                 1         2         3         4         5         6         7         8
                //            12345678901234567890123456789012345678901234567890123456789012345678901234567890
                cout << "DAFTAR NILAI MAHASISWA" << endl;
                cout << "+----------+-------+-------+-------+-------+-------+-------+-------+" << endl;
                cout << "|   NIM    | Hadir | Tugas | Quiz  |  NTS  |  NAS  | Rata2 | Grade |" << endl;
                cout << "+----------+-------+-------+-------+-------+-------+-------+-------+" << endl;
                for (i=0; i<jmlData; i++)
                {
                                rataRata=(float) 0.1*recNilaiMHS[i].hadir + 0.1*recNilaiMHS[i].quiz +
                                0.1*recNilaiMHS[i].tugas + 0.3*recNilaiMHS[i].nts + 0.4*recNilaiMHS[i].nas;
                                if (rataRata>=80)      { grade='A'; }
                                else if (rataRata>=70) { grade='B'; }
                                else if (rataRata>=60) { grade='C'; }
                                else if (rataRata>=50) { grade='D'; }
                                else                   { grade='E'; }
                                printf("|%10s|%7d|%7d|%7d|%7d|%7d|%7.2f|   %c   |\n", recNilaiMHS[i].nim,
                                recNilaiMHS[i].hadir, recNilaiMHS[i].tugas, recNilaiMHS[i].quiz,
                                recNilaiMHS[i].nts, recNilaiMHS[i].nas, rataRata, grade);
                }             
                cout << "+----------+-------+-------+-------+-------+-------+-------+-------+";
               
                cout<<endl;
                cout<<"\nApakah Anda Ingin Mengulangnya(y/t) ??? "; cin>>play;
                if(play=='y'||play=='Y')
                {              goto ulang;}
                else
                                {return 0;}}


Share this

Related Posts

Previous
Next Post »