Minggu, 17 April 2016

[Ebook] How to slove

4.1
C++ nya : 
·         Array A yang bertipe integer diisi dengan nilai {5, 10, 6, 0, 4}
·         Array B yang bertipe integer diisi dengan nilai {0, 0, 0, 0, 0}
·         Baris perulangan untuk menampilkan nilai dari array A.
·         Proses untuk mengisi array B dengan nilai yang dibalik.
·         Menampilkan output nilai dari array B.
C++""""'

#include <iostream>
#include <stdlib.h>
using namespace std;
int main(void)
{
       int A[5] = {5, 10, 6, 0, 4};
       int B[5] = {0, 0, 0, 0, 0};
       int i;
       // Nilai array A integer
       cout<<"Nilai dari array A: ";
       for(i=0; i<5; i++){
              cout<<A[i];
       }
       //
       for(i=0; i<5; i++){
              B[4-i] = A[i];
       }
       // Output
       cout<<"\n";
       cout<<"Nilai dari array B hasil dari membalikkan nilai array A :\n";
       for(i=0; i<5; i++){
              cout<<B[i];
       }
       cout<<"\n";
      
       system("pause");
       return(0);
}

4.2

Deklarasi banyak,i,x
array int nilai [20]
deklarasi string nama

inputkan banyak mahasiswa
for (int i=1;i<=banyak;i++){
input nama;
input nilai mahasiswa i
if (nilai[20]>=80 || nilai[20]<=100)
ceta nilai = A
else if (nilai[20]>=60 || nilai[20]<80)
cetak nilai = B
else if (nilai[20]>=40 || nilai[20]<60)
cetak nilai = C
else if (nilai[20]>=20 || nilai[20]<40)
cetak nilai = D
else if (nilai[20]>=0 || nilai[20]<20)
cetak nilai = E 
end for
C++"""""

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) { 
 int banyak, i,x;
 int nilai[20];
 string nama;
 cout<<"Masukan Banyak Mahasiswa :"; cin>>banyak;
 
 for (int i=1;i<=banyak;i++){
  cout<<"nama Mahasiswa :";cin>>nama;
  cout<<"Masukan nilai  :";cin>>nilai[20];
  
  if (nilai[20]>=80 || nilai[20]<=100){
   cout<<"\n Nilai "<<nilai[20]<<"Adalah A";
  }
  else if (nilai[20]>=60 || nilai[20]<80){
   cout<<"\n Nilai "<<nilai[20]<<"Adalah B";
  }
  else if (nilai[20]>=40 || nilai[20]<60){
   cout<<"\n Nilai "<<nilai[20]<<"Adalah C";
  }
  else if (nilai[20]>=20 || nilai[20]<40){
   cout<<"\n Nilai "<<nilai[20]<<"Adalah D";
  }
  else if (nilai[20]>=0 || nilai[20]<20){
   cout<<"\n Nilai "<<nilai[20]<<"Adalah E";
  }
  cout<<"\n========================================================================\n";
 }
 return 0;
}

4.3
Mencari Laba Usaha
Aspek perencanaan :
    Proyek bertujuan untuk mempermudah mencari laba usaha berdasarkan jenis-jenis laba yang ada .
Jenis-jenis laba usaha :
·         Laba kotor
·         Laba usaha
·         Laba sebelum pajak
·         Laba bersih
Program yang di rancang berdasarkan keluhan klien prodi management dan di kerjakan oleh 3 orang anggota kelompok menggunkan dev c++ dan raptor berdasarkan rumus-rumus pencarian laba
·         Laba kotor rumusnya                : penjualan bersih - harga pokok
·         Laba usaha rumusnya               : laba kotor - beban usaha
·         Laba sebelum pajak rumusnya : laba usaha + pendapatan di luar usaha - beban di luar usaha
·         Laba bersih rumusnya              : laba sebelum pajak – pajak (15%)
Aspek teknis :
      Program yang di rancang di harapkan dapat membantu klien dalam mencari laba usaha untuk tugas-tugas kuliah dan juga dapat membantu siapa saja yang membutuhkan sehingga kegunaaan program yang telah kami buat dapat digunakan secara maksimal

