Minggu, 16 Desember 2012
penggunaan string pada pascal
uses crt ;
var
NilaiString : string [10];
NilaiReal : real;
PosisiSalah : integer;
begin
clrscr;
NilaiString :='300.45';
val(NilaiString,NilaiReal,PosisiSalah);
writeln('Nilai String : ',NilaiString);
writeln('NIlai Real : ',NilaiReal);
writeln('Posisi Salah : ',PosisiSalah);
readkey;
end.
penggunaan array pada c++
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char nama[20][10];
char npm[8][10];
char kelas[5][10];
int jml;
cout<<"Masukkan jumlah record:";
cin>>jml;
clrscr();
for(int i=0;i<=jml;i++)
{
cout<<"\n input data ke-"<< i <<":";
cout<<"\n nama ke-"<<i<<":";
cin>>nama[i];
cout<<"\n npm ke-"<<i<<":";
cin>>npm[i];
cout<<"\n kelas ke-"<<i<<":";
cin>>kelas[i];
}
for(int j=0;j<=jml;j++)
{
cout<<"\n input data ke-"<< j;
cout<<"\n nama : "<< nama [j];
cout<<"\n npm : "<< npm [j];
cout<<"\n kelas : "<< kelas [j];
cout<<"\n================================\n";
}
getch();
}
penggunaan procedure pada c++
#include<iostream.h>
void volume_limas()
{
double p, l, t;
cout<<"Volume limas segi empat"<<endl;
cout<<"Masukkan panjang: ";
cin>>p;
cout<<"Masukkan lebar: ";
cin>>l;
cout<<"Masukkan tinggi: ";
cin>>t;
cout<<"Volume limas segi empat: "<<p*l*t/3<<endl;
}
void volume_kerucut()
{
double r, t;
cout<<"Volume kerucut"<<endl;
cout<<"Masukkan jari2: ";
cin>>r;
cout<<"Masukkan t: ";
cin>>t;
cout<<"Volume kerucut: "<<3.14*r*r*t/3<<endl;
}
void volume_bola()
{
double r;
cout<<"Volume bola"<<endl;
cout<<"Masukkan nilai r= ";
cin>>r;
cout<<"Volume bola= "<<4*3.14*r*r*r/3<<endl;
}
int main()
{
volume_limas();
volume_kerucut();
volume_bola();
return 0;
}
penggunaan string pada c++
#include <iostream.h>//pemanggilan cin
#include <conio.h>//pemanggilan getch
#include <string.h>//untuk dapat menggunakan string
int main(){
char nama_1[20];
char nama_2[20];
//input string
cout<<"Masukan nama depan : ";
cin.getline(nama_1,sizeof(nama_1));
cout<<"Masukan nama belakang : ";
cin.getline(nama_2,sizeof(nama_2));
cout<<"Nama depan : "<<nama_1<<endl;
cout<<"Nama belakang : "<<nama_2<<endl<<endl;
getch ();
}
penggunaan fungsi pada c++
#include<iostream.h>
#include<conio.h>
void gaya(double m, double a); //prototype function
void main() //main function
{
double m,a;
cout<<"Massa : "; cin>>m;
cout<<"percepatan : "; cin>>a;
cout<<"F : ";
gaya(m,a); //parameter aktual
getch();
}
void gaya(double m, double a) //function definition
{
double hasil;
hasil=m*a;
cout<<hasil;
}
Sabtu, 01 Desember 2012
CONTOH PENGGUNAAN ARRAY PADA PASCAL
program array_warnet;
uses crt;
const max=50;
type
Twarnet = record
NAMA : string [25] ;
KOMPI : string [8] ;
JAM : array [1..2] of real;
end;
Tkumpulanwarnet = array[1..max] of Twarnet;
var
A : Tkumpulanwarnet;
i,N: Integer;
NA: real;
durasi:real;
begin
clrscr;
writeln ('=====> PROGRAM DATA WARNET <=====');
writeln ('---------------------------------');
write ('Masukan Data yg ingin diisikan :');
readln(N);
writeln ;
writeln ('=+=+ MASUKAN DATA ANDA +=+= ');
writeln ('---------------------------');
for i:= 1 to N do begin
writeln('Data Pengunjung ke-',i);
with A[i] do begin
write ('NAMA :'); readln(NAMA);
write ('Komputer : KE-'); readln(KOMPI);
write ('Mulai Jam : '); readln(JAM[1]);
write ('Selsai Jam : '); readln(JAM[2]);
end;
writeln;
end;
writeln('Menampilkan Data');
writeln('------------------------------------');
writeln('NAMA':5,'':2, 'KOMPI':2, '':2,'BAYAR');
writeln('------------------------------------');
for i:=1 to N do begin
with A[i] do begin
NA:= (JAM[1]*JAM[2])/2 ;
write(NAMA:5, '':2, KOMPI:2, '' :3, NA:0:3);
end;
writeln;
end;
readln;
end.
CONTOH PENGGUNAAN ARRAY PADA C++
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
int n,i,harga,bayar=0,totalbayar,total[100],banyak[100]; //contoh ARRAY
float pajak;
char jenis[100];
cout << "Banyak Jenis = ";
cin>>n;
for (i=0;i<n;i++)
{
cout<<"Jenis ke-"<<(i+1) << endl;
cout<<"Jenis Potong [D/P/S] : ";
cin>>jenis[i];
cout<<"Banyak Potong : ";
cin>>banyak[i];
cout<<endl;
}
clrscr();
cout<<"-------------------------------------------------------------------------------\n";
cout<<"No\tJenis Potong\tHarga Satuan\tBanyak Barang\tJumlah Harga\n";
cout<<"-------------------------------------------------------------------------------\n";
for(i=0;i<n;i++)
{
cout<<setw(9)<<setiosflags(ios::left)<<(i+1); //Merapihkan Tampilan
cout<<setw(17)<< setiosflags(ios::left);
if(jenis[i]=='D'||jenis[i]=='d')
{
cout<<"Dada";
cout<<setw(17)<< setiosflags(ios::left);
harga=2500;
cout<<"2500";
}
else if (jenis[i]=='P'||jenis [i]=='p')
{
cout<<"Paha";
cout<<setw(17)<< setiosflags(ios::left);
harga=2000;
cout<<"2000";
}
else
{
cout<<"Sayap";
cout<<setw(17)<< setiosflags(ios::left);
harga=1500;
cout<<"1500";
}
cout<<setw(17)<< setiosflags(ios::left)<<banyak[i];
total[i]=banyak[i]*harga;
cout<<total[i];
bayar+=total [i];
cout<<endl ;
}
cout << endl ;
cout <<"--------------------------------------------------------------------------------\n";
cout<< "\t\t\t\t\tJumlah Bayar = "<<bayar<< endl ;
pajak = 0.1*bayar;
cout<< "\t\t\t\t\tPajak = "<<pajak<<endl;
totalbayar = bayar+pajak;
cout<< "\t\t\t\t\tToyal Bayar = "<<totalbayar<<endl<<endl ;
cout<<"----------------------------------Thank You--------------------------------------\n";
cout<<"hafizah program";
}
Langganan:
Postingan (Atom)