Pembelian Barang dengan C++
#include <iostream.h>
#include <conio.h>
struct barang
{
int kode;
char nama [20];
int harga;
};
struct mahasiswa
{
int nim;
char nama[30];
char alamat[50];
float ipk;
int jml;
barang brg[5];
};
main(){
mahasiswa mhs[10];
int i,n,j,k,cari,tempat,benar;
cout<<"\nmasukkan jumlah mahasiswa = ";cin>>n;
for(i=0;i<n;i++)
{
cout<<"\n\nInput Data ke "<<i<<" =\n";
cout<<"\n NIM = "; cin>>mhs[i].nim;
cout<<" Nama = "; cin>>mhs[i].nama;
cout<<" Alamat = "; cin>>mhs[i].alamat;
cout<<" IPK = "; cin>>mhs[i].ipk;
cout<<"\nJumlah barang yang di beli = "; cin>>mhs[i].jml;
for(j=0;j<mhs[i].jml;j++) {
cout<<" \nPembelian barang ke "<<j<<" \n";
cout<<" Kode ="; cin>>mhs[i].brg[j].kode;
cout<<" Nama ="; cin>>mhs[i].brg[j].nama;
cout<<" Harga ="; cin>>mhs[i].brg[j].harga;
}
}
cout<<"\n\nData yang anda masukkan :\n";
cout<<"*************************";
for(i=0;i<n;i++)
{
cout<<"\n\nData ke "<<i<<"= ";
cout<<"\n*************************";
cout<<"\nNIM anda = "<<mhs[i].nim;
cout<<"\nNama anda = "<<mhs[i].nama;
cout<<"\nAlamat anda = "<<mhs[i].alamat;
cout<<"\nIPK anda = "<<mhs[i].ipk;
cout<<"\nPembelian Barang\n";
for(j=0;j<mhs[i].jml;j++) {
cout<<"\nKode =" <<mhs[i].brg[j].kode;
cout<<"\nNama ="<<mhs[i].brg[j].nama;
cout<<"\nHarga ="<<mhs[i].brg[j].harga;
}
}
cout<<"\nMasukkan data yang di cari ="; cin>>cari;
for(i=0;i<n;i++)
{if (mhs[i].nim==cari)
{benar=1;
tempat=i;}
}
if (benar==0)
cout<<"Data yang anda cari tidak ditemukan\n";
else{
cout<<"Data yang anda cari ditemukan\n";
cout<<"Dengan nama = "<<mhs[tempat].nama;}
cout<<"\nBarang yang di beli = ";
for(j=0;j<mhs[tempat].jml;j++) {
cout<<mhs[tempat].brg[j].kode<<endl;
cout<<mhs[tempat].brg[j].nama<<endl;
cout<<mhs[tempat].brg[j].harga<<endl;
}
for(i=0;i<n;i++)
{ for(k=0;k<mhs[k].nim;k++)
getch(); }
}
#include <conio.h>
struct barang
{
int kode;
char nama [20];
int harga;
};
struct mahasiswa
{
int nim;
char nama[30];
char alamat[50];
float ipk;
int jml;
barang brg[5];
};
main(){
mahasiswa mhs[10];
int i,n,j,k,cari,tempat,benar;
cout<<"\nmasukkan jumlah mahasiswa = ";cin>>n;
for(i=0;i<n;i++)
{
cout<<"\n\nInput Data ke "<<i<<" =\n";
cout<<"\n NIM = "; cin>>mhs[i].nim;
cout<<" Nama = "; cin>>mhs[i].nama;
cout<<" Alamat = "; cin>>mhs[i].alamat;
cout<<" IPK = "; cin>>mhs[i].ipk;
cout<<"\nJumlah barang yang di beli = "; cin>>mhs[i].jml;
for(j=0;j<mhs[i].jml;j++) {
cout<<" \nPembelian barang ke "<<j<<" \n";
cout<<" Kode ="; cin>>mhs[i].brg[j].kode;
cout<<" Nama ="; cin>>mhs[i].brg[j].nama;
cout<<" Harga ="; cin>>mhs[i].brg[j].harga;
}
}
cout<<"\n\nData yang anda masukkan :\n";
cout<<"*************************";
for(i=0;i<n;i++)
{
cout<<"\n\nData ke "<<i<<"= ";
cout<<"\n*************************";
cout<<"\nNIM anda = "<<mhs[i].nim;
cout<<"\nNama anda = "<<mhs[i].nama;
cout<<"\nAlamat anda = "<<mhs[i].alamat;
cout<<"\nIPK anda = "<<mhs[i].ipk;
cout<<"\nPembelian Barang\n";
for(j=0;j<mhs[i].jml;j++) {
cout<<"\nKode =" <<mhs[i].brg[j].kode;
cout<<"\nNama ="<<mhs[i].brg[j].nama;
cout<<"\nHarga ="<<mhs[i].brg[j].harga;
}
}
cout<<"\nMasukkan data yang di cari ="; cin>>cari;
for(i=0;i<n;i++)
{if (mhs[i].nim==cari)
{benar=1;
tempat=i;}
}
if (benar==0)
cout<<"Data yang anda cari tidak ditemukan\n";
else{
cout<<"Data yang anda cari ditemukan\n";
cout<<"Dengan nama = "<<mhs[tempat].nama;}
cout<<"\nBarang yang di beli = ";
for(j=0;j<mhs[tempat].jml;j++) {
cout<<mhs[tempat].brg[j].kode<<endl;
cout<<mhs[tempat].brg[j].nama<<endl;
cout<<mhs[tempat].brg[j].harga<<endl;
}
for(i=0;i<n;i++)
{ for(k=0;k<mhs[k].nim;k++)
getch(); }
}
Komentar