#include
#include
void main ( )
{
const float phi=3.14;
float r,a,t,kell,luas;
int kode;
char pilih;
awal :
cout<<"||======================================||"<<<"||Program menghitung rumus bangun datar ||"<<<"||======================================||"<<<"\n 1. Keliling Lingkaran "<<<"2. Luas Segitiga "<<<"\n Pilihan anda adalah (1..2) = "; cin>>kode;
switch (kode)
{
case 1 :
cout<<"Anda memilih nomor 1 yaitu menghitung keliling lingkaran"; cout<<"\nMasukkan jari-jari = "; cin>>r;
kell=2*phi*r;
cout<<"\nKeliling Lingkaran = "<<<<"Anda memilih nomor 2 yaitu menghitung luas segitiga"; cout<<"\nMasukkan alas = "; cin>>a;
cout<<\nMasukkan tinggi = "; cin>>t;
luas=a*t*0.5;
cout<<"\nLuas Segitiga = "<<<<"\nMaaf anda memasukkan kode yang salah"<<<"Ingin mengulang lagi [Y/T] = "; cin>>pilih;
if ((pilih=='Y'||(pilih=='y'))
{
goto awal;
}
clrscr ( );
cout<<"\nGoodbye!!!";
}
goto awal;
getch ( );
}
#include
void main ( )
{
const float phi=3.14;
float r,a,t,kell,luas;
int kode;
char pilih;
awal :
cout<<"||======================================||"<<<"||Program menghitung rumus bangun datar ||"<<<"||======================================||"<<<"\n 1. Keliling Lingkaran "<<<"2. Luas Segitiga "<<<"\n Pilihan anda adalah (1..2) = "; cin>>kode;
switch (kode)
{
case 1 :
cout<<"Anda memilih nomor 1 yaitu menghitung keliling lingkaran"; cout<<"\nMasukkan jari-jari = "; cin>>r;
kell=2*phi*r;
cout<<"\nKeliling Lingkaran = "<<<<"Anda memilih nomor 2 yaitu menghitung luas segitiga"; cout<<"\nMasukkan alas = "; cin>>a;
cout<<\nMasukkan tinggi = "; cin>>t;
luas=a*t*0.5;
cout<<"\nLuas Segitiga = "<<<<"\nMaaf anda memasukkan kode yang salah"<<<"Ingin mengulang lagi [Y/T] = "; cin>>pilih;
if ((pilih=='Y'||(pilih=='y'))
{
goto awal;
}
clrscr ( );
cout<<"\nGoodbye!!!";
}
goto awal;
getch ( );
}
#include <windows.h>
static char g_szClassName[] = "MyWindowClass";
static HINSTANCE g_hInst = NULL;
const UINT idTimer1 = 1;
UINT nTimerDelay = 10;
HBITMAP hbmBall, hbmMask;
BITMAP bm;
int ballX, ballY;
int deltaX, deltaY;
int deltaValue = 4;
void EraseBall(HDC hdc)
{
RECT rc;
rc.left = ballX;
rc.top = ballY;
rc.right = ballX + bm.bmWidth;
rc.bottom = ballY + bm.bmHeight;
FillRect(hdc, &rc, (HBRUSH)(COLOR_BTNFACE+1));
}
void DrawBall(HDC hdc)
{
HDC hdcMemory;
hdcMemory = CreateCompatibleDC(hdc);
SelectObject(hdcMemory, hbmMask);
BitBlt(hdc, ballX, ballY, bm.bmWidth, bm.bmHeight, hdcMemory, 0, 0, SRCAND);
SelectObject(hdcMemory, hbmBall);
BitBlt(hdc, ballX, ballY, bm.bmWidth, bm.bmHeight, hdcMemory, 0, 0, SRCPAINT);
DeleteDC(hdcMemory);
}
void UpdateBall(HWND hwnd)
{
RECT rc;
GetClientRect(hwnd, &rc);
ballX += deltaX;
ballY += deltaY;
if(ballX < 0){
ballX = 0;
deltaX = deltaValue;
}
else if(ballX + bm.bmWidth > rc.right){
ballX = rc.right - bm.bmWidth;
deltaX = -deltaValue;
}
if(ballY < 0){
ballY = 0;
deltaY = deltaValue;
}
else if(ballY + bm.bmHeight > rc.bottom){
ballY = rc.bottom - bm.bmHeight;
deltaY = -deltaValue;
}
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_CREATE:
hbmBall = LoadBitmap(g_hInst, "BALLBMP");
hbmMask = LoadBitmap(g_hInst, "MASKBMP");
if(!hbmBall || !hbmMask){
MessageBox(hwnd, "Load of resources failed.", "Error",
MB_OK | MB_ICONEXCLAMATION);
return -1;
}
GetObject(hbmBall, sizeof(bm), &bm);
SetTimer(hwnd, idTimer1, nTimerDelay, NULL);
ballX = 0;
ballY = 0;
deltaX = deltaValue;
deltaY = deltaValue;
break;
case WM_TIMER:
if(hbmBall && hbmMask)
{
HDC hdcWindow;
hdcWindow = GetDC(hwnd);
EraseBall(hdcWindow);
UpdateBall(hwnd);
DrawBall(hdcWindow);
ReleaseDC(hwnd, hdcWindow);
}
break;
case WM_PAINT:
if(hbmBall && hbmMask)
{
PAINTSTRUCT ps;
HDC hdcWindow;
hdcWindow = BeginPaint(hwnd, &ps);
DrawBall(hdcWindow);
EndPaint(hwnd, &ps);
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
KillTimer(hwnd, idTimer1);
DeleteObject(hbmBall);
DeleteObject(hbmMask);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX WndClass;
HWND hwnd;
MSG Msg;
g_hInst = hInstance;
WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = 0;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = g_hInst;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = g_szClassName;
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&WndClass))
{
MessageBox(0, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"A Bitmap Program",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 320, 240,
NULL, NULL, g_hInst, NULL);
if(hwnd == NULL)
{
MessageBox(0, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
static char g_szClassName[] = "MyWindowClass";
static HINSTANCE g_hInst = NULL;
const UINT idTimer1 = 1;
UINT nTimerDelay = 10;
HBITMAP hbmBall, hbmMask;
BITMAP bm;
int ballX, ballY;
int deltaX, deltaY;
int deltaValue = 4;
void EraseBall(HDC hdc)
{
RECT rc;
rc.left = ballX;
rc.top = ballY;
rc.right = ballX + bm.bmWidth;
rc.bottom = ballY + bm.bmHeight;
FillRect(hdc, &rc, (HBRUSH)(COLOR_BTNFACE+1));
}
void DrawBall(HDC hdc)
{
HDC hdcMemory;
hdcMemory = CreateCompatibleDC(hdc);
SelectObject(hdcMemory, hbmMask);
BitBlt(hdc, ballX, ballY, bm.bmWidth, bm.bmHeight, hdcMemory, 0, 0, SRCAND);
SelectObject(hdcMemory, hbmBall);
BitBlt(hdc, ballX, ballY, bm.bmWidth, bm.bmHeight, hdcMemory, 0, 0, SRCPAINT);
DeleteDC(hdcMemory);
}
void UpdateBall(HWND hwnd)
{
RECT rc;
GetClientRect(hwnd, &rc);
ballX += deltaX;
ballY += deltaY;
if(ballX < 0){
ballX = 0;
deltaX = deltaValue;
}
else if(ballX + bm.bmWidth > rc.right){
ballX = rc.right - bm.bmWidth;
deltaX = -deltaValue;
}
if(ballY < 0){
ballY = 0;
deltaY = deltaValue;
}
else if(ballY + bm.bmHeight > rc.bottom){
ballY = rc.bottom - bm.bmHeight;
deltaY = -deltaValue;
}
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_CREATE:
hbmBall = LoadBitmap(g_hInst, "BALLBMP");
hbmMask = LoadBitmap(g_hInst, "MASKBMP");
if(!hbmBall || !hbmMask){
MessageBox(hwnd, "Load of resources failed.", "Error",
MB_OK | MB_ICONEXCLAMATION);
return -1;
}
GetObject(hbmBall, sizeof(bm), &bm);
SetTimer(hwnd, idTimer1, nTimerDelay, NULL);
ballX = 0;
ballY = 0;
deltaX = deltaValue;
deltaY = deltaValue;
break;
case WM_TIMER:
if(hbmBall && hbmMask)
{
HDC hdcWindow;
hdcWindow = GetDC(hwnd);
EraseBall(hdcWindow);
UpdateBall(hwnd);
DrawBall(hdcWindow);
ReleaseDC(hwnd, hdcWindow);
}
break;
case WM_PAINT:
if(hbmBall && hbmMask)
{
PAINTSTRUCT ps;
HDC hdcWindow;
hdcWindow = BeginPaint(hwnd, &ps);
DrawBall(hdcWindow);
EndPaint(hwnd, &ps);
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
KillTimer(hwnd, idTimer1);
DeleteObject(hbmBall);
DeleteObject(hbmMask);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX WndClass;
HWND hwnd;
MSG Msg;
g_hInst = hInstance;
WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = 0;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = g_hInst;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = g_szClassName;
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&WndClass))
{
MessageBox(0, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"A Bitmap Program",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 320, 240,
NULL, NULL, g_hInst, NULL);
if(hwnd == NULL)
{
MessageBox(0, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
- #include <stdio.h>
- #include <conio.h>
- #include
- <math.h> /*untuk mengaktifkan SQRT*/
- main()
- { float r1,r2,x1,x2,a,b,c; /*deklarasi bertipe float*/
- clrscr(); /*untuk membersihkan layar*/
- printf("Masukan Bilangan A = "); /*untuk memasukan data A*/
- scanf("%f",&a); /*membaca sebuah bilangan float*/
- printf("Masukan Bilangan B = "); /*untuk memasukan data B*/
- scanf("%f",&b); /*membaca sebuah bilangan float*/
- printf("Masukan Bilangan C = "); /*untuk memasukan data C*/
- scanf("%f",&c); /*membaca sebuah bilangan float*/
- r1=b*b-4*a*c;
- r2=sqrt(r1);
- x1=(-b+r2)/(2*a);
- x2=(-b-r2)/(2*a);
- printf("Nilai x1 = %f\n",x1); /*menampilkan isi variable x1*/
- printf("Nilai x2 = %f\n",x2); /*menampilkan isi variable x2*/
- getch(); /*menahan tampilan di layar*/
- }
- </math.h></conio.h></stdio.h>
- #include <stdio.h>
- #include <conio.h>
- main()
- { float j,r,b1,b2,b3,b4,b5; /*deklarasi bertipe float*/
- clrscr(); /*untuk membersihkan layar*/
- printf("Masukan Bilangan 1 = "); /*untuk memasukan bilangan 1*/
- scanf("%f",&b1); /*membaca sebuah bilangan float*/
- printf("Masukan Bilangan 2 = "); /*untuk memasukan bilangan 2*/
- scanf("%f",&b2); /*membaca sebuah bilangan float*/
- printf("Masukan Bilangan 3 = "); /*untuk memasukan bilangan 3*/
- scanf("%f",&b3); /*membaca sebuah bilangan float*/
- printf("Masukan Bilangan 4 = "); /*untuk memasukan bilangan 4*/
- scanf("%f",&b4); /*membaca sebuah bilangan float*/
- printf("Masukan Bilangan 5 = "); /*untuk memasukan bilangan 5*/
- scanf("%f",&b5); /*membaca sebuah bilangan float*/
- j=b1+b2+b3+b4+b5;
- r=j/5;
- printf("Jumlah = %0.2f\n",j); /*menampilkan isi variable j*/
- printf("Rata-rata = %0.2f\n",r); /*menampilkan isi variable r*/
- getch(); /*menahan tampilan di layar*/
- }
- </conio.h></stdio.h>
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
main()
{
int s,l;
cout<<”Diketahui: Sisi=”;cin>>s;
cout<<”Diketahui: Sisi=”;cin>>s;
cout<<”Ditanya : Luas=..?”<<endl;
cout<<”s=”<<s<<”cm”<<endl;
cout<<”s=”<<s<<”cm”<<endl;
cout<<”L=..?”<<endl;
l=(s*s);
cout<<”Nilai L=(s*s)=”<<l<<”cm”;
getch();
}
Tidak ada komentar:
Posting Komentar