You can replace this text by going to "Layout" and then "Page Elements" section. Edit " About "

07/04/14

1. SAP Factorial
#include <iostream>
#include <string>

using namespace std;
int main()
{
   int n;
   int i;
   int faktorial;

   cout<<"masukan Angka"<<endl;
   cin >> n;
   faktorial =1;
   i =1;
   while (!(i>n))
   {
      faktorial =faktorial*i;
      i =i+1;
   }
   cout<<"faktorial"<<endl;
   return 0;
}
2. SAP Pangkat
#include <iostream>
#include <string>

using namespace std;
int main()
{
   int x;
   int y;
   int i;
   int pangkat;

   cout<<"masukan bilangan"<<endl;
   cin >> x;
   cout<<"masukan bilangan"<<endl;
   cin >> y;
   pangkat =1;
   i =1;
   while (!(i>y))
   {
      pangkat =pangkat*x;
      i =i+1;
   }
   cout << "pangkat" << endl;
   return 0;
}
3. SAP Matriks
4. SAP Loop
#include <iostream>
#include <string>

using namespace std;
int main()
{
   int i;
   int jumlah;

   i =1;
   jumlah =0;
   while (!(i>100))
   {
      if (i % 3==0)
      {
         if (i % 5==0)
         {
            jumlah =jumlah+1;
            cout<<"i"<<endl;         }
         else
         {
         }
      }
      else
      {
      }
      i =i+1;
   }
   cout <<"Jumlah bilangan = +jumlah"<< endl;
   return 0;
}
5. SAP Fibonasi alternatif
#include <iostream>
#include <string>

using namespace std;
int main()
{
   int x;
   int a;
   int b;
   int c;
   int i;

   cout<<"Input number"<<endl;
   cin >> x;
   a =0;
   b =1;
   c =1;
   i =1;
   while (!(i>x))
   {
      cout << c << endl;      c =b+a;
      a =b;
      b =c;
      i =i+1;
   }

   return 0;
}
6. SAP GUR
#include <iostream>
#include <string>

using namespace std;
int main()
{
   int hasil;
   int n;
   int bil;

   cout<<"Masukan bilangan faktorial !"<<endl;
   cin >> bil;
   hasil =1;
   n =1;

   return 0;
}

31/03/14

1. Apa saja yang sudah kami peroleh dari pertemuan keempat ?
  • Memasuki materi tentang subprogram.
  • Mempelajari bagaimana menyelesaikan sigma (penjumlahan).
  • Kuis kelompok (di kumpul jam 8 maks)

2. Apa yang belum di pahami di pertemuan keempat ?
  • Belum mengerti tentang integer factorial
3. Usaha yang di tempuh untuk No.2 ?
  • Bertanya dan mendiskusikan bareng bersama teman
  • Jika masih belum mengerti, bertanya kepada dosen di pertemuan selanjutnya
4. Waktu Belajar
    :[750' ngerjain kuis, ngeposting tugas.

    24/03/14

    • 5.11 Figure 5.23 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;
    }
    • 5.2 Figure 5.2 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;
    }
    • 5.3 Figure 5.4 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;
    }
    • 5.4 Figure 5.5 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;
    }
    • 5.4 Figure 5.5 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;
    }
    • 5.4 Figure 5.8 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;
    }
    • 5.5 Figure 5.9 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);
                     }
    • 5.6 Figure 5.10 Sentinel-Controlled while Loop
    #include <cstdlib>
    #include <iostream>
    #define sentinel -99

    using namespace std;

    int main(int argc, char *argv[])
    {
        int sum=0, score;
       
        cout<<"Enter first score(or "<< sentinel<<" to quit)> ";
        cin>>score;
        while (score != sentinel) {
              sum += score;
              cout<<"Enter next score ("<<sentinel<<"to quit)> ";
              cin>>score;
              }
        cout<<"Sum of exam scores is "<<sum<<endl;
       
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    • 5.6 Figure 5.11 Batch Version of Sum of Exam Scores Program
    #include <cstdlib>
    #include <iostream>
    #include <stdio.h>
    using namespace std;

    int main(void)
    {
        int sum=0,score,input_status;
       
        cout<<"Score=";

        cin>>score; return input_status;
       
       
        while (input_status != EOF) {
              cout<<"     "<<score<<endl;
              sum+=score;
                cin>>score; return input_status;
              }
       
        cout<<"Sum of exam scores is "<<sum;

        system("PAUSE");
        return EXIT_SUCCESS;
    }
    • 5.7 Figure 5.12  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;
    }
    • 5.7 Figure 5.13  Nested Counting Loop Program
    #include <cstdlib>
    #include <iostream>

    using namespace std;

    int main(void)
    {
        int i,j;
        cout<<"\ti\tj"<<endl;
       
                    for (i=1;i<4;++i){
                        cout<<"Outer      "<<i<<endl;
                    for(j=0;j<i;++j){
                                     cout<<"Inner         "<<j<<endl;
                                     }
                        }
                   
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    • 5.9 Figure 5.16  Using a Function Parameter
    #include <cstdlib>
    #include <iostream>

    using namespace std;

        void evaluate ( double f(double f_arg), double pt1,double pt2,double pt3){
             cout<<" = "<<pt1<<f(pt1);
             cout<<" = "<<pt2<<f(pt2);
             cout<<" = "<<pt3<<f(pt3);
             }
    int main(int argc, char *argv[])
    {

        system("PAUSE");
        return EXIT_SUCCESS;
    }
    • 5.9 Figure 5.19 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);
                  };
    • 5.11 Figure 5.22 Program to draw a quilt
    #include <cstdlib>
    #include <iostream>

    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;
            }
           
        closegraph();
        system("PAUSE");
        return EXIT_SUCCESS;
    }