tutorialswb

TutorialsWB hadir sebagai wadah bagi teman-teman yang ingin "Belajar PHP Dasar". Sehingga kami yakin bahwa TutorialsWB akan menjadi Pusat "Belajar Bahasa Pemrograman PHP" Disamping PHP website ini menyediakan berbagai tips dan trik Blogger. Kami menerima Pemasangan iklan banner atau artikel.

Hubungi Saya

Gabungan Matriks, Deret, Bilangan Prima dan Struct Applied Programming



selamat malam guys kali ini saya akan berbagi aplikasi gabungan antara matriks, deret, bilangan prima dan struct. mungkin jika saya hanya banyak bicara tanpa programmnya anda juga tidak akan mengerti, makanya langsung saja saya akan berikan kodingannya, perhatikan kodingannya dibawah ini.

#include<iostream>
#include<stdlib.h>
using namespace std;

void satu();
void dua();
void tiga();
void empat();
void menu();


main()
{
menu();
}

void menu()
{
system("cls");
int menu;

cout<<" ********Menu Program********" <<endl<<endl;
cout<<"1. Penjumlahan Array 2 Dimensi" <<endl<<endl;
cout<<"2. Deret" <<endl<<endl;
cout<<"3. Bilangan Prima" <<endl<<endl;
cout<<"4. Structures" <<endl<<endl;
cout<<"5. Exit" <<endl<<endl;
cout<<"_____________________________________________________________" <<endl;
cout<<" Masukkan Pilihan Anda [1/2/3/4/5]= "; cin>>menu;

if (menu==1)
{
satu ();
}
else if (menu==2)
{
dua ();
}
else if (menu==3)
{
tiga ();
}
else if (menu==4)
{
empat ();
}
else if (menu==5)
{
system("cls");
}
}

void satu()
{
system("cls");
cout<<"************Penjumlahan Array 2 Dimensi************" <<endl<<endl<<endl;
int matrixA [5][5], a, b, matrixB [10][10],c,d;

    cout<<"-----------Matrix A-----------";
    cout<<"\nEnter the number of rows = ";
    cin>>a;
    cout<<"Enter the number of coulomn= ";
    cin>>b;

    cout<<"----------------------------------------------" <<endl;
    for(int bar=1;bar<=a;bar++)
    {
        for(int kol=1;kol<=b;kol++)
        {
            cout<<"MatrixA[" <<bar <<"][" <<kol <<"]=";
            cin>>matrixA [bar][kol];
        }
        cout<<endl;
    }

    system("cls");
    cout<<"************Penjumlahan Array 2 Dimensi************" <<endl<<endl<<endl;

    cout<<"-----------Matrix B-----------";
    cout<<"\nEnter the rows matriks B= ";
    cin>>c;
    cout<<"Enter the coulomn matriks B= ";
    cin>>d;

    cout<<"----------------------------------------------" <<endl;
    for(int row=1;row<=c;row++)
    {
        for(int col=1;col<=d;col++)
        {
            cout<<"mB[" <<row <<"][" <<col <<"]=";
            cin>>matrixB [row][col];
        }
        cout<<endl;
    }
   
    system("cls");
    cout<<"************Penjumlahan Array 2 Dimensi************" <<endl<<endl<<endl;

    int matrixC [5][5];

    if(a==c && b==d)
    {
        cout<<"-Matrix A-" <<endl;
        for(int bar=1;bar<=a;bar++)
        {
            for(int kol=1;kol<=b;kol++)
            {
                cout<<matrixA[bar][kol] <<" ";
            }
            cout<<endl;
        }

        cout<<endl <<endl;

        cout<<"-Matrix B-" <<endl;
        for(int row=1;row<=c;row++)
        {
            for(int col=1;col<=d;col++)
            {
                cout<<matrixB[row][col] <<" ";
            }
            cout<<endl;
        }

        cout<<endl <<endl;
        cout<<"----------------------------------------------" <<endl;

        cout<<"Matrix A+ Matrix B= " <<endl;
        for(int baris=1;baris<=c;baris++)
        {
            for(int kolom=1;kolom<=d;kolom++)
            {
                matrixC[baris][kolom]= matrixA[baris][kolom]+matrixB [baris][kolom];
            }
            cout<<endl;
        }

        for(int baris=1;baris<=c;baris++)
        {

            for(int kolom=1;kolom<=d;kolom++)
            {
                cout<<matrixC[baris][kolom] <<" ";
            }
            cout<<endl;
        }
    }
    else
    {
        cout<<"Matrix can not be summed";
    }
   
       
char kembali(2);
cout<<"\n\n____________________________________________________________________________" <<endl;
cout<<" Kembali ke program [y/t]? "; cin>>kembali;

if (kembali=='y')
{
satu();
}
else if (kembali=='t')
{
menu();
}
}

