#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int nim[10];
char nama[10][10];
int nilai[10];
int i,n,no=1;
cout<<"masukkan jumlah mahasiswa: ";cin>>n;;
for (i=1;i<=n;i++)
{
cout<<"masukkan nim : ";cin>>nim[i];
cout<<"masukkan nama : ";cin>>nama[i];
cout<<"masukkan nilai: ";cin>>nilai[i];
cout<<"\n";
};
cout<<"jum mahasiswa: "<<n<<endl;
cout<<"\n";
cout<<"|no|\tnim\t|\tnama\t|\tnilai\t| nilai huruf |\n";
for (i=1;i<=n;i++)
{
if(nilai[i]>= 80 && nilai[i]<=100){
cout<<"|"<<no++<<" |\t"<<nim[i]<<"\t|\t"<<nama[i]<<"\t|\t"<<nilai[i]<<"\t|\t"<<"A"<<"\t|"<<endl;
}
else if(nilai[i]>=60)
{cout<<"|"<<no++<<" |\t"<<nim[i]<<"\t|\t"<<nama[i]<<"\t|\t"<<nilai[i]<<"\t|\t"<<"B"<<"\t|"<<endl;
}
else{
cout<<"|"<<no++<<" |\t"<<nim[i]<<"\t|\t"<<nama[i]<<"\t|\t"<<nilai[i]<<"\t|\t"<<"C"<<"\t|"<<endl;
}}
cout<<"\n";
getch();
}
Hasil Compile :
Script C++ Selection Sort
#include <iostream>
#include <iomanip>
#include <conio.h>
using namespace std;
int selectionsort (int array[], const int size)
{
int i, j, kecil, temp;
for (i=0; i<size; i++)
{
kecil=i;
for (j=i; j<size; j++)
{
if (array[kecil]>array[j])
{kecil = j;}
}
temp = array [i];
array[i] = array[kecil];
array[kecil] = temp;
}
}
int main()
{
int NumList[8] = {5, 34, 32, 25, 75, 42, 22, 2};
int temp;
cout<<"Data sebelum diurutkan: \n";
for (int d=0; d<8; d++)
{
cout<<setw(3)<<NumList[d];
}
cout<<"\n\n";
selectionsort(NumList,8);
cout<<"Data setelah diurutkan:\n";
for (int iii=0; iii<8; iii++)
cout<<setw(3)<<NumList[iii]<<endl<<endl;
return 0;
}
Hasil Compile :
#include <iomanip>
#include <conio.h>
using namespace std;
int selectionsort (int array[], const int size)
{
int i, j, kecil, temp;
for (i=0; i<size; i++)
{
kecil=i;
for (j=i; j<size; j++)
{
if (array[kecil]>array[j])
{kecil = j;}
}
temp = array [i];
array[i] = array[kecil];
array[kecil] = temp;
}
}
int main()
{
int NumList[8] = {5, 34, 32, 25, 75, 42, 22, 2};
int temp;
cout<<"Data sebelum diurutkan: \n";
for (int d=0; d<8; d++)
{
cout<<setw(3)<<NumList[d];
}
cout<<"\n\n";
selectionsort(NumList,8);
cout<<"Data setelah diurutkan:\n";
for (int iii=0; iii<8; iii++)
cout<<setw(3)<<NumList[iii]<<endl<<endl;
return 0;
}
Hasil Compile :
Script C++ Penjumlahan Matrix
#include <iostream>
#include <iomanip>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char *argv[]) {
int i,j,hasil[3][3];
int data[3][3],data2[3][3];
//untuk menampilkan isi matrik
cout<<"Isi variabel data adalah "<<endl;
cout<<"-------------------------\n\n";
cout<<" MATRIK 1 | MATRIK 2 "<<endl;
for (i=0;i<3;i++)
{ for(j=0;j<3;j++)
{cout<<"masukkan data "<<setw(3)<<i<<" "<<j<<":"<<setw(3);
cin>>data[i][j];
cout<<"masukkan data2 "<<setw(2)<<i<<" "<<j<<":"<<setw(3);
cin>>data2[i][j];}}
for (i=0;i<3;i++)
{for(j=0;j<3;j++)
{ cout<<setw(3)<<data[i][j];}
cout<<" | ";
for(j=0;j<3;j++)
{cout<<setw(3)<<data2[i][j];}
cout<<endl;}
//untuk proses penjumlahan
cout<<"\n\n Hasil Penjumlahan kedua Matrik"<<endl;
for (i=0;i<3;i++)
{ for(j=0;j<3;j++)
{hasil[i][j]=data[i][j]+data2[i][j];
cout<<" "<<hasil[i][j]<<" ";}
cout<<endl;}
return 0;
}
Hasil Compile :
#include <iomanip>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char *argv[]) {
int i,j,hasil[3][3];
int data[3][3],data2[3][3];
//untuk menampilkan isi matrik
cout<<"Isi variabel data adalah "<<endl;
cout<<"-------------------------\n\n";
cout<<" MATRIK 1 | MATRIK 2 "<<endl;
for (i=0;i<3;i++)
{ for(j=0;j<3;j++)
{cout<<"masukkan data "<<setw(3)<<i<<" "<<j<<":"<<setw(3);
cin>>data[i][j];
cout<<"masukkan data2 "<<setw(2)<<i<<" "<<j<<":"<<setw(3);
cin>>data2[i][j];}}
for (i=0;i<3;i++)
{for(j=0;j<3;j++)
{ cout<<setw(3)<<data[i][j];}
cout<<" | ";
for(j=0;j<3;j++)
{cout<<setw(3)<<data2[i][j];}
cout<<endl;}
//untuk proses penjumlahan
cout<<"\n\n Hasil Penjumlahan kedua Matrik"<<endl;
for (i=0;i<3;i++)
{ for(j=0;j<3;j++)
{hasil[i][j]=data[i][j]+data2[i][j];
cout<<" "<<hasil[i][j]<<" ";}
cout<<endl;}
return 0;
}
Hasil Compile :
Script C++ Memindah Array 1 Dimensi ke 2 Dimensi
#include <cstdlib>
#include <iostream>
using namespace std;
class convert{
friend istream& operator>>(istream&, convert&);
friend ostream& operator<<(ostream&, convert&);
public:
convert();
void pindah();
private:
int x[100],y[100][100];
int l,k,m,n;
};
convert::convert(){
cout<<"===============================\n"<<endl;
cout<<"Memindah Array 1 ke 2 Dimensi\n"<<endl;
cout<<"===============================\n"<<endl;
}
istream& operator>>(istream& in, convert& a){
cout<<"Masukkan Banyak Digit Array 1 Dimensi :";
in>>a.l;
for(int i=0; i<a.l; i++){
cout<<"Imput Data ke ["<<i+1<<"]:";
in>>a.x[i];
}
cout<<"\nMasukkan Baris Array 2 Dimensi :";
in>>a.n;
cout<<"\nMasukkan Kolom Array 2 Dimensi :";
in>>a.m;
return in;}
ostream& operator<<(ostream& out, convert& b){
out<<"Data Array 1 Dimensi :"<<endl;
for(int i=0; i<b.l; i++){
out<<b.x[i]<<" ";
}
out<<"\nData Array Setelah di Pindah :"<<endl;
for(int i=0; i<b.n; i++){
for(int j=0; j<b.m; j++){
out<<b.y[i][j]<<" ";
}
out<<endl;
}
return out;}
void convert::pindah(){
k=0;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
y[i][j]=x[k];
k=k+1;
}
cout<<endl;
}
}
int main(int argc, char *argv[])
{
convert marty;
cin>>marty;
marty.pindah();
cout<<marty;
system("PAUSE");
return EXIT_SUCCESS;
}
Hasil Comple :
#include <iostream>
using namespace std;
class convert{
friend istream& operator>>(istream&, convert&);
friend ostream& operator<<(ostream&, convert&);
public:
convert();
void pindah();
private:
int x[100],y[100][100];
int l,k,m,n;
};
convert::convert(){
cout<<"===============================\n"<<endl;
cout<<"Memindah Array 1 ke 2 Dimensi\n"<<endl;
cout<<"===============================\n"<<endl;
}
istream& operator>>(istream& in, convert& a){
cout<<"Masukkan Banyak Digit Array 1 Dimensi :";
in>>a.l;
for(int i=0; i<a.l; i++){
cout<<"Imput Data ke ["<<i+1<<"]:";
in>>a.x[i];
}
cout<<"\nMasukkan Baris Array 2 Dimensi :";
in>>a.n;
cout<<"\nMasukkan Kolom Array 2 Dimensi :";
in>>a.m;
return in;}
ostream& operator<<(ostream& out, convert& b){
out<<"Data Array 1 Dimensi :"<<endl;
for(int i=0; i<b.l; i++){
out<<b.x[i]<<" ";
}
out<<"\nData Array Setelah di Pindah :"<<endl;
for(int i=0; i<b.n; i++){
for(int j=0; j<b.m; j++){
out<<b.y[i][j]<<" ";
}
out<<endl;
}
return out;}
void convert::pindah(){
k=0;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
y[i][j]=x[k];
k=k+1;
}
cout<<endl;
}
}
int main(int argc, char *argv[])
{
convert marty;
cin>>marty;
marty.pindah();
cout<<marty;
system("PAUSE");
return EXIT_SUCCESS;
}
Hasil Comple :
Script C++ Penggunaan Switch Case
#include <iostream>
#include <cstdlib>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
class panji{
public:
void input();
void proses();
void output();
private:
string a;
int b,c,d,e;
};
void panji::input(){
cout<<"DAFTAR MENU"<<endl;
cout<<"1. Paket 1: Nasi + Ayam + Sambal + Lalapan + Es Teh Harga Rp 9.000,-"<<endl;
cout<<"2. Paket 2: Nasi + Lele + Sambal + Lalapan + Es Teh Harga Rp 8.000,-"<<endl;
cout<<"3. Paket 3: Nasi + Bebek + Sambal + Lalapan + Es Teh Harga Rp 10.000,-"<<endl;
cout<<"masukkan nama : ";
cin>>a;
cout<<"masukkan no. kursi : ";
cin>>b;
cout<<"masukkan jenis paket : ";
cin>>c;
};
void panji::proses(){
switch(c){
case 1:
cout<<" Anda memilih paket 1"<<endl;
cout<<" Paket 1: Nasi + Ayam + Sambal + Lalapan + Es Teh Harga Rp 9.000,-"<<endl;
cout<<" masukkan jumlah uang yang dibayarkan : ";cin>>d;
e=d-9000;
break;
case 2:
cout<<" Anda memilih paket 2"<<endl;
cout<<" Paket 2: Nasi + Lele + Sambal + Lalapan + Es Teh Harga Rp 8.000,-"<<endl;
cout<<" masukkan jumlah uang yang dibayarkan : ";cin>>d;
e=d-8000;
break;
case 3:
cout<<" Anda memilih paket 3"<<endl;
cout<<" Paket 3: Nasi + Bebek + Sambal + Lalapan + Es Teh Harga Rp 10.000,-"<<endl;
cout<<" masukkan jumlah uang yang dibayarkan : ";cin>>d;
e=d-10000;
break;
default:
cout<<"Menu yang anda pilih tidak tersedia.";
break;
};
};
void panji::output(){
cout<<"Nama : "<<a<<endl;
cout<<"No. kursi : "<<b<<endl;
cout<<"Paket nomor : "<<c<<endl;
cout<<"Uang yang dibayar : "<<d<<endl;
cout<<"Uang kembalian : "<<e<<endl;
};
int main(int argc, char *argv[]) {
panji wijaya;
wijaya.input();
wijaya.proses();
wijaya.output();
return 0;
}
Hasil Compile :
#include <cstdlib>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
class panji{
public:
void input();
void proses();
void output();
private:
string a;
int b,c,d,e;
};
void panji::input(){
cout<<"DAFTAR MENU"<<endl;
cout<<"1. Paket 1: Nasi + Ayam + Sambal + Lalapan + Es Teh Harga Rp 9.000,-"<<endl;
cout<<"2. Paket 2: Nasi + Lele + Sambal + Lalapan + Es Teh Harga Rp 8.000,-"<<endl;
cout<<"3. Paket 3: Nasi + Bebek + Sambal + Lalapan + Es Teh Harga Rp 10.000,-"<<endl;
cout<<"masukkan nama : ";
cin>>a;
cout<<"masukkan no. kursi : ";
cin>>b;
cout<<"masukkan jenis paket : ";
cin>>c;
};
void panji::proses(){
switch(c){
case 1:
cout<<" Anda memilih paket 1"<<endl;
cout<<" Paket 1: Nasi + Ayam + Sambal + Lalapan + Es Teh Harga Rp 9.000,-"<<endl;
cout<<" masukkan jumlah uang yang dibayarkan : ";cin>>d;
e=d-9000;
break;
case 2:
cout<<" Anda memilih paket 2"<<endl;
cout<<" Paket 2: Nasi + Lele + Sambal + Lalapan + Es Teh Harga Rp 8.000,-"<<endl;
cout<<" masukkan jumlah uang yang dibayarkan : ";cin>>d;
e=d-8000;
break;
case 3:
cout<<" Anda memilih paket 3"<<endl;
cout<<" Paket 3: Nasi + Bebek + Sambal + Lalapan + Es Teh Harga Rp 10.000,-"<<endl;
cout<<" masukkan jumlah uang yang dibayarkan : ";cin>>d;
e=d-10000;
break;
default:
cout<<"Menu yang anda pilih tidak tersedia.";
break;
};
};
void panji::output(){
cout<<"Nama : "<<a<<endl;
cout<<"No. kursi : "<<b<<endl;
cout<<"Paket nomor : "<<c<<endl;
cout<<"Uang yang dibayar : "<<d<<endl;
cout<<"Uang kembalian : "<<e<<endl;
};
int main(int argc, char *argv[]) {
panji wijaya;
wijaya.input();
wijaya.proses();
wijaya.output();
return 0;
}
Hasil Compile :
Script C++ Penggabungan Fungsi Perkalian, Pengurangan dan transpose matrix
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
class Array{
public:
void input();
void kurang();
void kali();
void output();
private:
int n,m,a[10][10], b[10][10], c[10][10],d[10][10];
};
void Array::input(){
cout<<"Masukkan banyak baris : ";cin>>n;
cout<<"Masukkan banyak kolom : ";cin>>m;
cout<<endl;
cout<<"Input Matriks A"<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cout<<"Data ke A["<<i<<"]"<<"["<<j<<"] : ";cin>>a[i][j];
}
}
cout<<endl;
cout<<"Input Matriks B"<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cout<<"Data ke A["<<i<<"]"<<"["<<j<<"] : ";cin>>b[i][j];
}
}}
void Array::kurang(){
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
c[i][j]=a[i][j]-b[i][j];
}
}
void Array::kali(){
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
{
d[i][j]=0;
for (int k=1;k<=m;k++)
{
d[i][j]+= a[i][k]*b[k][j];
}
}
}
}
void Array::output(){
cout<<"Matriks A"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<a[i][j]<<" ";
cout<<endl;
}
cout<<endl;
cout<<"Matriks B"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<b[i][j]<<" ";
cout<<endl;
}
cout<<"Hasil Pengurangan"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<c[i][j]<<" ";
cout<<endl;
}
cout<<"Hasil Perkalian"<<endl;
cout<<endl;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cout<<setw(4)<<d[i][j];
}
cout<<endl;
}
cout<<endl;
cout<<"Transpose Matrik A"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<a[j][i]<<" ";
cout<<endl;
}
}
int main(int argc, char *argv[])
{
Array x;
x.input();
x.kurang();
x.kali();
x.output();
system("PAUSE");
return EXIT_SUCCESS;
}
Hasil Compile :
#include <iostream>
#include <iomanip>
using namespace std;
class Array{
public:
void input();
void kurang();
void kali();
void output();
private:
int n,m,a[10][10], b[10][10], c[10][10],d[10][10];
};
void Array::input(){
cout<<"Masukkan banyak baris : ";cin>>n;
cout<<"Masukkan banyak kolom : ";cin>>m;
cout<<endl;
cout<<"Input Matriks A"<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cout<<"Data ke A["<<i<<"]"<<"["<<j<<"] : ";cin>>a[i][j];
}
}
cout<<endl;
cout<<"Input Matriks B"<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cout<<"Data ke A["<<i<<"]"<<"["<<j<<"] : ";cin>>b[i][j];
}
}}
void Array::kurang(){
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
c[i][j]=a[i][j]-b[i][j];
}
}
void Array::kali(){
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
{
d[i][j]=0;
for (int k=1;k<=m;k++)
{
d[i][j]+= a[i][k]*b[k][j];
}
}
}
}
void Array::output(){
cout<<"Matriks A"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<a[i][j]<<" ";
cout<<endl;
}
cout<<endl;
cout<<"Matriks B"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<b[i][j]<<" ";
cout<<endl;
}
cout<<"Hasil Pengurangan"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<c[i][j]<<" ";
cout<<endl;
}
cout<<"Hasil Perkalian"<<endl;
cout<<endl;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cout<<setw(4)<<d[i][j];
}
cout<<endl;
}
cout<<endl;
cout<<"Transpose Matrik A"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<a[j][i]<<" ";
cout<<endl;
}
}
int main(int argc, char *argv[])
{
Array x;
x.input();
x.kurang();
x.kali();
x.output();
system("PAUSE");
return EXIT_SUCCESS;
}
Hasil Compile :
Script C++ Transpose Matrix
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
class Array{
public:
void input();
void output();
private:
int n,m,a[10][10];
};
void Array::input(){
cout<<"Masukkan banyak baris : ";cin>>n;
cout<<"Masukkan banyak kolom : ";cin>>m;
cout<<endl;
cout<<"Input Matriks A"<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cout<<"Data ke A["<<i<<"]"<<"["<<j<<"] : ";cin>>a[i][j];
}
}
}
void Array::output(){
cout<<"Matriks A"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<a[i][j]<<" ";
cout<<endl;
}
cout<<endl;
cout<<"Transpose Matrik A"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<a[j][i]<<" ";
cout<<endl;
}
}
int main(int argc, char *argv[])
{
Array x;
x.input();
x.output();
system("PAUSE");
return EXIT_SUCCESS;
}
Hasil Compile :
#include <iostream>
#include <iomanip>
using namespace std;
class Array{
public:
void input();
void output();
private:
int n,m,a[10][10];
};
void Array::input(){
cout<<"Masukkan banyak baris : ";cin>>n;
cout<<"Masukkan banyak kolom : ";cin>>m;
cout<<endl;
cout<<"Input Matriks A"<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cout<<"Data ke A["<<i<<"]"<<"["<<j<<"] : ";cin>>a[i][j];
}
}
}
void Array::output(){
cout<<"Matriks A"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<a[i][j]<<" ";
cout<<endl;
}
cout<<endl;
cout<<"Transpose Matrik A"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<a[j][i]<<" ";
cout<<endl;
}
}
int main(int argc, char *argv[])
{
Array x;
x.input();
x.output();
system("PAUSE");
return EXIT_SUCCESS;
}
Hasil Compile :
Script C++ Perkalian Array
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
class Array{
public:
void input();
void kali();
void output();
private:
int n,m,a[10][10], b[10][10],d[10][10];
};
void Array::input(){
cout<<"Masukkan banyak baris : ";cin>>n;
cout<<"Masukkan banyak kolom : ";cin>>m;
cout<<endl;
cout<<"Input Matriks A"<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cout<<"Data ke A["<<i<<"]"<<"["<<j<<"] : ";cin>>a[i][j];
}
}
cout<<endl;
cout<<"Input Matriks B"<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cout<<"Data ke A["<<i<<"]"<<"["<<j<<"] : ";cin>>b[i][j];
}
}}
void Array::kali(){
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
{
d[i][j]=0;
for (int k=1;k<=m;k++)
{
d[i][j]+= a[i][k]*b[k][j];
}
}
}
}
void Array::output(){
cout<<"Matriks A"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<a[i][j]<<" ";
cout<<endl;
}
cout<<endl;
cout<<"Matriks B"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<b[i][j]<<" ";
cout<<endl;
}
cout<<"Hasil Perkalian"<<endl;
cout<<endl;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cout<<setw(4)<<d[i][j];
}
cout<<endl;
}
}
int main(int argc, char *argv[])
{
Array x;
x.input();
x.kali();
x.output();
system("PAUSE");
return EXIT_SUCCESS;
}
Hasil Compile :
#include <iostream>
#include <iomanip>
using namespace std;
class Array{
public:
void input();
void kali();
void output();
private:
int n,m,a[10][10], b[10][10],d[10][10];
};
void Array::input(){
cout<<"Masukkan banyak baris : ";cin>>n;
cout<<"Masukkan banyak kolom : ";cin>>m;
cout<<endl;
cout<<"Input Matriks A"<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cout<<"Data ke A["<<i<<"]"<<"["<<j<<"] : ";cin>>a[i][j];
}
}
cout<<endl;
cout<<"Input Matriks B"<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cout<<"Data ke A["<<i<<"]"<<"["<<j<<"] : ";cin>>b[i][j];
}
}}
void Array::kali(){
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
{
d[i][j]=0;
for (int k=1;k<=m;k++)
{
d[i][j]+= a[i][k]*b[k][j];
}
}
}
}
void Array::output(){
cout<<"Matriks A"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<a[i][j]<<" ";
cout<<endl;
}
cout<<endl;
cout<<"Matriks B"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<b[i][j]<<" ";
cout<<endl;
}
cout<<"Hasil Perkalian"<<endl;
cout<<endl;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cout<<setw(4)<<d[i][j];
}
cout<<endl;
}
}
int main(int argc, char *argv[])
{
Array x;
x.input();
x.kali();
x.output();
system("PAUSE");
return EXIT_SUCCESS;
}
Hasil Compile :
Script C++ Pengurangan Array
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
class Array{
public:
void input();
void kurang();
void output();
private:
int n,m,a[10][10], b[10][10], c[10][10];
};
void Array::input(){
cout<<"Masukkan banyak baris : ";cin>>n;
cout<<"Masukkan banyak kolom : ";cin>>m;
cout<<endl;
cout<<"Input Matriks A"<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cout<<"Data ke A["<<i<<"]"<<"["<<j<<"] : ";cin>>a[i][j];
}
}
cout<<endl;
cout<<"Input Matriks B"<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cout<<"Data ke A["<<i<<"]"<<"["<<j<<"] : ";cin>>b[i][j];
}
}}
void Array::kurang(){
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
c[i][j]=a[i][j]-b[i][j];
}
}
void Array::output(){
cout<<"Matriks A"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<a[i][j]<<" ";
cout<<endl;
}
cout<<endl;
cout<<"Matriks B"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<b[i][j]<<" ";
cout<<endl;
}
cout<<"Hasil Pengurangan"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<c[i][j]<<" ";
cout<<endl;
}
}
int main(int argc, char *argv[])
{
Array x;
x.input();
x.kurang();
x.output();
system("PAUSE");
return EXIT_SUCCESS;
}
Hasil Compile :
#include <iostream>
#include <iomanip>
using namespace std;
class Array{
public:
void input();
void kurang();
void output();
private:
int n,m,a[10][10], b[10][10], c[10][10];
};
void Array::input(){
cout<<"Masukkan banyak baris : ";cin>>n;
cout<<"Masukkan banyak kolom : ";cin>>m;
cout<<endl;
cout<<"Input Matriks A"<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cout<<"Data ke A["<<i<<"]"<<"["<<j<<"] : ";cin>>a[i][j];
}
}
cout<<endl;
cout<<"Input Matriks B"<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cout<<"Data ke A["<<i<<"]"<<"["<<j<<"] : ";cin>>b[i][j];
}
}}
void Array::kurang(){
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
c[i][j]=a[i][j]-b[i][j];
}
}
void Array::output(){
cout<<"Matriks A"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<a[i][j]<<" ";
cout<<endl;
}
cout<<endl;
cout<<"Matriks B"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<b[i][j]<<" ";
cout<<endl;
}
cout<<"Hasil Pengurangan"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<c[i][j]<<" ";
cout<<endl;
}
}
int main(int argc, char *argv[])
{
Array x;
x.input();
x.kurang();
x.output();
system("PAUSE");
return EXIT_SUCCESS;
}
Hasil Compile :
Script C++ menghitung jumlah huruf genap
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
void genap (char kat,int i,int jumlah)
{
char x1;
char x2;
int x=strlen(kat);
if (i>x)
{
cout << "jumlah huruf genap adalah "+jumlah << endl; }
else
{
x1 =((int) kat(i));
x2 =((char) x1);
if (i % 2==0)
{
cout << x2 << endl;
jumlah =jumlah+1;
}
else
{
}
genap(kat,i+1,jumlah);
}
}
int main()
{
char kat[200];
int i, jumlah;
cout<<"masukkan kalimat";
cin >> kat;
i =1;
jumlah =0;
cout << "kalimat genap ada ";
genap(kat,i,jumlah);
return 0;
}
#include <string.h>
#include <stdio.h>
using namespace std;
void genap (char kat,int i,int jumlah)
{
char x1;
char x2;
int x=strlen(kat);
if (i>x)
{
cout << "jumlah huruf genap adalah "+jumlah << endl; }
else
{
x1 =((int) kat(i));
x2 =((char) x1);
if (i % 2==0)
{
cout << x2 << endl;
jumlah =jumlah+1;
}
else
{
}
genap(kat,i+1,jumlah);
}
}
int main()
{
char kat[200];
int i, jumlah;
cout<<"masukkan kalimat";
cin >> kat;
i =1;
jumlah =0;
cout << "kalimat genap ada ";
genap(kat,i,jumlah);
return 0;
}
Script C++ membuat matrik berordo 3x3
#include <iostream>
#include <iomanip>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char *argv[]) {
int i,j;
int data[3][3];
cout<<"-------------------------\n\n";
cout<<" MATRIK 3X3 "<<endl;
for (i=0;i<3;i++)
{ for(j=0;j<3;j++)
{cout<<"masukkan data "<<setw(2)<<i<<";"<<j<<" = "<<setw(3);
cin>>data[i][j];}}
for (i=0;i<3;i++)
{for(j=0;j<3;j++)
{ cout<<setw(3)<<data[i][j];}
cout<<endl;}
return 0;
}
Hasil Compile :
#include <iomanip>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char *argv[]) {
int i,j;
int data[3][3];
cout<<"-------------------------\n\n";
cout<<" MATRIK 3X3 "<<endl;
for (i=0;i<3;i++)
{ for(j=0;j<3;j++)
{cout<<"masukkan data "<<setw(2)<<i<<";"<<j<<" = "<<setw(3);
cin>>data[i][j];}}
for (i=0;i<3;i++)
{for(j=0;j<3;j++)
{ cout<<setw(3)<<data[i][j];}
cout<<endl;}
return 0;
}
Hasil Compile :
Script C++ mancari hasil dari bilangan berpangkat
#include <cstdlib>
#include <iostream>
using namespace std;
class pangkat{
public:
int input();
int proses();
int output();
private:
int b,p,i,h;
};
int pangkat::input(){
cout<<"Silahkan masukan bilangan : ";cin>>b;
cout<<"Silahkan masukan pangkat : ";cin>>p;
}
int pangkat::proses(){
h=1;
for(i=1;i<=p;i++){
h=h*b;
}}
int pangkat::output(){
cout<<h<<endl;
}
int main(int argc, char *argv[])
{ pangkat pa;
pa.input();
pa.proses();
pa.output();
system("PAUSE");
return EXIT_SUCCESS;
}
Hasil Compile :
#include <iostream>
using namespace std;
class pangkat{
public:
int input();
int proses();
int output();
private:
int b,p,i,h;
};
int pangkat::input(){
cout<<"Silahkan masukan bilangan : ";cin>>b;
cout<<"Silahkan masukan pangkat : ";cin>>p;
}
int pangkat::proses(){
h=1;
for(i=1;i<=p;i++){
h=h*b;
}}
int pangkat::output(){
cout<<h<<endl;
}
int main(int argc, char *argv[])
{ pangkat pa;
pa.input();
pa.proses();
pa.output();
system("PAUSE");
return EXIT_SUCCESS;
}
Hasil Compile :
Refleksi Pertemuan Kedelapan
Pertemuan kali ini membahas tentang searching dan sorting. Sorting adalah usaha untuk mengurutkan data dari yang tak terurut menjadi urut. Beberapa macam sorting yaitu : bubble sort, selection sort, dll.
Kendala saat kuliah : Belum paham betul untuk pembuatan program dengan metode sorting. solusinya perlu banyak latihan dan belajar.
Download materi : sudah
Kendala saat kuliah : Belum paham betul untuk pembuatan program dengan metode sorting. solusinya perlu banyak latihan dan belajar.
Download materi : sudah
Refleksi Pertemuan Ketujuh
Pertemuan kali ini membahas tentang array 1 dimensi. Array merupakan struktur data yang mengandung beberapa type data yang memiliki type sama.
Kendala saat perkuliahan : belum ada kendala, namun masih perlu banyak latihan.
Download materi : sudah
Kendala saat perkuliahan : belum ada kendala, namun masih perlu banyak latihan.
Download materi : sudah
Refleksi Pertemuan Keenam
Pada pertemuan keenam saya mempelajari tentang ateri rekursif dan iteratif. Rekursif adalah program yang memanggil dirinya sendiri sebagai pengganti perulangan. Sedangkan iteratif program yang menggunakan perulangan.
Kendala saat perkuliahan : belum ada kendala, namun masih perlu banyak latihan.
Download materi : sudah
Kendala saat perkuliahan : belum ada kendala, namun masih perlu banyak latihan.
Download materi : sudah
Script C++ Program ATM
#include <iostream>
#include <cstdlib>
using namespace std;
class Panji{
public:
Panji();
void in();
void on1();
void on2();
void menu();
void again();
private:
char yn;
int i, kirim, pin=1400018145, tujuan, pilih, saldo, jum=1000000, a[4]={0,100000,500000,1000000};
};
Panji::Panji(){
cout<<"Nama : Muhammad Panji Wijaya"<<endl;
cout<<"Nim : 1400018145"<<endl;
}
void Panji::on1(){
cout<<"\t\t\tATM"<<endl<<endl;
cout<<"masukan PIN anda=";cin>>pin;
if(pin!=1400018145){
for(i=0;i<=2;i++){
if(pin!=1400018145){
cout<<"Pin salah, masukan kembali PIN anda=";cin>>pin;
}
else{
cout<<endl; menu();
}
}
cout<<"Pin 3x salah,ATM sementara terblokir"<<endl;
cout<<"silahkan hubungi petugas bank"<<endl;
}
else {
cout<<endl; menu ();
}
}
void Panji::menu(){
cout<<"\t SELAMAT DATANG DI ATM"<<endl;
cout<<".........................................."<<endl;
cout<<"MENU"<<endl;
cout<<"1. AMBIL UANG"<<endl;
cout<<"2. LIHAT SALDO"<<endl;
cout<<"3. TRANSFER"<<endl;
cout<<"4. KELUAR PROGRAM"<<endl;
cout<<"..........................................."<<endl;
cout<<"PILIHAN [1,2,3,4]= ";cin>>pilih;
while (pilih!=1 && pilih!=2 && pilih!=3 &&pilih!=4){//jika pilihan nggak ada akan di peringatan lagi
cout<<"menu yang anda pilih tidak tersedia, silahkan masukkan pilihan anda"<<endl;//satpam ATM
cout<<"pilihan [1,2,3,4]=";cin>>pilih;
}
on2();
}
void Panji::again(){
cout<<"Transaksi lagi?b(Y/N) ";cin>>yn;//transaksi lagi tidak?
if(yn=='y' || yn=='Y'){
system("CLS");// diclearscreen dulu
menu();//jika ya maka akan memanggil lagi method/functionnya menu
}
if(yn=='n' || yn=='Y'){
system("CLS");
cout<<"Terimakasih telah menggunakan ATM kami"<<endl; // clearscream dan tidak bisa transaksi lagi
}
}
void Panji::on2(){
switch(pilih){
case 1:
cout<<"Nominal yang anda mau ambil"<<endl;
for(i=1;i<4;i++){
cout<<i<<" . "<<a[i]<<endl;
}
cout<<"Pilih=";cin>>i;
cout<<"Uang yang anda ambil= Rp."<<a[i]<<endl;
saldo=jum-a[i];//memunculkan saldo setelah transaksi
cout<<"sisa saldo anda= Rp."<<saldo<<endl;
again();
break;
case 2:
cout<<"sisa saldo anda = Rp."<<jum<<endl;//saldo non transaksi
again();
break;
case 3:
cout<<"Masukkan no. rekening tujuan : ";cin>>tujuan;
cout<<"Masukkan nominal uang yang akan ditransfer : ";cin>>kirim;
if(kirim>=jum){
cout<<"Maaf saldo anda tidak mencukupi";
}
else{
cout<<"No. tujuan transfer : "<<tujuan<<endl;
cout<<"Nominal transfer : "<<kirim<<endl;
cout<<"Sisa saldo : "<<jum-kirim;
}
cout<<endl;
again();
case 4:
system ("CLS");//clearscreem
cout<<"Terimakasih telah menggunakan ATM kami"<<endl;
break;
default:;
}
}
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
Panji c;
c.on1();
return 0;
}
#include <cstdlib>
using namespace std;
class Panji{
public:
Panji();
void in();
void on1();
void on2();
void menu();
void again();
private:
char yn;
int i, kirim, pin=1400018145, tujuan, pilih, saldo, jum=1000000, a[4]={0,100000,500000,1000000};
};
Panji::Panji(){
cout<<"Nama : Muhammad Panji Wijaya"<<endl;
cout<<"Nim : 1400018145"<<endl;
}
void Panji::on1(){
cout<<"\t\t\tATM"<<endl<<endl;
cout<<"masukan PIN anda=";cin>>pin;
if(pin!=1400018145){
for(i=0;i<=2;i++){
if(pin!=1400018145){
cout<<"Pin salah, masukan kembali PIN anda=";cin>>pin;
}
else{
cout<<endl; menu();
}
}
cout<<"Pin 3x salah,ATM sementara terblokir"<<endl;
cout<<"silahkan hubungi petugas bank"<<endl;
}
else {
cout<<endl; menu ();
}
}
void Panji::menu(){
cout<<"\t SELAMAT DATANG DI ATM"<<endl;
cout<<".........................................."<<endl;
cout<<"MENU"<<endl;
cout<<"1. AMBIL UANG"<<endl;
cout<<"2. LIHAT SALDO"<<endl;
cout<<"3. TRANSFER"<<endl;
cout<<"4. KELUAR PROGRAM"<<endl;
cout<<"..........................................."<<endl;
cout<<"PILIHAN [1,2,3,4]= ";cin>>pilih;
while (pilih!=1 && pilih!=2 && pilih!=3 &&pilih!=4){//jika pilihan nggak ada akan di peringatan lagi
cout<<"menu yang anda pilih tidak tersedia, silahkan masukkan pilihan anda"<<endl;//satpam ATM
cout<<"pilihan [1,2,3,4]=";cin>>pilih;
}
on2();
}
void Panji::again(){
cout<<"Transaksi lagi?b(Y/N) ";cin>>yn;//transaksi lagi tidak?
if(yn=='y' || yn=='Y'){
system("CLS");// diclearscreen dulu
menu();//jika ya maka akan memanggil lagi method/functionnya menu
}
if(yn=='n' || yn=='Y'){
system("CLS");
cout<<"Terimakasih telah menggunakan ATM kami"<<endl; // clearscream dan tidak bisa transaksi lagi
}
}
void Panji::on2(){
switch(pilih){
case 1:
cout<<"Nominal yang anda mau ambil"<<endl;
for(i=1;i<4;i++){
cout<<i<<" . "<<a[i]<<endl;
}
cout<<"Pilih=";cin>>i;
cout<<"Uang yang anda ambil= Rp."<<a[i]<<endl;
saldo=jum-a[i];//memunculkan saldo setelah transaksi
cout<<"sisa saldo anda= Rp."<<saldo<<endl;
again();
break;
case 2:
cout<<"sisa saldo anda = Rp."<<jum<<endl;//saldo non transaksi
again();
break;
case 3:
cout<<"Masukkan no. rekening tujuan : ";cin>>tujuan;
cout<<"Masukkan nominal uang yang akan ditransfer : ";cin>>kirim;
if(kirim>=jum){
cout<<"Maaf saldo anda tidak mencukupi";
}
else{
cout<<"No. tujuan transfer : "<<tujuan<<endl;
cout<<"Nominal transfer : "<<kirim<<endl;
cout<<"Sisa saldo : "<<jum-kirim;
}
cout<<endl;
again();
case 4:
system ("CLS");//clearscreem
cout<<"Terimakasih telah menggunakan ATM kami"<<endl;
break;
default:;
}
}
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
Panji c;
c.on1();
return 0;
}
Langganan:
Postingan (Atom)