Minggu, 06 Agustus 2023

Program Bank Sederhana Bahasa C++

 


#include <iostream>

#include <string>


using namespace std;


class BankAccount {

private:

    string accountNumber;

    string accountHolderName;

    double balance;


public:

    BankAccount(string accNum, string accHolderName) : accountNumber(accNum), accountHolderName(accHolderName), balance(0.0) {}


    void deposit(double amount) {

        balance += amount;

        cout << "Berhasil menabung. Saldo Anda sekarang: Rp" << balance << endl;

    }


    void withdraw(double amount) {

        if (balance >= amount) {

            balance -= amount;

            cout << "Berhasil menarik. Saldo Anda sekarang: Rp" << balance << endl;

        } else {

            cout << "Saldo tidak mencukupi untuk penarikan." << endl;

        }

    }


    void checkBalance() const {

        cout << "Saldo Anda: Rp" << balance << endl;

    }

};


int main() {

    string accountNumber, accountHolderName;

    cout << "Selamat datang di Bank Indonesia!" << endl;

    cout << "Masukkan nomor akun Anda: ";

    cin >> accountNumber;

    cout << "Masukkan nama pemegang akun: ";

    cin.ignore();

    getline(cin, accountHolderName);


    BankAccount account(accountNumber, accountHolderName);


    int choice;

    double amount;


    do {

        cout << "===== MENU BANK =====" << endl;

        cout << "1. Menabung" << endl;

        cout << "2. Menarik" << endl;

        cout << "3. Cek Saldo" << endl;

        cout << "4. Keluar" << endl;

        cout << "Pilih opsi (1/2/3/4): ";

        cin >> choice;


        switch (choice) {

            case 1:

                cout << "Masukkan jumlah uang yang ingin ditabung: ";

                cin >> amount;

                account.deposit(amount);

                break;

            case 2:

                cout << "Masukkan jumlah uang yang ingin ditarik: ";

                cin >> amount;

                account.withdraw(amount);

                break;

            case 3:

                account.checkBalance();

                break;

            case 4:

                cout << "Terima kasih telah menggunakan layanan kami. Sampai jumpa!" << endl;

                break;

            default:

                cout << "Opsi tidak valid. Silakan pilih opsi yang benar." << endl;

                break;

        }

    } while (choice != 4);


    return 0;

}


Program Warung Makan Sederhana bahasa C++


 

berikut kode programnya

#include <iostream>

#include <string>

#include <iomanip>


using namespace std;


// Function to calculate the total cost of the order

double calculateTotalCost(int quantity, double price) {

    return quantity * price;

}


int main() {

    // Menu items

    string menu[] = {"Nasi Goreng", "Mie Goreng", "Ayam Goreng", "Sate Ayam"};

    double prices[] = {15000.0, 12000.0, 18000.0, 20000.0};

    const int numMenuItems = sizeof(menu) / sizeof(menu[0]);


    cout << "Welcome to Warung Makan Sederhana!" << endl;

    cout << "Menu:" << endl;


    // Display the menu

    for (int i = 0; i < numMenuItems; i++) {

        cout << i + 1 << ". " << menu[i] << " - Rp " << prices[i] << endl;

    }


    // Take customer order

    int choice, quantity;

    double totalCost = 0.0;


    while (true) {

        cout << "Enter menu number (0 to finish order): ";

        cin >> choice;


        if (choice == 0) {

            break;

        } else if (choice >= 1 && choice <= numMenuItems) {

            cout << "Enter quantity: ";

            cin >> quantity;


            double itemTotal = calculateTotalCost(quantity, prices[choice - 1]);

            totalCost += itemTotal;


            cout << menu[choice - 1] << " (x" << quantity << ") added to the order. Subtotal: Rp " << itemTotal << endl;

        } else {

            cout << "Invalid menu number. Please try again." << endl;

        }

    }


    // Display the total bill

    cout << "===================" << endl;

    cout << "Total bill: Rp " << totalCost << endl;

    cout << "Thank you for dining with us!" << endl;


    return 0;

}


Sabtu, 05 Agustus 2023

Program Kasir sederhana Menggunakan bahasa pemrograman C++

Berikut Programnya

 #include <iostream>

using namespace std;


int main() {

    int jumlahItem;

    double hargaSatuan, totalHarga, pajak, totalAkhir;


    cout << "Program Kasir" << endl;

    cout << "Masukkan jumlah item yang dibeli: ";

    cin >> jumlahItem;


    totalHarga = 0;

    for (int i = 1; i <= jumlahItem; i++) {

        cout << "Masukkan harga satuan item " << i << ": ";

        cin >> hargaSatuan;


        totalHarga += hargaSatuan;

    }


    // Misalnya PPN sebesar 10%

    pajak = 0.1 * totalHarga;

    totalAkhir = totalHarga + pajak;


    cout << "Total Harga: " << totalHarga << endl;

    cout << "Pajak (10%): " << pajak << endl;

    cout << "Total Akhir: " << totalAkhir << endl;


    return 0;

}

semoga bermanfaat

Jumat, 04 Agustus 2023

Tugas Grafika Komputer OpenGL Mobil 3D

