kasus 3.2
(tentukan bilangan terbesar antara 3 bilangan bulat)
flowchart :
C++ :
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
string raptor_prompt_variable_zzyz;
int x;
int y;
int z;
int maks;
raptor_prompt_variable_zzyz="masukkan x :";
cout<<raptor_prompt_variable_zzyz<<endl;
cin>>x;
raptor_prompt_variable_zzyz="masukkan y :";
cout<<raptor_prompt_variable_zzyz<<endl;
cin>>y;
raptor_prompt_variable_zzyz="masukkan z :";
cout<<raptor_prompt_variable_zzyz<<endl;
cin>>z;
maks=x;
if(y>maks)
{
if(y>z)
{
cout<<"bil maks :"<<y<<endl;}
else
{
cout<<"bil maks :"<<z<<endl;}
}
else
{
if(z>maks)
}
cout<<"bil maks :"<<z<<endl;
else
{
cout<<"bil maks :"<<x<<endl;}
}
system("PAUSE");
return EXIT_SUCCESS;
}
Kasus 3.3
(carilah akar-akar persamaan kuadrat)
flowchart :
C++ :
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
string raptor_prompt_variable_zzyz;
int A, B, C;
long disk;
float x1, x2;
cout<<"koefisien pangkat 2 :";cin>>A;
cout<<"koefisien pangkat 1 :";cin>>B;
cout<<"koefisien pangkat 0 :";cin>>C;
if(A==0){
cout<<"bukan pers. kuadrat.\n";
cout<<"harga akar ="<<-C/B;}else{
disk =B*B-4*A*C;
if(disk > 0){
x1=-B+sqrt(disk)/(2*A);
x2=-B-sqrt(disk)/(2*A);
cout<<"diskriminan ="<<disk<<endl;
cout<<"x1 ="<<x1<<endl;
cout<<"x2 ="<<x2<<endl;
}else if(disk == 0){
x1=-B/(2*A); x2=x1;
cout<<"x1 ="<<x1<<endl;
cout<<"x2 ="<<x2<<endl;
}else cout<<"akar imajiner";
}
system("PAUSE");
return EXIT_SUCCESS;
}
kasus 3.4
(Mengkonversi Nilai)
flowchart :
C++ :
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
float nilai;
cout<<"KONVERSI NILAI ANGKA MENJADI HURUF\n";
cout<<"^^^^_________^^^^\n";
cout<<"masukkan nilai kamu :";cin>>nilai;
if((100>=nilai)&&(nilai>80))
{
cout<<"Nilai 'A'";
}
else if((79>=nilai)&&(nilai>60))
{
cout<<"Nilai 'B'";
}
else if((59>=nilai)&&(nilai>40))
{
cout<<"Nilai 'C'";
}
else if((39>=nilai)&&(nilai>20))
{cout<<"Nilai 'D'";
}
else if((19>=nilai)&&(nilai>0))
{
cout<<"Nilai 'E'";
}
cout<<endl;
cout<<"Terima Kasih Ya ....^_^"<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
kasus 3.5
(Mengkonversi Hari)
flowchart :
C++ :
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int a;
cout<<"|===============================|"<<endl;
cout<<"|-Program Untuk Menentukan Hari-|"<<endl;
cout<<"|===============================|"<<endl;
cout<<"\n Masukkan bilangan :";cin>>a;
switch(a/1)
{
case 1:
cout<<"\n Hari Senin"<<endl;break;
case 2:
cout<<"\n Hari Selasa"<<endl;break;
case 3:
cout<<"\n Hari Rabu"<<endl;break;
case 4:
cout<<"\n Hari Kamis"<<endl;break;
case 5:
cout<<"\n Hari Jum'at"<<endl;break;
case 6:
cout<<"\n Hari Sabtu"<<endl;break;
default:
cout<<"\n maaf, dalam 1 minggu hanya ada 7 hari"<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
itu lah kasus-kasus yang berhasil saya kerjakan...
:D
Geen opmerkings nie:
Plaas 'n opmerking