C++"""
#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;


int main(int argc, char *argv[])
{
 int a,b,c,d,bersih,pokok,pajak;
 int pendapatan,beban;
 int laba_usaha,laba_kotor,laba_sebelum_pajak,laba_bersih;
 cout<<"|====================================================|\n";
 cout<<"|                                                    |\n";
 cout<<"|          Program Untuk Mencari Laba Usaha          |\n";
 cout<<"|                                                    |\n";
 cout<<"|====================================================|\n";
 cout<<"| Mencari Pendapatan                                 |\n";
 cout<<"|----------------------------------------------------|\n";
 cout<<"| Masukkan pendapatan usaha         : ";cin>>a;
 cout<<"| Masukkan pendapatan di luar usaha : ";cin>>b;
 pendapatan=a+b;
 cout<<"| Jumlah pendapatan usaha           : "<<pendapatan<<"\n";
 cout<<"|----------------------------------------------------|\n";
 cout<<"| Mencari Beban                                      |\n";
 cout<<"|----------------------------------------------------|\n";
 cout<<"| Masukkan beban usaha \t\t: ";cin>>c;
 cout<<"| Masukkan beban di luar usaha  : ";cin>>d;
 beban=c+d;
 cout<<"| Jumlah beban \t\t\t: "<<beban<<"\n";
 cout<<"|----------------------------------------------------|\n";
 cout<<"| Mencari Laba                                       |\n";
 cout<<"|----------------------------------------------------|\n";
 cout<<"| Masukkan penjualan bersih     : ";cin>>bersih;
 cout<<"| Masukkan harga pokok    \t: ";cin>>pokok;
 cout<<"| Masukkan pajak     \t\t: ";cin>>pajak;
 cout<<"|----------------------------------------------------|\n";
 cout<<"| Hasil Laba                                         |\n";
 cout<<"|----------------------------------------------------|\n";
 laba_kotor=bersih-pokok;
 cout<<"| Laba Kotor \t\t: "<<laba_kotor<<"\n";
 laba_usaha=laba_kotor-c;
 cout<<"| Laba Usaha \t\t: "<<laba_usaha<<"\n";
 laba_sebelum_pajak=laba_usaha+(b-d);
 cout<<"| Laba Sebelum Usaha    : "<<laba_sebelum_pajak<<"\n";
 laba_bersih=laba_sebelum_pajak-(pajak*15/100);
 cout<<"| Laba Bersih \t\t: "<<laba_bersih<<"\n";
 cout<<"|====================================================|\n";
 
 system("pause");
 return 0;
}


 
4.4

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
 int a[20],n;
 cout<<"Batas : ";
 cin>>n;
 
 for (int i=0;i<n;i++){
 cout<<"Data : ";
 cin>>a[i];
}
 for (int i=0;i<n;i++){
 if(a[i]==a[i+1])
 cout<<a[i];
 else if(a[i-1]==a[i])
 cout<<"";
 else if(a[i]==a[i+2])
 cout<<a[i];
 else if(a[i-2]==a[i])
 cout<<"";
 else if(a[i]==a[i+3])
 cout<<a[i];
 else if(a[i-3]==a[i])
 cout<<"";
 else if(a[i]==a[i+4])
 cout<<a[i];
 else if(a[i-4]==a[i])
 cout<<"";
 else if(a[i]==a[i+5])
 cout<<a[i];
 else if(a[i-5]==a[i])
 cout<<"";
 
 else 
 cout<<a[i];
}

/* for (int i=0;i<n;i++){ 
  cout<<a[i]<<" ";  
 
 
 }*/
 
 return 0;
}



4.5

Dibab ini merupakan perulangan menggunakan for untuk mencari angka maksimal, tetap koding kawan2 
CPP 4.5.1 

#include <iostream>
#include <stdio.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

int main() {  

    int n, *arr, onee = 0, twoo, threee, total = 0, maxx = -1, temp_maxx;

    cin >> n;
    arr = new int[n];

    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        total += arr[i];
    }

    // O(n^2) is the following

    for (int i = 1; i < n - 1; i++) {
        onee += arr[i - 1];
        twoo = 0;
        for (int j = i + 1; j < n; j++) {
            twoo += arr[j - 1];
            threee = total - twoo - onee;
            temp_maxx = max(max(onee, twoo), threee);
            if ((temp_maxx < maxx) || (maxx == -1))
                maxx = temp_maxx;
        }
    }

    cout << maxx;

    return 0;
}
CPP 4.5.2
#include <iostream>
#include <stdio.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

int main() {  

    int n, *arr, onee = 0, twoo, threee, total = 0, maxx = -1, temp_maxx;

    cin >> n;
    arr = new int[n];

    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        total += arr[i];
    }

    // O(n^2) is the following

    for (int i = 1; i < n - 1; i++) {
        onee += arr[i - 1];
        twoo = 0;
        for (int j = i + 1; j < n; j++) {
            twoo += arr[j - 1];
            threee = total - twoo - onee;
            temp_maxx = max(max(onee, twoo), threee);
            if ((temp_maxx < maxx) || (maxx == -1))
                maxx = temp_maxx;
        }
    }

    cout << maxx;

    return 0;
}

4.6

Disini kita memiliki 2 versi kodingan menggunakan perulangan dan percabangan

#include <stdio.h>
#include<iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

main() {
 int x;
 int y;
 cout<<"\nMasukkan bilangan ke- 1 :";
 cin>>x;
 cout<<"Masukkan bilangan ke-2 :";
 cin>>y;
 if(x>y){
 
 cout<<"lebih besar dari pada\n\n ";cin>>x,y;
}else if(x=y){
 cout<<"sama besar dengan\n\n";cin>>x,y;

}else{
 cout<<"lebih kecil dari pada\n\n";cin>>x,y;
}
 
 return 0;
}
CPP 2 
#include<iostream>  
#include<iomanip>  
  
using namespace std;  
  
main()  
{  
    int byk, htg=1, tmp, data[15];  
  
      cout << "Banyak data : ";  
      cin >> byk;  
  
      for(int i=0; i<byk; i++)  
      {  
      cout << "Masukkan data ke-"<<i<<" : ";  
      cin >> data[i];  
      }  
     
    endl(cout);  
      
   cout<<"data diurut (Naik): ";  
      for(int a=0; a<byk; a++)  
      {  
            for(int b=byk-1; b>=a; b--)  
            {  
             if(data[b]<data[b-1])  
             {  
             tmp = data[b];  
             data[b] = data[b-1];  
             data[b-1] = tmp;  
             }  
  
            }  
            cout<<data[a]<<" ";  
        }  
  
        cout<<"\nData diurut (Turun) : ";  
  
       for(int i=byk-1; i<=0; i--)  
       {  
            for(int h=0; h<i; h++)  
            {  
                if(data[h] > data[h+1])  
                {  
                    tmp = data[h];  
                    data[h] = data[h+1];  
                    data[h+1] = tmp;  
                }  
            }  
            cout<<data[i]<<" ";  
       }  
       cout<<"\n"<<endl;  
  
    return 0;  
}          






Related Articles

0 komentar:

Posting Komentar

Diberdayakan oleh Blogger.