Senin, 14 November 2016

Aplikasi gotoxy dan clrscr C++

Kursus Hari5 Materi2 


/** Aplikasi clrscr(), dan gotoxy( x, y ) untuk Windows OS's **/

#include <windows.h>
#include <stdio.h>

void clrscr()
{
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); // gets the window handle
COORD coord = {0, 0}; // sets coordinates to 0,0
DWORD count;

CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hStdOut, &csbi); // gets the buffer info (screen)

// fill all characters as ' ' (empty the screen)
FillConsoleOutputCharacter(hStdOut, ' ', csbi.dwSize.X * csbi.dwSize.Y, coord, &count);

// resets the cursor position
SetConsoleCursorPosition(hStdOut, coord);
}

void gotoxy (int x, int y)
{
COORD coord; // coordinates
coord.X = x; coord.Y = y; // X and Y coordinates
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}


#include<iostream.h>
#include<conio.h>
#include<iomanip.h>

int main() {
    
    char nama[30], barang[30];
    int jumlah_kursus, jumlah_peserta = 0;
    long harga_kursus, jumlah_harga, total_bayar = 0;

    cout << "Nama Perusahaan            : " ; 
cin >> nama;
    cout << "Jumlah Kursus yg Diikuti   : " ; 
cin >> jumlah_kursus;
    cout << endl;
    
    cout << "=====================================================================" << endl;
    cout << "| NO |   NAMA KURSUS | JUMLAH PESERTA | HARGA KURSUS | JUMLAH HARGA |" << endl;
    cout << "=====================================================================" << endl;
    
    for (int i = 1; i <= jumlah_kursus; i++) {
        gotoxy(1,i+6); cout << "|";
        gotoxy(6,i+6); cout << "|";
        gotoxy(24,i+6); cout << "|";
        gotoxy(38,i+6); cout << "|";
        gotoxy(53,i+6); cout << "|";
        gotoxy(68,i+6); cout << "|";
        gotoxy(3,i+6); cout << setw(2) << i;
    }
    
    cout << endl;
    cout << "====================================================================" << endl;
    cout << "|                     TOTAL                         |              |" << endl;
    cout << "====================================================================" << endl;
    
    for (int j = 1; j <= jumlah_kursus; j++) {
        gotoxy(8,j+6); cin >> barang;
        gotoxy(26,j+6); cin >> jumlah_peserta;
        gotoxy(40,j+6); cin >> harga_kursus;
        jumlah_harga = jumlah_peserta * harga_kursus;
        gotoxy(55,j+6); cout << setw(12) << jumlah_harga;
        total_bayar = total_bayar + jumlah_harga;
    }
    gotoxy(55,jumlah_kursus+8); cout << setw(12) << total_bayar << endl;
    
    gotoxy(1,jumlah_kursus+11);cout << "TERIMA KASIH";
    
    getch();
return 0;
}

Adapun hasil yang didapat adalah sbb:









1 komentar:

  1. Slot Machines for Sale | JTM Hub
    Find Slot Machines & Video Game Dealers for 계룡 출장샵 sale at JTM Shop or online for 통영 출장마사지 best prices at JTM. 제천 출장샵 Slot machines & Video Game Dealers at Slot 전라북도 출장마사지 Machines at JTM. 거제 출장마사지

    BalasHapus