SOAL LATIAN
No 1.
Algoritma
Deklarasi Subprogram
c,i,j,kali,proses,masuk,hasil=integer
Deskripsi
Void masuk(c[20],b[20])
For(i=1;j<=2;i++) then
For(j=1;j<=3;j++)then
Write(“Vaktor A”)
Write(“Vaktor B”)
Void proses(c[20],b[20])
Write(“Vaktor A”)
For(i=1;j<=2;i++) then
For(j=1;j<=3;j++)then
Write(b)
Write(“Vaktor B”)
For(i=1;j<=2;i++) then
For(j=1;j<=3;j++)then
Write(c)
Write(“Vaktor C”)
For(i=1;j<=2;i++) then
For(j=1;j<=3;j++)then
Hasil<-b+c
Write(hasil)
Write(“Vaktor Hasil
Kali”)
For(i=1;j<=2;i++) then
For(j=1;j<=3;j++)then
Kali<-b*hasil
Write(Kali)
Write(“Banyak Elemen”)
Int main()
Write(“Menghitung
Vaktor”)
Masuk(b,c)
Proses(b,c,hasil,kali)
Dev C++
source code :
#include <iostream>
#include <windows.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void masuk(int c[20],int b[20]){
for (int i=1;i<=2;i++){
for (int j=1;j<=3;j++){
cout<<"Vaktor A "<<i<<","<<j<<" =";cin>>b[i,j];
cout<<"Vaktor B "<<i<<","<<j<<" =";cin>>c[i,j];
}
}
system("cls");
}
void proses(int b[20],int c[20],int hasil[20],int kali[20]){
cout<<"Vaktor A"<<endl;
for(int i=1;i<=2;i++){
for(int j=1;j<=3;j++){
cout<<b[i,j]<<" ";
}
}
cout<<"\n\nVaktor B"<<endl;
for(int i=1;i<=2;i++){
for(int j=1;j<=3;j++){
cout<<c[i,j]<<" ";
}
}
cout<<"\n\nVektor C"<<endl;
for (int i=1;i<=2;i++){
for (int j=1;j<=3;j++){
hasil[i,j]=b[i,j]+c[i,j];
cout<<hasil[i,j]<<" ";
}
}
cout<<"\n\nVaktor Hasil Kali"<<endl;
for (int i=1;i<=2;i++){
for (int j=1;j<=3;j++){
kali[i,j]=b[i,j]*hasil[i,j];
cout<<kali[i,j]<<" ";
}
}
cout<<"\n\nBanyak Elemen ="<<12;
}
int main(int argc, char** argv) {
int hasil[20];
int kali[20];
int b[20];
int c[20];
cout<<"Menghitung faktor"<<endl;
masuk(b,c);
proses(b,c,hasil,kali);
return 0;
}
outputnya :
Raptor
KASUS-KASUS
2
6.2
Algoritma
Deklarasi :
N,a[i] : integer(input)
Std : integer (output)
Deskripsi :
A[20] ß
0
Iß1
Jumlahß0
Rataß0
For (i>n)
jumlahßjumlah+a[i]
ißi+1
rataßjumlah/n
stdß0
jß1
For (j>n)
jumlahßjumlah+sqrt((((a[i]-rata)*(a[i]-rata)))
jßj+1
stdßsqrt(jumlah/(n-1))
Dev C++
source code :
#include <iostream>
#include <math.h>
#include <conio.h>
using namespace std;
class HitungStatistik {
friend ostream& operator<<(ostream&, HitungStatistik&);
friend istream& operator>>(istream&, HitungStatistik&);
public:
float rata();
float STD();
private:
long sqrt(int n) { return(n*n); }
int n;
int A[20];
};
istream& operator>>(istream& in, HitungStatistik& a)
{
cout << "Banyaknya data : ";
cin >> a.n;
for (int i = 0; i < a.n; i++)
{
cout << "Masukkan data ke- : " << i+1 << " > ";
cin >> a.A[i];
}
return in;
}
float HitungStatistik::rata()
{
float total=0;
for (int i = 0; i<n; i++) total = total + A[i];
return(total/n);
}
float HitungStatistik::STD ()
{ float rerata = rata();
float jumlah=0.0;
for (int i = 0; i<n; i++)
jumlah = jumlah + sqrt(A[i] - rerata);
return(sqrt (jumlah/(n-1)));
}
ostream& operator<<(ostream& out, HitungStatistik& a) {
cout << "Rata-rata dari " << a.n;
cout<< " bilangan adalah : " << a.rata() << endl;
cout << "Standar deviasi= " << a.STD();
return out;
}
int main() {
HitungStatistik run;
cin >> run;
cout << run;
return 0;
}
outputnya :
Raptor
6.5
Algoritma
Deklarasi :
N,a[i] : integer (input)
Item : integer (output)
Deskrispsi :
A[20]ß0
F[11] ß
0
Maks ß
0
I ß
1
For (i>n)
Ißi+1
Maks ß
f[1]
Itemß1
For (j>n)
F[j]>maks
Maksßf[j]
Itemßi
source code :
#include <iostream>
#include <math.h>
using namespace std;
class HitungStatistik {
friend ostream& operator<<(ostream&, HitungStatistik&);
friend istream& operator>>(istream&, HitungStatistik&);
public:
HitungStatistik();
void hitung_modus();
private:
void maksimum();
void frekuensi();
int maks, item;
int n;
int A[20];
int f[11];
};
HitungStatistik::HitungStatistik()
{ for (int i=0; i<20; i++) f[i] = 0; }
istream& operator>>(istream& in, HitungStatistik& a) {
cout << "Banyaknya data : ";
cin >> a.n;
for (int i = 0; i < a.n; i++) {
cout << "Data ke- : " << i+1 << " > ";
cin >> a.A[i];
}
return in;
}
void HitungStatistik::maksimum()
{
maks = f[0];
item = 1;
for (int i=0; i<n; i++)
if (f[i] > maks) {
maks = f[i];
item = i;
}
cout << "Modus = " << item;
}
void HitungStatistik::frekuensi()
{
for (int i=1; i<n; i++) ++f[A[i]];
}
void HitungStatistik::hitung_modus() {
cout << "Frekuensi running\n";
frekuensi();
maksimum();
}
ostream& operator<<(ostream& out, HitungStatistik& a) {
cout << "Mulai ...\n";
a.hitung_modus();
cout << "Nilai modus : " << a.item;
return out;
}
main() {
HitungStatistik run;
cout << run;
return 0;
}
outputnya:
Raptor
Untuk Latian Diktat silahkan kunjungi link dibawah ini :
no 2 Ela Dwi Anggraini
no 3 Agus Prasetyo
Untuk Kasus Diktat silahkan kunjungi link dibawah ini :
no 1,6,7 : agus prasetyo
no 3 dan 4 : ela dwi anggraini
Tidak ada komentar:
Posting Komentar