Nama Tim : TIM 06A
Kelas : A
Nama Anggota Tim :
1. [2000018059] [D.A.Rosi Arsida Wardani]
2. [2000018031] [Wahyu Saputri]
3. [2000018040] [Dinda Putri Dwi Yanti]
Source Code :
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <string.h>
using namespace std;
struct reg{
string kapal;
string no_penumpang;
string loket;
};
reg penumpang[3][8][4];
char pilihan;
int pilih, offset;
string temp, key, nama;
int i,j, k, n;
int arr[20];
void confirm(){
opt:
cout << "\n\nTekan Y untuk melanjutkan: ";
cin >> pilihan;
if(pilihan == 'Y' || pilihan == 'y'){
}else{
cout << "\n\nPeriksa kembali input anda" << endl;
goto opt;
}
}
void baca_tulis(){
int n;
string temp;
ofstream myfile;
cout<<" Masukkan jumlah penumpang : ";
cin>>n;
cout<<endl;
for (int i = 0; i < n; i++){
myfile.open("kapal.txt", ios::app);
cout<<" Kapal : ";
cin.ignore();
getline (cin, penumpang[i][j][k].kapal);
myfile<<penumpang[i][j][k].kapal;
myfile<<endl;
myfile.close();
}
for (int i = 0; i < n; i++){
myfile.open("nomor.txt", ios::app);
cout<<" Nomor Penumpang : ";
cin>>penumpang[i][j][k].no_penumpang;
myfile<<penumpang[i][j][k].no_penumpang;
myfile<<endl;
myfile.close();
}
for (int i = 0; i < n; i++){
myfile.open("loket.txt", ios::app);
cout<<" Loket\t : ";
cin>>penumpang[i][j][k].loket;
myfile<<penumpang[i][j][k].loket;
myfile<<endl;
myfile.close();
}
system ("cls");
cout<<setiosflags(ios::left)
<<setw(10)<<"Kapal" <<setw(20)<<"Nomor Penumpang"
<<setw(7) <<"Loket"<<endl;
cout<<"-----------------------------------------------------"<<endl;
for(int i =0; i<3; i++){
for(int k=0; k<n; k++){
for(int j=0; j<3; j++){
cout<<setiosflags(ios::left)
<<setw(10)<<penumpang[i][j][k].kapal<<setw(20)<<penumpang[i][j][k].no_penumpang<<setw(7)
<<setprecision(3)<<penumpang[i][j][k].loket<<endl;
}
}
}
}
void tukar(int* x, int* y){
int a = *x;
*x=*y;
*y=a;
}
void sorting(){
i=0;
ifstream infile;
infile.open("nomor.txt");
while(!infile.eof()){
infile>>arr[i];
i++;
}
int n2=i-1;
for(i=0; i<n2; i++){
for(j=1;j<n2;j++){
if(arr[j]<arr[j-1]){
tukar (&arr[j], &arr[j-1]);
}
}
}
cout<<endl;
cout<<"Data yang Diurutkan : ";
cout<<endl;
cout<<endl;
for(i=0; i<n2; i++){
cout<<arr[i]<<endl;
}
infile.close();
}
void searching(){
ifstream infile;
infile.open("kapal.txt");
cout<<"Masukkan Data Yang Ingin Dicari : ";
cin>>key;
if(infile.is_open()){
unsigned int index = 0;
while(getline(infile, nama)){
index++;
if((offset=nama.find(key, 0)) !=string::npos){
cout<<"Kapal "<< key <<" terdapat di index : "<< index <<endl;
}
}
infile.close();
}
else cout<<"Data tidak ditemukan"<<endl;
}
int main(){
menu:
cout<<" PENDATAAN PENUMPANG KAPAL "<<endl;
cout<<"++++++++++++++++++++++++++++++++++++++++++"<<endl;
cout<<"\tPelabuhan HK Sungai Guntung "<<endl;
cout<<"=========================================="<<endl;
cout<<endl;
cout << "\n================================"<<endl;
cout << " \tMENU PILIHAN "<< endl;
cout << "================================"<<endl;
cout << "1. Menyimpan dan Menampilkan Data yang Baru dimasukkan "<<endl;
cout << "2. Sort nomor penumpang"<<endl;
cout << "3. Search kapal"<<endl;
cout << "4. EXIT"<<endl;
cout << "================================"<<endl;
cout << "Masukkan Nomor Pilihan (1 - 4) : "; cin>>pilih;
switch ( pilih){
case 1:
baca_tulis();
confirm();
system ("cls");
goto menu;
break;
case 2:
sorting();
confirm();
system ("cls");
goto menu;
break;
case 3:
searching();
confirm();
system ("cls");
goto menu;
break;
case 4:
cout << "\n Anda Telah Keluar Dari Program " <<endl;
cout << " TERIMA KASIH " <<endl;
exit(1);
break;
default:
system ("cls");
goto menu;
cout << "Input salah. \n";
break;
}
return 0;
}
Kommentarer