//
// main.cpp
// tugas strukdat 2
//
// Created by FaqihMac on 24/10/11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
#include <iostream>
using namespace std;
struct data
{
int NPM;
char Nama[20];
int Nilai;
data* next;
};
struct hasil
{
float Maks, Min, rtrt;
int nomor2;
};
typedef data* pointer;
typedef pointer List;
void createList(List& First);
void insertFirst(List& First, pointer pBaru);
void traversal(List First, hasil& b);
void createElemen(pointer& pBaru);
void header();
float rata2(hasil b);
int main()
{
pointer p1;
List Ma10;
int pilih;
hasil b;
char pilih3;
b.nomor2 = 0;
header();
do
{
createList(Ma10);
cout << "Masukkan Berapa Banyak Data : "; cin >> pilih;
for (int i=0; i<pilih; i++)
{
createElemen(p1);
insertFirst(Ma10, p1);
}
system("cls");
traversal(Ma10, b);
cout << endl << "Coba Lagi? (Y)/(N) "; cin >> pilih3;
system("cls");
header();
} while (pilih3 == 'Y' || pilih3 == 'y');
return 0;
}
void createList(List& First)
{
First =0;
}
void insertFirst(List& First, pointer pBaru)
{
if(First ==0)
{
First = pBaru;
}
else
{
pBaru -> next = First;
First = pBaru;
}
}
void traversal(List First,hasil& a)
{
pointer pBantu;
pBantu = First;
int nomor = 1, pilih2;
a.Maks = 0, a.Min = 1000000;
float ratarata;
header();
cout << "No NPM Nama Nilai Keterangan" << endl;
while(pBantu !=0)
{
if (pBantu -> Nilai > 69)
{
cout << nomor << " " << pBantu -> NPM << " " << pBantu -> Nama << " " << pBantu -> Nilai << " " << "Lulus" << endl;
}
else
{
cout << nomor << " " << pBantu -> NPM << " " << pBantu -> Nama << " " << pBantu -> Nilai << " " << "Gagal" << endl;
}
a.rtrt = a.rtrt + (pBantu -> Nilai);
if (pBantu -> Nilai >= a.Maks)
{
a.Maks = pBantu -> Nilai;
}
if (pBantu -> Nilai <= a.Min)
{
a.Min = pBantu -> Nilai;
}
pBantu = pBantu -> next;
nomor++, a.nomor2++;
}
cout << endl;
cout << "Menu : " << endl;
cout << "1. Rata-Rata" << endl;
cout << "2. Nilai Maks" << endl;
cout << "3. Nilai Min" << endl;
cout << "4. Tampilkan Semuanya" << endl << endl;
cout << "Masukkan pilihan : "; cin >> pilih2;
cout << endl;
switch(pilih2)
{
case 1:
{
ratarata = rata2(a);
cout << "Rata-Rata : " << ratarata << endl;
}
break;
case 2:
{
cout << "Nilai Maks : " << a.Maks << endl;
}
break;
case 3:
{
cout << "Nilai Min : " << a.Min << endl;
}
break;
case 4:
{
ratarata = rata2(a);
cout << "Rata-Rata : " << ratarata << endl;
cout << "Nilai Maks : " << a.Maks << endl;
cout << "Nilai Min : " << a.Min << endl;
}
break;
default:
{
cout << " Menu tidak ada" << endl;
}
}
}
void createElemen(pointer& pBaru)
{
pBaru = new data;
cout << "NPM : "; cin >> pBaru -> NPM;
cout << "Nama : "; cin >> pBaru -> Nama;
cout << "Nilai : "; cin >> pBaru -> Nilai;
cout << endl;
pBaru -> next = NULL;
}
void header()
{
cout << "Program Mencari Nilai Tertinggi Terendah & Rerata" << endl;
}
float rata2(hasil b)
{
return (b.rtrt / b.nomor2);
}