Berikut Ini adalah Code Program OpenGL membuat mobil keren.


#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <glut.h>

#define Vrt glVertex3s

int proj = 1, new_mouse = 0, mouse_rot = 1, mouse_trn = 0;

float turn = 50.0, tipp = 30.0, twst = 0.0, x_click = 0, y_click = 0, xtm = 0.0, ytm = 0.0,
      scl = 1.0, xcr = 0.0;

GLfloat lit1_spc[] = {0.20, 0.20,  0.15, 1.00},
        lit1_dfs[] = {0.70, 0.70,  0.65, 1.00},
lit1_amb[] = {0.25, 0.25,  0.20, 1.00},
lit1_pos[] = {0.20, 2.50,  5.20, 1.00};

GLfloat lit2_spc[] = { 0.00,  0.00,  0.00, 1.00},
        lit2_dfs[] = { 0.30,  0.30,  0.35, 1.00},
lit2_amb[] = { 0.20,  0.20,  0.25, 1.00},
lit2_pos[] = { 1.50, -2.00, -4.00, 0.01};

//-----------------------------------------   Keybord   --------------------------------------------

void Keybord (unsigned char ch, int x, int y)
{
    printf ("   Keyboard -> '%c' pressed.", ch);

    switch (ch)  {
       case 'p' :  proj      = !proj;        break;
       case 'r' :  mouse_trn = 0;
                   mouse_rot = 1;            break;
       case 't' :  mouse_trn = 1;
                   mouse_rot = 0;            break;
       case 'z' :  turn = 0.0; tipp = 0.0;
                   xtm  = 0.0; ytm  = 0.0;
                   scl  = 1.0;               break;
       case '-' :  scl *= 0.92;              break;
       case '+' :  scl *= 1.06;              break;
       case 'd' :  xcr += 2.00;              break;
       case 'D' :  xcr -= 2.00;              break;

       case  27 :  exit (0);                 break;
    }

    glutPostRedisplay();
}

//--+----4----+----3----+----2----+----1----+----|----+----1----+----2----+----3----+----4----+----5
//------------------------------------------   Mouse   ---------------------------------------------

void Mouse (int button, int state, int x, int y)
{
    x_click = x;
    y_click = y;

    new_mouse = 1;
}

//--+----4----+----3----+----2----+----1----+----|----+----1----+----2----+----3----+----4----+----5
//------------------------------------------   Motion   --------------------------------------------

void Motion (int x, int y)
{
    float turn_del, tipp_del, x_del, y_del;

    static int c = 0, x_sav, y_sav;
    static float turn_save = 0.0, tipp_save = 0.0;

    // printf ("   Motion:  %5d ->   x = %5d, y = %5d.", ++c, x, y);

    if (new_mouse)  {
       new_mouse = 0;
       x_sav = x_click;
       y_sav = y_click;
    }

    if (mouse_rot)  {

       turn_del = x - x_sav;
       turn += turn_del;

       tipp_del = y - y_sav;
       tipp += tipp_del;

    }  else if (mouse_trn)  {

       x_del = float(x - x_sav) * 0.01;
       xtm  += x_del;

       y_del = float(y - y_sav) * 0.01;
       ytm  -= y_del;

    }

    x_sav = x;
    y_sav = y;

    glutPostRedisplay();
}

//---9----8----7----6----5----4----3----2----1---++---1----2----3----4----5----6----7----8----9---\\
//---------------------------------------   Init_Lights   ------------------------------------------

void Init_Lights (void)
{
    glLightfv (GL_LIGHT1, GL_SPECULAR, lit1_spc);
    glLightfv (GL_LIGHT1, GL_DIFFUSE , lit1_dfs);
    glLightfv (GL_LIGHT1, GL_AMBIENT , lit1_amb);
    glLightfv (GL_LIGHT1, GL_POSITION, lit1_pos);

    glLightfv (GL_LIGHT2, GL_SPECULAR, lit2_spc);
    glLightfv (GL_LIGHT2, GL_DIFFUSE , lit2_dfs);
    glLightfv (GL_LIGHT2, GL_AMBIENT , lit2_amb);
    glLightfv (GL_LIGHT2, GL_POSITION, lit2_pos);

    glEnable (GL_LIGHT1);
    glEnable (GL_LIGHT2);

    glEnable (GL_AUTO_NORMAL);
    glEnable (GL_NORMALIZE  );
}

//----------------------------------------   Draw_Road   -------------------------------------------

void Draw_Road (void)
{
    glColor3f (0.30,0.25,0.30);
    glEnable (GL_LIGHTING);

    glPushMatrix();
       glTranslatef (0.0, -25.0, 0.0);
       glScalef     (10.0, 0.3,3.0);
       glutSolidCube (-20.0f);
    glPopMatrix();
}

//---------------------------------------   Render_Wheel   -----------------------------------------

void Render_Wheel (int xt, int yt, int zt)
{
    glPushMatrix();
       glTranslatef   (xt, yt, zt);
       glutSolidTorus (2,5,12,36);
    glPopMatrix();
}

//-----------------------------------------   Draw_Car   -------------------------------------------

