hayo yang ada tugas disuruh bikin array sama buble sort :D
silahkan menikmati ;v
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
using namespace std;
string cari,nama[100],nis[100],kelas[100],temps;
int nharian[100],ntugas[100],nuas[100],nuts[100],tempi,x,y,banyak,pilihan;
void garis(){
cout<<"========================================================"<<endl;
}
void bubble_sort(){
for(x=1;x<=banyak-1;x++){
for(y=banyak;y>=x+1;y--){
if(nis[y]<nis[y-1]){
temps=nis[y];
nis[y]=nis[y-1];
nis[y-1]=temps;
temps=nama[y];
nama[y]=nama[y-1];
nama[y-1]=temps;
temps=kelas[y];
kelas[y]=kelas[y-1];
kelas[y-1]=temps;
temps=nharian[y];
nharian[y]=nharian[y-1];
nharian[y-1]=tempi;
temps=ntugas[y];
ntugas[y]=ntugas[y-1];
ntugas[y-1]=tempi;
temps=nuts[y];
nuts[y]=nuts[y-1];
nuts[y-1]=tempi;
temps=nuas[y];
nuas[y]=nuas[y-1];
nuas[y-1]=tempi;
}}}}
void input_array(){
system("cls");
garis();
cout<<"Masukan jumlah data "; cin>>banyak;
garis();
for(x=1;x<=banyak;x++){
cout<<"Data ke "<<x<<endl;
cout<<"NIS : "; cin>>nis[x];
cout<<"Nama : "; cin>>nama[x];
cout<<"Kelas : "; cin>>kelas[x];
cout<<"Nilai Harian : "; cin>>nharian[x];
cout<<"Nilai Tugas : "; cin>>ntugas[x];
cout<<"Nilai UTS : "; cin>>nuts[x];
cout<<"Nilai UAS : "; cin>>nuas[x];
garis();
}
getch();
}
void tampil_array(){
system("cls");
garis();
bubble_sort();
cout<<"Data pada array"<<endl;
garis();
for(x=1;x<=banyak;x++){
cout<<"Data ke "<<x<<endl;
cout<<"NIS : "<<nis[x]<<endl;
cout<<"Nama : "<<nama[x]<<endl;
cout<<"Kelas : "<<kelas[x]<<endl;
cout<<"Nilai Harian : "<<nharian[x]<<endl;
cout<<"Nilai Tugas : "<<ntugas[x]<<endl;
cout<<"Nilai UTS : "<<nuts[x]<<endl;
cout<<"Nilai UAS : "<<nuas[x]<<endl;
garis();
}
getch();
}
void cari_array(){
system("cls");
garis();
cout<<"Input data yang anda cari "; cin>>cari;
garis();
x=1;
while((cari!=nama[x])&&(x<=banyak)){
x++;
}
if(cari==nama[x]){
cout<<"Data ke "<<x<<endl;
cout<<"NIS : "<<nis[x]<<endl;
cout<<"Nama : "<<nama[x]<<endl;
cout<<"Kelas : "<<kelas[x]<<endl;
cout<<"Nilai Harian : "<<nharian[x]<<endl;
cout<<"Nilai Tugas : "<<ntugas[x]<<endl;
cout<<"Nilai UTS : "<<nuts[x]<<endl;
cout<<"Nilai UAS : "<<nuas[x]<<endl;
garis();
}
getch();
}
void menu(){
system ("cls");
garis();
cout<<" MENU UTAMA"<<endl;
garis();
cout<<"1. Input data siswa"<<endl;
cout<<"2. Tampil data siswa"<<endl;
cout<<"3. Cari data siswa"<<endl;
cout<<"4. Exit"<<endl;
garis();
cout<<"pilihan anda [1/2/3/4] "; cin>>pilihan;
}
int main(int argc, char *argv[])
{
do{
menu();
if(pilihan==1){
input_array();
}else if(pilihan==2){
tampil_array();
}else if(pilihan==3){
cari_array();
}else if(pilihan==4){
}else{
cout<<"anda salah input"<<endl;
}
}while(pilihan!=4);
system("PAUSE");
return EXIT_SUCCESS;
}
follow me in Twitter Devia N <= (Just Klik)
add me in Facebook Devia N <= (Just Klik)
Tidak ada komentar:
Posting Komentar