Senin, 31 Maret 2014
Minggu, 30 Maret 2014
REFLEKSI PERTEMUAN MINGGU KE LIMA PADA HARI SELASA, 25 MARET 2014
Tidak terasa sudah pertemuan minggu ke 5. Hal-hal yang saya dapat selama pertemuan ke lima ini adalah sebagai berikut:
1. Materi yang diperoleh:
a. Penjelasan tentang sub program
b. Perulangan (loop) dengan subprogram: rekursif.
c. Penghitungan faktorial, deret aritmatik
2. Usaha untuk memahami manteri yang belum dipahami:
a. Memahami sendiri terlebih dahulu
b. browsing di google
c. tanya ke teman sekelas atau kelas lain
d. tanya ke mentor atau kakak tingkat yang lebih tau
Minggu, 23 Maret 2014
LOOPING KEHIDUPAN (KESEHARIAN KITA)
For, While Do, dan Repeat Until
Perulangan Dalam Kehidupan Kita:
1. Kita tahu dalam waktu sehari kita mengalami 24 jam begitupun juga hari-hari berikutnya. Kegiatan kita menjelang malam pun tidur dan saat menjelang pagi pun kita kan terbangun untuk melanjutkan dan memulai aktivitas seperti biasanya. seperti halnya mandi, makan, kuliah, jalan-jalan dan lain sebagainya. Hal tesebut akan kita lakukan sehari-hari untuk beberapa hari kemudian hingga pemberhentian looping diperhentikan oleh Allah SWT ^^ Begitulah algoritma kehidupan..
2. Hal yang lain yang ada algoritmanya adalah hendak makan seperti langkah pertama mengambil piring, mengambil nasi-lauk-sayur-sendok-airputih dan sebagainya. Dalam kehidupan ini pun harus berjalan sesuai algoritma agar semuanya terlaksana dengan lancar jaya. Begitupun dengan kita tuk membuat program harus kita rangkai dulu algoritmanya ^.^
Pertemuan 04. E-Book Program to Process Bald Eagle Sightings for a Year
#include <cstdlib>
#include <iostream>
#define SENTINEL 0
#define NUM_MONTHS 12
using namespace std;
int main(void)
{
int month,mem_sight,sightings;
cout<<"BALD EAGLE SIGHTINGS"<<endl;
for(month=1;month<=NUM_MONTHS;month++){
sightings=0;
cin>>mem_sight;
while (mem_sight != SENTINEL){
if(mem_sight>=0)
sightings += mem_sight;
else
cout<<"Warning, negative count ignored"<<mem_sight<<endl;
cin>>mem_sight;
}
cout<<"month : "<<month<<sightings;
}
system("PAUSE");
return EXIT_SUCCESS;
}
#include <iostream>
#define SENTINEL 0
#define NUM_MONTHS 12
using namespace std;
int main(void)
{
int month,mem_sight,sightings;
cout<<"BALD EAGLE SIGHTINGS"<<endl;
for(month=1;month<=NUM_MONTHS;month++){
sightings=0;
cin>>mem_sight;
while (mem_sight != SENTINEL){
if(mem_sight>=0)
sightings += mem_sight;
else
cout<<"Warning, negative count ignored"<<mem_sight<<endl;
cin>>mem_sight;
}
cout<<"month : "<<month<<sightings;
}
system("PAUSE");
return EXIT_SUCCESS;
}
Bahasa C++ run
Pertemuan 04. E-Book Figure Program to draw a moving ball
#include <cstdlib>
#include <iostream>
#include <graphics.h>
#define TRUE 1
using namespace std;
int main(void)
{
const int PAUSE=20;
const int DELTA=5;
const int RADIUS=30;
const int COLOR=RED;
int width,height,x,y,stepX,stepY;
width = getmaxwidth();
height = getmaxheight();
initwindow(width, height,"Pong - close window to quit",0,0,TRUE);
x = RADIUS;
y = RADIUS;
stepX = DELTA;
stepY = DELTA;
while (TRUE){
clearviewport();
setfillstyle(SOLID_FILL, COLOR);
fillellipse(x, y, RADIUS, RADIUS);
swapbuffers();
delay(PAUSE);
if(x<= RADIUS)
stepX = DELTA;
else if (x>= width - RADIUS)
stepX = -DELTA;
if(y <= RADIUS)
stepY = DELTA;
else if (y >= height - RADIUS)
stepY + -DELTA;
x = x + stepX;
y = y + stepY;
}
closegraph();
system("PAUSE");
return EXIT_SUCCESS;
}
#include <iostream>
#include <graphics.h>
#define TRUE 1
using namespace std;
int main(void)
{
const int PAUSE=20;
const int DELTA=5;
const int RADIUS=30;
const int COLOR=RED;
int width,height,x,y,stepX,stepY;
width = getmaxwidth();
height = getmaxheight();
initwindow(width, height,"Pong - close window to quit",0,0,TRUE);
x = RADIUS;
y = RADIUS;
stepX = DELTA;
stepY = DELTA;
while (TRUE){
clearviewport();
setfillstyle(SOLID_FILL, COLOR);
fillellipse(x, y, RADIUS, RADIUS);
swapbuffers();
delay(PAUSE);
if(x<= RADIUS)
stepX = DELTA;
else if (x>= width - RADIUS)
stepX = -DELTA;
if(y <= RADIUS)
stepY = DELTA;
else if (y >= height - RADIUS)
stepY + -DELTA;
x = x + stepX;
y = y + stepY;
}
closegraph();
system("PAUSE");
return EXIT_SUCCESS;
}
Pertemuan 04. E-Book Program to draw a quilt
using namespace std;
int main(void)
{
int x1,y1,x2,y2,stepX,stepY,foreColor,numBars,width, height;
cout<<"Enter number of bars> ";
cin>>numBars;
width = getmaxwidth();
height = getmaxheight();
initwindow(width, height, "Quilt");
x1=0;
x2=width;
y1=0;
y2=height;
stepX = width/(2 * numBars);
stepX = height/(2 * numBars);
for (int i= 1; i<= numBars; ++i){
foreColor= i%16;
setcolor(foreColor);
setfillstyle(i%12, foreColor);
bar(x1, y1, x2, y2);
x1 = x1 + stepX;
y1 = y1 + stepY;
x2 = x2 - stepX;
y2 = y2 - stepY;
}
Pertemuan 04. E-Book Finding a Function Root Using the Bisection Method
#include <cstdlib>
#include <iostream>
#include <math.h>
#define FALSE 0
#define TRUE 1
#define NO_ROOT -99999.0
double bisect(double x_left,double x_right, double epsilon, double f( double farg));
double g(double x);
double h(double x);
using namespace std;
int main(void)
{
double x_left,x_right,epsilon,root;
cout<<"Enter interval endpoints> ";
cin>>x_left>>x_right;
cout<<"Enter tolerance> ";
cin>>epsilon;
cout<<"Function g"<<endl;
root = bisect(x_left,x_right,epsilon,g);
if(root != NO_ROOT)
cout<<"g ="<<root<<g(root)<<endl<<endl;
cout<<"Function h"<<endl;
root= bisect(x_left,x_right,epsilon,h);
if(root != NO_ROOT)
cout<<"h =n"<<root<<h(root);
return(0);
}
double bisect(double x_left, double x_right, double epsilon, double f(double farg))
{
double x_mid, f_left, f_mid, f_right;
int root_found;
f_left = f(x_left);
f_right = f(x_right);
if(f_left * f_right>0){
cout<<"May be no root in "<<x_left<<x_right<<endl;
return NO_ROOT;
}
root_found = FALSE;
while(fabs(x_right - x_left) > epsilon && !root_found)
{
x_mid = (x_left + x_right)/2.0;
f_mid = f(x_mid);
if(f_mid == 0.0){
root_found = TRUE;
}
else if (f_left * f_mid < 0.0) {
x_right = x_mid;
}
else {
x_left + x_mid;
}
if(root_found)
cout<<"Root found at x = ,midpoint of "<<x_mid<<x_right<<endl;
else
cout<<"New interval is "<<x_left<<x_right;
}
return ((x_left + x_right)/2.0);
}
double g(double x) {
return (5 * pow(x, 3.0) -2 *pow(x,2.0)+3);
}
double h(double x){
return(pow(x, 4.0) - 3 * pow(x,2.0) - 8);
};
Pertemuan 04. E-Book Program to Monitor Gasoline Storage Tank
#include <cstdlib>
#include <iostream>
#define capacity 80000.0
#define min_pct 10
#define gals_per_brl 42.0
double monitor_gas(double min_supplay,double start_supply);
using namespace std;
int main(void)
{
double start_supply, min_supply, current;
min_supply = min_pct/100.0*capacity;
cout<<"Number of barrels currently in tank> ";
cin>>start_supply;
current = monitor_gas(min_supply,start_supply);
cout<<"only barrels are left."<<current<<endl<<endl;
cout<<"*** WARNING ***"<<endl;
cout<<"Available supply is less than percent of"<<min_pct<<"tank's "<<endl;
cout<<capacity<<"barrel capacity."<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
double monitor_gas(double min_supply, double start_supply)
{
double remov_gals, remov_brls,current;
for (current = start_supply; current >= min_supply; current -= remov_brls){
cout<<"barrels are available."<<current<<endl<<endl;
cout<<"Enter number of gallons removed> ";
cin>>remov_gals;
remov_brls = remov_gals/gals_per_brl;
cout<<"After removal of"<<remov_gals<<" gallone {"<<remov_brls<<" barrels)"<<endl;
}
return (current);
}
#include <iostream>
#define capacity 80000.0
#define min_pct 10
#define gals_per_brl 42.0
double monitor_gas(double min_supplay,double start_supply);
using namespace std;
int main(void)
{
double start_supply, min_supply, current;
min_supply = min_pct/100.0*capacity;
cout<<"Number of barrels currently in tank> ";
cin>>start_supply;
current = monitor_gas(min_supply,start_supply);
cout<<"only barrels are left."<<current<<endl<<endl;
cout<<"*** WARNING ***"<<endl;
cout<<"Available supply is less than percent of"<<min_pct<<"tank's "<<endl;
cout<<capacity<<"barrel capacity."<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
double monitor_gas(double min_supply, double start_supply)
{
double remov_gals, remov_brls,current;
for (current = start_supply; current >= min_supply; current -= remov_brls){
cout<<"barrels are available."<<current<<endl<<endl;
cout<<"Enter number of gallons removed> ";
cin>>remov_gals;
remov_brls = remov_gals/gals_per_brl;
cout<<"After removal of"<<remov_gals<<" gallone {"<<remov_brls<<" barrels)"<<endl;
}
return (current);
}
BAHASA C++ RUN
Pertemuan 04. E-Book Displaying a Celsius-to-Fahrenheit Conversion Table
#include <cstdlib>
#include <iostream>
#define cbegin 10
#define climit -5
#define cstep 5
using namespace std;
int main(int argc, char *argv[])
{
int celcius;
double fahrenheit;
cout<<"Celcius \tFahrenheit"<<endl<<endl;
for (celcius=cbegin;celcius>=climit;celcius -= cstep) {
fahrenheit= 1.8*celcius+32.0;
cout<<"celcius "<<celcius<<"\tfahrenheit "<<fahrenheit<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
#include <iostream>
#define cbegin 10
#define climit -5
#define cstep 5
using namespace std;
int main(int argc, char *argv[])
{
int celcius;
double fahrenheit;
cout<<"Celcius \tFahrenheit"<<endl<<endl;
for (celcius=cbegin;celcius>=climit;celcius -= cstep) {
fahrenheit= 1.8*celcius+32.0;
cout<<"celcius "<<celcius<<"\tfahrenheit "<<fahrenheit<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
BAHASA C++ RUN
Pertemuan 04. E-Book Function to Compute Factorial
#include <cstdlib>
#include <iostream>
using namespace std;
int faktorial(int n) {
using namespace std;
int faktorial(int n) {
int i, product=1;
for (i=n; i>1; --i) {
product=product*i;
}
return product;
}
int main(int argc, char *argv[])
{
int n;
cout<<"Masukkan nilai= ";
cin>> n ;
cout<< faktorial(n) ;
system("PAUSE");
return EXIT_SUCCESS;
}
for (i=n; i>1; --i) {
product=product*i;
}
return product;
}
int main(int argc, char *argv[])
{
int n;
cout<<"Masukkan nilai= ";
cin>> n ;
cout<< faktorial(n) ;
system("PAUSE");
return EXIT_SUCCESS;
}
-BAHASA C++ RUN
Pertemuan 04. E-book Using a for Statement in a Counting Loop
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int count_emp, number_emp;
float rate,pay,total_pay=0.0,hours;
cout<<"Enter number of employees> ";
cin>>number_emp;
for (count_emp=0;count_emp < number_emp; count_emp += 1) {
cout<<"Hours> ";
cin>>hours;
cout<<"Rate> $";
cin>>rate;
pay= hours*rate;
cout<<"Pay is= $ "<< pay<<endl;
total_pay=total_pay+pay;
}
cout<<"All employees processed"<<endl;
cout<<"Total payroll is " <<total_pay<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
RUN :
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int count_emp, number_emp;
float rate,pay,total_pay=0.0,hours;
cout<<"Enter number of employees> ";
cin>>number_emp;
for (count_emp=0;count_emp < number_emp; count_emp += 1) {
cout<<"Hours> ";
cin>>hours;
cout<<"Rate> $";
cin>>rate;
pay= hours*rate;
cout<<"Pay is= $ "<< pay<<endl;
total_pay=total_pay+pay;
}
cout<<"All employees processed"<<endl;
cout<<"Total payroll is " <<total_pay<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
RUN :
Pertemuan 04. Ebook Program to Compute Company Payroll
include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int count_emp=0, number_emp;
double rate,pay,total_pay=0,hours;
cout<<"Enter number of employees> ";
cin>>number_emp;
while(count_emp<number_emp){
cout<<"Karyawan "<<count_emp+1<<endl;
cout<<"Hours> ";
cin>>hours;
cout<<"Rate> ";
cin>>rate;
pay= hours*rate;
cout<<"Pay is= $ "<< pay<<endl;
total_pay=total_pay+pay;
count_emp=count_emp+1;
}
cout<<"All employees processed"<<endl;
cout<<"Total payroll is " <<total_pay<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int count_emp=0, number_emp;
double rate,pay,total_pay=0,hours;
cout<<"Enter number of employees> ";
cin>>number_emp;
while(count_emp<number_emp){
cout<<"Karyawan "<<count_emp+1<<endl;
cout<<"Hours> ";
cin>>hours;
cout<<"Rate> ";
cin>>rate;
pay= hours*rate;
cout<<"Pay is= $ "<< pay<<endl;
total_pay=total_pay+pay;
count_emp=count_emp+1;
}
cout<<"All employees processed"<<endl;
cout<<"Total payroll is " <<total_pay<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Bahasa c++
Pertemuan 04. Ebook Program Fragment With a Loop
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int count_emp=0,hours;
float rate,pay;
while(count_emp<7){
cout<<"Hours> ";
cin>>hours;
cout<<"Rate> ";
cin>>rate;
pay= hours*rate;
cout<<"Pay is= $ "<< pay <<endl;
count_emp=count_emp+1;
} cout<<"All employees processed"<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int count_emp=0,hours;
float rate,pay;
while(count_emp<7){
cout<<"Hours> ";
cin>>hours;
cout<<"Rate> ";
cin>>rate;
pay= hours*rate;
cout<<"Pay is= $ "<< pay <<endl;
count_emp=count_emp+1;
} cout<<"All employees processed"<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Sabtu, 22 Maret 2014
Pertemuan 04. Bilangan Acak
Algoritma
dengan mengunakan
metode linear congruential untuk menghasilkan satu set seragam nomor
pseudo-random atau bilangan acak
A. Analisis
Input : R (masukkan angka secara
acak)
Proses : z yang mengalami proses
(a*x)+c%m
Output : menampilkan hasil bilangan
acak
B. Algoritma
1. Deklarasi
R : masukkan angka yang secara acak ibarat
untuk pendeklarasian
2. Deskripsi
Read (R)
Write (menghasilkan bilangan acak)
C. Flowchart
Langganan:
Postingan (Atom)