void Draw_Car (void)
{
    glDisable (GL_LIGHTING);

    glBegin (GL_QUADS);
       glColor3f (0.3, 0.6, 0.6);
       Vrt(-40,  0, 15); Vrt( 40,  0, 15); Vrt( 40,-15, 15); Vrt(-40,-15, 15);  // left
       Vrt(-40,  0,-15); Vrt( 40,  0,-15); Vrt( 40,-15,-15); Vrt(-40,-15,-15);  // right
       glColor3f (0.4, 0.6, 0.6);
       Vrt( 40,  0,-15); Vrt( 40,  0, 15); Vrt( 40,-15, 15); Vrt( 40,-15,-15);  // back
       Vrt(-40,  0,-15); Vrt(-40,  0, 15); Vrt(-40,-15, 15); Vrt(-40,-15,-15);  // front
       glColor3f (0.4, 0.6, 0.8);
       Vrt(-40,  0, 15); Vrt(-40,  0,-15); Vrt( 40,  0,-15); Vrt( 40,  0, 15);  // trunks
       Vrt(-10, 10, 15); Vrt(-10, 10,-15); Vrt( 20, 10,-15); Vrt( 20, 10, 15);  // roof
       glColor3f (0.7, 0.7, 0.5);
       Vrt(-20,  0, 15); Vrt(-10, 10, 15); Vrt( 20, 10, 15); Vrt( 25,  0, 15);  // window l
       Vrt(-20,  0,-15); Vrt(-10, 10,-15); Vrt( 20, 10,-15); Vrt( 25,  0,-15);  // window r
       glColor3f (0.7, 0.6, 0.5);
       Vrt(-10, 10, 15); Vrt(-20,  0, 15); Vrt(-20,  0,-15); Vrt(-10, 10,-15);  // windshield
       Vrt( 20, 10, 15); Vrt( 20, 10,-15); Vrt( 25,  0,-15); Vrt( 25,  0, 15);  // rear window
       glColor3f (0.4, 0.5, 0.5);
       Vrt(-40,-15, 15); Vrt(-40,-15,-15); Vrt( 40,-15,-15); Vrt( 40,-15, 15);  // bottom
    glEnd ();


    // Render wheels using torus's with lighting on.

     glEnable     (GL_LIGHTING);
     glColor3f    (0.3, 0.3, 0.3);
     Render_Wheel (-20,-15, 15);
     Render_Wheel ( 20,-15, 15);
     Render_Wheel (-20,-15,-15);
     Render_Wheel ( 20,-15,-15);
}

//------------------------------------------   Poster's Display   ----------------------------------

void Display (void)
{
    static float x = 2.0;

    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode   (GL_PROJECTION);
    glLoadIdentity ();

    if (proj == 0)  glOrtho        (-x, x, -x, x, 0.0, 10.0);
    else            gluPerspective ( 60.0,  1.0,  1.0, 10.0);

    glMatrixMode   (GL_MODELVIEW);
    glLoadIdentity ();

    glTranslatef (xtm, ytm, -4.0);       // Place objects between near and far clipping planes.
    glRotatef    (tipp,  1, 0, 0);       // Rotate around screen horizontal axis.
    glRotatef    (turn,  0, 1, 0);       // Rotate around world    vertical axis.
    glLightfv (GL_LIGHT1, GL_POSITION, lit1_pos);
    glLightfv (GL_LIGHT2, GL_POSITION, lit2_pos);
    glScalef     (scl, scl, scl );       // Scale world relative to its origin.
    glScalef     (0.02, 0.02, 0.02);

    Draw_Road ();
    glTranslatef (-xcr, 0.0, 0.0);
    Draw_Car  ();

    glutSwapBuffers();
}

//-----------------------------------------   Init_GL   --------------------------------------------

void Init_GL (void)
{
    Init_Lights ();

    glEnable (GL_DEPTH_TEST);
    glEnable (GL_LIGHTING  );
    glEnable (GL_COLOR_MATERIAL);

    glColorMaterial (GL_AMBIENT_AND_DIFFUSE, GL_FRONT);
    glColorMaterial (GL_SPECULAR           , GL_FRONT);

    glClearColor (0.2, 0.3, 0.3, 1.0);
}

//----------------------------------------   Init_Glut   -------------------------------------------

int Init_Glut (void)
{
    glutInitDisplayMode    (GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowPosition (800, 200);
    glutInitWindowSize     (800, 800);
    glutCreateWindow       ("Carmine's Car On Road");

    glutKeyboardFunc (Keybord);
    glutDisplayFunc  (Display);
    glutMouseFunc    (Mouse  );
    glutMotionFunc   (Motion );
}

//------------------------------------------   main   ----------------------------------------------

int main (int argc, char **argv)
{
    glutInit (&argc, argv);

    Init_Glut ();
    Init_GL   ();

    glutMainLoop ();

    return (1);
}

// -------------------------------------------------------------------------------------------------


Tampilan 3D



Program Bank Sederhana Bahasa C++

  #include <iostream> #include <string> using namespace std; class BankAccount { private:     string accountNumber;     string a...