twitter



#include
#include
#define max 5
main()
{
                typedef struct transaksi {
                                char nama[30], nim[12];
                                double harga ;
                                int urutan;
                };

                transaksi trn[max];
                int i, j;
                float total=0;

                cout << "- Input Data" << endl;
                for (i=1;i<=max;i++) {
                                cout << "  Data ke-" << i << endl;
                                cout << "  Masukkan Nama  : ";
                                cin >> trn[i].nama;
                                cout << "  Masukkan NIM   : ";
                                cin >> trn[i].nim;
                                cout << "  Masukkan Harga : ";
                                cin >> trn[i].harga;
                                cout << endl;
                }

                for (i=1;i<=max;i++) {
                                trn[i].urutan=max;
                                for (j=1;j<=max;j++) {
                                                if (trn[i].harga>trn[j].harga)
                                                trn[i].urutan--;
                                }
                                total+=trn[i].harga;
                }

                cout << endl << "- Harga Tertinggi" << endl;
                for (i=1;i<=max;i++) {
                                if (trn[i].urutan == 1) {
                                  cout << "  Nama  : " << trn[i].nama << endl;
                                  cout << "  NIM   : " << trn[i].nim << endl;
                                  cout << "  Nilai : " << trn[i].harga << endl;
                                }
                }

                cout << endl << "- Harga Terendah" << endl;
                for (i=1;i<=max;i++) {
                                if (trn[i].urutan == max) {
                                  cout << "  Nama  : " << trn[i].nama << endl;
                                  cout << "  NIM   : " << trn[i].nim << endl;
                                  cout << "  Nilai : " << trn[i].harga << endl;
                                }
                }

                cout << endl << "- Rata Rata" << endl;
                cout << "  Total                      : " << total << endl;
                cout << "  Jumlah Transaksi : " << max << endl;
                cout << "  Rata-rata        : " << total/max << endl;

                cout << endl << "- Semua Data (Diurutkan berdasarkan Harga)" << endl;
                for (i=1;i<=max;i++) {
                                for (j=1;j<=max;j++) {
                                                if (trn[j].urutan == i) {
                                                                cout << "  * Urutan ke-" << trn[j].urutan << endl;
                                                                cout << "    Nama  : " << trn[j].nama << endl;
                                                  cout << "    NIM   : " << trn[j].nim << endl;
                                                  cout << "    Harga : " <<< endl << endl;
                                                }
                                }
                }

                getch();
                return 0;
}

0 comments:

Posting Komentar