void dua()
{
system("cls");
cout<<"************DERET************" <<endl<<endl<<endl;

int z,ganjil1,ganjil2,sum;

cout<<"Enter the limit= "; cin>>z;

for (int x=z; x>=1; x--)
{
   sum=0;
for (int y=1; y<=x; y++)
{
   ganjil1=(y*2)-1;
   sum=ganjil1+sum;
cout<<ganjil1;

if (y<x)
{
cout<<" + ";
}
else
{
cout<<" = ";
}
}
cout<<sum;
cout<<endl;
}

for (int x=2; x<=z; x++)
{
sum=0;
for (int y=1; y<=x; y++)
{
   ganjil2=(y*2)-1;
   sum=ganjil2+sum;
cout<<ganjil2;

if (y<x)
{
cout<<" + ";
}
else
{
cout<<" = ";
}
}
cout<<sum;
cout<<endl;
}
 
char kembali(2);
cout<<"\n\n____________________________________________________________________________" <<endl;
cout<<" Kembali ke program [y/t]? "; cin>>kembali;

if (kembali=='y')
{
dua();
}
else if (kembali=='t')
{
menu();
}
}

void tiga()
{
//Bilangan Prima//
   
char kembali(2);
cout<<"\n\n____________________________________________________________________________" <<endl;
cout<<" Kembali ke program [y/t]? "; cin>>kembali;

if (kembali=='y')
{
tiga();
}
else if (kembali=='t')
{
menu();
}
}

struct student
{
char studentname [5][20], studyprogram [5][20];
int idstudent[5];
}; student student1;

struct score
{
char grade [5];
int midscore [5], finalscore[5], asscore [5], ip[5];
}; score score1;

struct lecturer
{
char lecturername [5][20];
int idlecturer [5];
}; lecturer lecturer1;

void empat()
{
//Structures//
system("cls");

int ip, limitstruct;
cout<<" Masukkan banyak data= "; cin>>limitstruct;

for (int x=1; x<=limitstruct; x++)
{
system("cls");
cout<<" -----Student Data-----" <<endl <<endl;
cout<<"Input Name = "; cin>>student1.studentname[x];
cout<<"Input Id Number = "; cin>>student1.idstudent[x];
cout<<"Input The Study Program = "; cin>>student1.studyprogram[x];

system("cls");
cout<<" -----Score Data-----" <<endl <<endl;
cout<<"Input mid score = "; cin>>score1.midscore[x];
cout<<"Input final score = "; cin>>score1.finalscore[x];
cout<<"Input assignment score = "; cin>>score1.asscore[x];

score1.ip[x]= (score1.midscore[x]*0.3) + (score1.finalscore[x]*0.4) + (score1.asscore[x]*0.3);

if (ip>=90)
{
score1.grade[x]='A';
}
else if (ip>=80&&ip<=89)
{
score1.grade[x]='B';
}
else if (ip>=70&&ip<=79)
{
score1.grade[x]='C';
}
else if (ip>=60&&ip<=69)
{
score1.grade[x]='D';
}
else if (ip>=50&&ip<=59)
{
score1.grade[x]='E';
}

system("cls");
cout<<" -----Lecturer Data-----" <<endl <<endl;
cout<<"Input Number Id = "; cin>>lecturer1.idlecturer[x];
cout<<"Input Lecturer Name = "; cin>>lecturer1.lecturername[x];
cout<<"Subject = "; cin>>student1.studyprogram[x];

}

system("cls");
cout<<"\n\n____________________________________________________________________________" <<endl;
cout<<"ID-Student| Student Name | Subject | NIlai | Grade |Id-Lecturer| Lecturer Name |" <<endl;
cout<<"____________________________________________________________________________" <<endl;

for (int x=1; x<=limitstruct; x++)
    {
    cout<<student1.idstudent[x] <<"\t" <<student1.studentname[x] <<"\t" <<student1.studyprogram[x] <<"\t"<<score1.ip[x]  <<"\t";
cout<<score1.grade[x]<<"\t"<<lecturer1.idlecturer[x] <<"\t" <<lecturer1.lecturername[x];
    cout<<endl;
}
   
char kembali(2);
cout<<"\n\n____________________________________________________________________________" <<endl;
cout<<" Kembali ke program [y/t]? "; cin>>kembali;

if (kembali=='y')
{
empat();
}
else if (kembali=='t')
{
menu();
}
}


tampilan ketika programmnya di run seperti gambar dibawah ini.


giaman guys cukup panjang bukan kodingannya, jika ada yang kurang jelas da sebagainya silahkan tinggalkan comment dibawah, sekian wassalam😃



Baca Juga

closed