Sabtu, 17 April 2010

cpp

Pada sesi kali ini kita belajar bahasa pemrogrraman C++, anda pasti tidak asing lagi mendengar bahasa pemrograman ini. pada contoh-contoh ini saya ambil langsung dari matakulaih yg saya peroleh di kampus saya yaitu Pemrograman BerOrientasi Objek (PBO). Mungkin anda akan bilang dengan nada yg sepele “apaan tuh PBO”. Sssssssssssssssst.... jangan bilang seperti itu, buat saya yg sudah ppernah terjun di software Engginering akan berani ngecam pd perkataan itu, dan akan berani mematahkan ucapan itu dengan “kalo memang anda jurusan sistem informasi atau teknik informatika dll yg setara dengannya..... sungguh sayang sekali uang yg kau ambur2kan dari dulu, anak SI or TI kalau tidak mau kenal dengan PBO menyesalah kau kelak jika anda memang benar2 sampai WISUDA.apakah anda sudah merasa menguasai teknik jaringan atau yg berkaitan dengan hardware...? itu bagus klo jwbannya ya tapi klo tidak.. anda akan merasa bahwa ijasah/titel S.Kom kamu akan setara dan/ tidak jauh beda sengan ijasah SMU/SMEA”. Ingat itu. Langsung aja saya mau memberi Contoh skrip.

Bilangan ganjil menurun :
/*Program for bilangan menurun*/
/*herisokwan tgal wong*/

#include
#include
#include "iostream.h"
main()
{
int a=19;
clrscr();
do
{cout <<=1);
getch();
}



Bilangan ganjil menurun :
/*Program for bilangan ggenap menurun*/
/*herisokwan tgal wong*/

#include
#include
#include "iostream.h"

main()
{
int a;
clrscr();
for(a=10;a>=1;a-=2)
cout <<
#include
#include "iostream.h"

main()
{
int a;
clrscr();
for(a=10;a>=1;--a)
cout <<
#include
#include "iostream.h"
main()
{
int a;
clrscr();
for(a=1;a<=10;a+=2) cout <
#include
#include "iostream.h"
main()
{
int bil=2;
clrscr();
do
{printf("%d",bil);
bil+=2;}
while(bil<=30); getch(); } /*Program for bilangan naik*/ #include
#include
#include "iostream.h"
main()
{
int a;
clrscr();
for(a=1;a<=10;++a) cout<
#include
#include
main()
{
char nama[25],jur[2],grade,wkt;
float sesi,grd;
long total;
clrscr();
cout<<"\nNama Zaya :";cin>>nama;
getch();
}



#include
#include
#include
#include
main()
{
char nama[5],nim[20],kd,jrs[25];
long bkl,bpr,ttl;
clrscr();
cout <<"PROGRAM HITUNG BIAYA KULIAH"<<<"*******************************"<<<"Nama Mahassiswa :";cin>>nama;
cout <<"NIM :";cin>>nim;
cout <<"Kode Jurusan [1/2/3] :";cin>>kd;
cout <<"*********************************"<<<"Nama Mahasiswa :"<<<<"Jurusan :"<<<<"Biaya Kuliah :"<<<<"Biaya Praktikum :"<<<<"Total Biaya :"<<
#include
#include "iostream.h"
main()
{
int a;
clrscr();
for(a=1;a<=10;++a) cout<
getch();
}

cpp Bilangan ganjil menurun

Pada sesi kali ini kita belajar bahasa pemrogrraman C++, anda pasti tidak asing lagi mendengar bahasa pemrograman ini. pada contoh-contoh ini saya ambil langsung dari matakulaih yg saya peroleh di kampus saya yaitu Pemrograman BerOrientasi Objek (PBO). Mungkin anda akan bilang dengan nada yg sepele “apaan tuh PBO”. Sssssssssssssssst.... jangan bilang seperti itu, buat saya yg sudah ppernah terjun di software Engginering akan berani ngecam pd perkataan itu, dan akan berani mematahkan ucapan itu dengan “kalo memang anda jurusan sistem informasi atau teknik informatika dll yg setara dengannya..... sungguh sayang sekali uang yg kau ambur2kan dari dulu, anak SI or TI kalau tidak mau kenal dengan PBO menyesalah kau kelak jika anda memang benar2 sampai WISUDA.apakah anda sudah merasa menguasai teknik jaringan atau yg berkaitan dengan hardware...? itu bagus klo jwbannya ya tapi klo tidak.. anda akan merasa bahwa ijasah/titel S.Kom kamu akan setara dan/ tidak jauh beda sengan ijasah SMU/SMEA”. Ingat itu. Langsung aja saya mau memberi Contoh skrip.

Bilangan ganjil menurun :
/*Program for bilangan menurun*/
/*herisokwan tgal wong*/

#include
#include
#include "iostream.h"
main()
{
int a=19;
clrscr();
do
{cout <<=1);
getch();
}



Bilangan ganjil menurun :
/*Program for bilangan ggenap menurun*/
/*herisokwan tgal wong*/

#include
#include
#include "iostream.h"

main()
{
int a;
clrscr();
for(a=10;a>=1;a-=2)
cout <
<
#include
#include "iostream.h"

main()
{
int a;
clrscr();
for(a=10;a>=1;--a)
cout <
<
#include
#include "iostream.h"
main()
{
int a;
clrscr();
for(a=1;a<=10;a+=2) cout <
#include
#include "iostream.h"
main()
{
int bil=2;
clrscr();
do
{printf("%d",bil);
bil+=2;}
while(bil<=30); getch(); } /*Program for bilangan naik*/ #include
#include
#include "iostream.h"
main()
{
int a;
clrscr();
for(a=1;a<=10;++a) cout<
#include
#include
main()
{
char nama[25],jur[2],grade,wkt;
float sesi,grd;
long total;
clrscr();
cout<<"\nNama Zaya :";cin>>nama;
getch();
}



#include
#include
#include
#include
main()
{
char nama[5],nim[20],kd,jrs[25];
long bkl,bpr,ttl;
clrscr();
cout <<"PROGRAM HITUNG BIAYA KULIAH"<<<"*******************************"<<<"Nama Mahassiswa :";cin>>nama;
cout <<"NIM :";cin>>nim;
cout <<"Kode Jurusan [1/2/3] :";cin>>kd;
cout <<"*********************************"<<<"Nama Mahasiswa :"<<<<"Jurusan :"<<<<"Biaya Kuliah :"<<<<"Biaya Praktikum :"<<<<"Total Biaya :"<<
#include
#include "iostream.h"
main()
{
int a;
clrscr();
for(a=1;a<=10;++a) cout<
getch();
}





Bilangan ganjil menurun

Bilangan ganjil menurun :
/*Program for bilangan ggenap naik*/
/*herisokwan tgal wong*/

#include "stdio.h"
#include "conio.h"
#include

main()
{
int i,jum=0;
clrscr();
for(i=0;i<=10;i+=2)
{
cout< if(i<10)
cout<<"+";
else
cout<<"=";
jum=jum+i;
}
cout< getch();
}

tugas

#include "stdio.h"
#include "conio.h"
#include
main()
{
int a,b,jum=0;
clrscr();

for (a=5;a>=1;a--)
{
for (b=1;b<=a;b++)
{
cout<if (a<=5)
cout <<"+";
else
cout<<"=";
}
cout<<"\n";
}
getch();
}

Tugas

#include "stdio.h"
#include "conio.h"
#include
main()
{
int a,b,jum=0;
clrscr();

for (a=5;a>=1;a--)
{
for (b=1;b<=a;b++)
{
cout<if (a<=5)
cout <<"+";
else
cout<<"=";
}
cout<<"\n";
}
getch();
}

Cpp ifn

#include

int main(){

int hari = 5;

if(hari == 1){

// proses
printf("hari senin");

}
else if(hari == 2){

// proses
printf("hari selasa");

}
else if(hari == 3){

// proses
printf("hari rabu");

}
else if(hari == 4){

// proses
printf("hari kamis");

}
else if(hari == 5){

// proses
printf("hari jumat");

}
else if(hari == 6){

// proses
printf("hari sabtu");

}
else if(hari == 7){

// proses
printf("hari minggu");

}
else{

// proses
printf("tidak ada hari ke : %d\n", hari);

}

return 0;

}

Cpp if2

#include

int main(){

bool ketemu = false;
if(ketemu == true){

// proses
printf("(if) nilai variabel ketemu : true\n");

}
else{

// proses
printf("(else) nilai variabel ketemu : false\n");

}

return 0;

}

Cpp if1

#include

int main(){

bool ketemu = true;
if(ketemu == true){

// proses
printf("nilai variabel ketemu : true\n");

}

return 0;

}

Cpp masukan

#include

int main(){

int bilBulat = 0;

printf("masukkan masukan bilangan bulat : \n");

scanf("%d", &bilBulat);

printf("nilai masukan : %d\n", bilBulat);
if1
#include

int main(){

bool ketemu = true;
if(ketemu == true){

// proses
printf("nilai variabel ketemu : true\n");

}

return 0;

}

return 0;
}

Cpp for

#include

int main(){

int fak = 5;
int i;
int hasil = 1;

for(i=2; i<=fak;i++){
hasil = hasil * i;
printf("nilai variabel penghitung : %d\n", i);
}

printf("hasil faktorial : %d\n", hasil);

return 0;

}

Cpp fungsi

#include

int hasilKali(int a, int b, int c){


int hasil;
hasil = a * b * c;
return hasil;
}

int main(){

int a = 1;
int b = 2;
int c = 3;
int hasil;

hasil = hasilKali(a, b, c);
printf("hasil perkalian : %d\n", hasil);
return 0;

}

Cpp parameter

#include

void hitung(int a, int b, int *c){

*c = a + b;
printf("dalam prosedur : hasil penjumlahan : %d\n", *c);

}

int main(){

int operan1 = 2;
int operan2 = 3;
int hasil = 0;
hitung(operan1, operan2, &hasil);

printf("setelah prosedur : nilai hasil : %d\n", hasil);

return 0;

}

Cpp repeat

#include

int main(){

// inisialisasi
int i = 1;
bool ketemu = false;

do{
// proses
printf("nilai variabel i : %d, nilai variabel ketemu : false\n", i);


// iterasi
i = i + 1;

} while((i < 2) && (ketemu != true));

return 0;

}

Cpp while

#include

int main(){

// inisialisasi
int i = 1;
bool ketemu = false;

while((i <= 9) && (ketemu == false)){

// proses
printf("nilai variabel i : %d, nilai variabel ketemu : false\n", i);


// iterasi
i = i + 1;

// kondisi terminasi
if((i == 10) && (ketemu == false)){
ketemu = true;
}
}

return 0;

}

Cpp arrai1

#include

int main(){

int tabInt[5];

tabInt[0] = 1;
tabInt[1] = 2;
tabInt[2] = 3;
tabInt[3] = 4;
tabInt[4] = 5;

printf("isi array : \n");


int i;

for(i=0; i<5; i++){
printf("%d\n", tabInt[i]);
}

return 0;

}

Cpp array3

#include

int main(){

char tabChar[3][3][3] = {
{
{'a', 'b', 'c'},
{'d', 'e', 'f'},
{'g', 'h', 'i'}
}, {
{'j','k','l'},
{'m', 'n', 'o'},
{'p', 'q', 'r'}
}, {
{'s', 't', 'u'},
{'v', 'w', 'x'},
{'y', 'z', '0'}
}
};


printf("isi array : \n");

int i;
int j;
int k;

for(i=0; i<3; i++){
/* perulangan indeks pertama */
for(j=0; j<3; j++){
/* perulangan indeks kedua */
for(k=0; k<3; k++){
/* perulangan indeks ketiga */
printf("%c ", tabChar[i][j][k]);
}
printf("\n");
}
printf("\n");
}

return 0;

}

Cpp array2

#include

int main(){

char tabChar[5][5] = {
{'a', 'b', 'c', 'd', 'e'}, {'f', 'g', 'h', 'i', 'j'}, {'k', 'l', 'm', 'n', 'o'}, {'p', 'q', 'r', 's', 't'}, {'u', 'v', 'w', 'x', 'y'}
};

printf("isi array : \n");

int i;
int j;

for(i=0; i<5; i++){
// perulangan baris
for(j=0; j<5; j++){
// perulangan kolom
printf("%c ", tabChar[i][j]);
}
printf("\n");
}

return 0;

}

Cpp fakrekursi

#include

void faktorial(int n, int hasil){


if(n > 1){

hasil = hasil * n;
printf("rekursi dengan nilai hasil : %d, nilai n : %d\n", hasil, n);

n = n - 1;
faktorial(n, hasil);

}
}

int main(){

int hasil = 1;
faktorial(10, hasil);

return 0;

}

Cpp rekursi

#include

void tulis(int n){

int counter = n;

if(counter > 0){

printf("proses rekursi dengan nilai counter : %d\n", counter);
counter = counter - 1;
tulis(counter);

}

}

int main(){

tulis(10);

return 0;

}

Cpp file1

#include

int main(){

FILE *file_baru;

file_baru = fopen("Latihan.txt","w");

fclose(file_baru);

return 0;

}

Cpp file2


#include

int main(){

FILE *file_cek;

file_cek = fopen("Latihan.txt","r");

if( file_cek != NULL){

printf("file Latihan.txt sudah ada");

fclose(file_cek);

}

else{

printf("file Latihan.txt belum ada");

}

return 0;

}

Cpp file3

#include

int main(){

FILE *f;

f = fopen("Latihan.txt","w");

fprintf(f, "%s", "ini adalah file latihan");
fclose(f);

return 0;

}

Cpp file4

#include



int main(){

FILE *f;

f = fopen("Latihan.txt","r");

char str[100];

fgets(str, 100, f);


printf("isi file : %s\n", str);

fclose(f);

return 0;

}


Cpp seqfile1

#include
#include

int main(){

struct nilaiMatKul {
char nim[10];
char nama[100];
char nilai[2];
};

nilaiMatKul rekaman;

FILE *arsipMatKul;

arsipMatKul = fopen("ArsipMatKul.dat", "w");

printf("Tuliskan rekaman satu per satu : \n");

printf("masukkan nim : \n");

scanf("%s", &rekaman.nim);

while(strcmp(rekaman.nim, "XXXXXXXX") != 0){
/* proses */

printf("masukkan nama : \n");

scanf("%s", &rekaman.nama);

printf("masukkan nilai : \n");

scanf("%s", &rekaman.nilai);

fprintf(arsipMatKul, "%s %s %s\n", rekaman.nim, rekaman.nama, rekaman.nilai);
/* iterasi */

printf("masukkan nim : \n");

scanf("%s",&rekaman.nim);
}

fprintf(arsipMatKul, "%s %s %s\n", "XXXXXXXX","XXX","X");
fclose(arsipMatKul);

return 0;

}


Cpp seqfile2

#include
#include

int main(){

struct nilaiMatKul {
char nim[10];
char nama[100];
char nilai[2];
};

nilaiMatKul rekaman;

FILE *arsipMatKul;

arsipMatKul = fopen("ArsipMatKul.dat", "r");

printf("isi arsip beruntun adalah : \n");

fscanf(arsipMatKul, "%s %s %s\n", &rekaman.nim, &rekaman.nama, &rekaman.nilai);

if(strcmp(rekaman.nim, "XXXXXXXX") == 0){
printf("arsip kosong\n");
}
else{
do{
/* proses */
printf("nim : %s\n", rekaman.nim);
printf("nama : %s\n", rekaman.nama);
printf("nilai : %s\n", rekaman.nilai);
printf("-----------------\n");
/* iterasi */
fscanf(arsipMatKul, "%s %s %s\n", &rekaman.nim, &rekaman.nama, &rekaman.nilai);


}while(strcmp(rekaman.nim, "XXXXXXXX") != 0);
}

fclose(arsipMatKul);

return 0;

}


Cpp seqfile3

#include
#include

int main(){

struct nilaiMatKul {
char nim[10];
char nama[100];
char nilai[2];
};

nilaiMatKul rekaman;


FILE *arsipMatKul;


arsipMatKul = fopen("ArsipMatKul.dat", "r");

char kata_cari[10];

printf("masukkan nim yang dicari : \n");
scanf("%s", &kata_cari);

fscanf(arsipMatKul, "%s %s %s\n", &rekaman.nim, &rekaman.nama, &rekaman.nilai);

if(strcmp(rekaman.nim, "XXXXXXXX") == 0){
printf("arsip kosong\n");

}
else{
if(strcmp(kata_cari, "XXXXXXXX") == 0){
printf("tidak ditemukan\n");

}
else{
while((strcmp(rekaman.nim, "XXXXXXXX") != 0)&&(strcmp(rekaman.nim, kata_cari) != 0)){
/* iterasi */
fscanf(arsipMatKul, "%s %s %s\n", &rekaman.nim, &rekaman.nama, &rekaman.nilai);
}
if(strcmp(rekaman.nim, kata_cari)== 0){
printf("hasil pencarian : \n");
printf("nim : %s\n", rekaman.nim);
printf("nama : %s\n", rekaman.nama);
printf("nilai : %s\n", rekaman.nilai);
printf("------------\n");

}
else{
printf("tidak ditemukan\n");

}
}
}

fclose(arsipMatKul);

return 0;

}

Cpp seqfile4

#include
#include

int main(){

struct nilaiMatKul {
char nim[10];
char nama[100];
char nilai[2];
};

nilaiMatKul rekaman;

FILE *arsipMatKul1;

FILE *arsipMatKul2;

arsipMatKul1 = fopen("ArsipMatKul.dat", "r");

arsipMatKul2 = fopen("ArsipMatKul.bak", "w");

printf("mulai proses menyalin file\n");

fscanf(arsipMatKul1, "%s %s %s\n", &rekaman.nim, &rekaman.nama, &rekaman.nilai);

if(strcmp(rekaman.nim, "XXXXXXXX") == 0){
fprintf(arsipMatKul2, "%s %s %s\n", "XXXXXXXX","XXX","X");
}
else{
while(strcmp(rekaman.nim, "XXXXXXXX") != 0){
fprintf(arsipMatKul2, "%s %s %s\n", rekaman.nim, rekaman.nama, rekaman.nilai);

fscanf(arsipMatKul1, "%s %s %s\n", &rekaman.nim, &rekaman.nama, &rekaman.nilai);

}

fprintf(arsipMatKul2, "%s %s %s\n", "XXXXXXXX","XXX","X");
}

printf("proses menyalin file selesai\n");

fclose(arsipMatKul1);
fclose(arsipMatKul2);

return 0;

}

Cpp seqqfile6

import java.io.*;

class NilaiMatKul{
String nim;
String nama;
String nilai;

NilaiMatKul(){
}
}

class SeqFile6{

public static void main(String[] args) {

NilaiMatKul rekaman1 = new NilaiMatKul();

NilaiMatKul rekaman2 = new NilaiMatKul();

File arsipMatKul1;

File arsipMatKul2;

File fArsipMatKul;

arsipMatKul1 = new File("ArsipMatKul1.dat");

arsipMatKul2 = new File("ArsipMatKul2.dat");

fArsipMatKul = new File("ArsipMatKul4.dat");

if(!fArsipMatKul.exists()){
try{
new File("ArsipMatKul4.dat").
createNewFile();
}catch(Exception e){
}
}

try{
PrintWriter arsipMatKul3 = new PrintWriter(new FileWriter("ArsipMatKul4.dat", false));

System.out.println("mulai proses menyalin file");


FileReader fr1 = new FileReader (arsipMatKul1);
BufferedReader in1 = new BufferedReader( fr1 );

FileReader fr2 = new FileReader (arsipMatKul2);
BufferedReader in2 = new BufferedReader( fr2 );

String line1 = in1.readLine();

String[] rekList = line1.split("\\s+", 3);
rekaman1.nim = rekList[0];
rekaman1.nama = rekList[1];
rekaman1.nilai = rekList[2];

String line2 = in2.readLine();

rekList = line2.split("\\s+", 3);
rekaman2.nim = rekList[0];
rekaman2.nama = rekList[1];
rekaman2.nilai = rekList[2];
while((rekaman1.nim.compareTo("XXXXXXXX") != 0)&&( rekaman2.nim.compareTo("XXXXXXXX") != 0)){ if(rekaman1.nim.compareTo(rekaman2.nim) < 1){
arsipMatKul3.println(
rekaman1.nim + " " + rekaman1.nama + " " + rekaman1.nilai);

line1 = in1.readLine();
rekList = line1.split("\\s+", 3);
rekaman1.nim = rekList[0];
rekaman1.nama = rekList[1];
rekaman1.nilai = rekList[2];
}
else{
arsipMatKul3.println(
rekaman2.nim + " " + rekaman2.nama + " " + rekaman2.nilai);

line2 = in2.readLine();
rekList = line2.split("\\s+", 3);
rekaman2.nim = rekList[0];
rekaman2.nama = rekList[1];
rekaman2.nilai = rekList[2];

}
}

while(rekaman1.nim.compareTo("XXXXXXXX") != 0){
arsipMatKul3.println(
rekaman1.nim + " " + rekaman1.nama + " " + rekaman1.nilai);

line1 = in1.readLine();
rekList = line1.split("\\s+", 3);
rekaman1.nim = rekList[0];
rekaman1.nama = rekList[1];
rekaman1.nilai = rekList[2];
}

while(rekaman2.nim.compareTo("XXXXXXXX") != 0){
arsipMatKul3.println(
rekaman2.nim + " " + rekaman2.nama + " " + rekaman2.nilai);

line2 = in2.readLine();
rekList = line2.split("\\s+", 3);
rekaman2.nim = rekList[0];
rekaman2.nama = rekList[1];
rekaman2.nilai = rekList[2];
}

arsipMatKul3.println(
"XXXXXXXX XXX X");

arsipMatKul3.flush();
in1.close();
in2.close();
}catch(Exception e){
}
System.out.println("proses menyalin file selesai");

}
}

Cpp seqfile5

#include
#include

int main(){

struct nilaiMatKul {
char nim[10];
char nama[100];
char nilai[2];
};

nilaiMatKul rekaman;

FILE *arsipMatKul1;

FILE *arsipMatKul2;

FILE *arsipMatKul3;

arsipMatKul1 = fopen("ArsipMatKul1.dat", "r");

arsipMatKul2 = fopen("ArsipMatKul2.dat", "r");

arsipMatKul3 = fopen("ArsipMatKul3.dat", "w");

printf("mulai proses penggabungan file\n");

fscanf(arsipMatKul1, "%s %s %s\n", &rekaman.nim, &rekaman.nama, &rekaman.nilai);

while(strcmp(rekaman.nim, "XXXXXXXX") != 0){
fprintf(arsipMatKul3, "%s %s %s\n", rekaman.nim, rekaman.nama, rekaman.nilai);

fscanf(arsipMatKul1, "%s %s %s\n", &rekaman.nim, &rekaman.nama, &rekaman.nilai);

}

fscanf(arsipMatKul2, "%s %s %s\n", &rekaman.nim, &rekaman.nama, &rekaman.nilai);

while(strcmp(rekaman.nim, "XXXXXXXX") != 0){
fprintf(arsipMatKul3, "%s %s %s\n", rekaman.nim, rekaman.nama, rekaman.nilai);

fscanf(arsipMatKul2, "%s %s %s\n", &rekaman.nim, &rekaman.nama, &rekaman.nilai);



}

fprintf(arsipMatKul3, "%s %s %s\n", "XXXXXXXX","XXX","X");

printf("proses penggabungan file selesai\n");

fclose(arsipMatKul1);
fclose(arsipMatKul2);
fclose(arsipMatKul3);

return 0;

}

Cpp liststatik

#include
#include

//----------------------
struct nilaiMatKul{
char nim[10];
char nama[50];
char nilai[2];
};

struct elemen{
nilaiMatKul elmt;
int next;
};

struct list{
int first;
elemen data[10];
};

//----------------------
void createList(list *L){


(*L).first = -1;
int i;

for(i=0;i<=10;i++){
/*proses menginisialisasi isi array*/
(*L).data[i].next = -2;
}

}

//----------------------
int countElement(list L){


int hasil = 0;

if(L.first != -1){
/*list tidak kosong*/

int elmt;

/*inisialisasi*/
elmt = L.first;

while(elmt != -1){
/*proses*/
hasil = hasil + 1;

/*iterasi*/
elmt = L.data[elmt].next;
}

}

return hasil;

}

//----------------------
int emptyElement(list L){


int hasil = -1;

if(countElement(L) < 10){

bool ketemu = false;
int i = 0;
while((ketemu == false)&&(i <= 10)){
if(L.data[i].next == -2){
hasil = i;
ketemu = true;
}
else{
i = i + 1;
}
}

}

return hasil;

}

//----------------------
void addFirst(char nim[], char nama[], char nilai[], list *L){


if(countElement(*L) < 10){

int indeks = emptyElement(*L);

strcpy((*L).data[indeks].elmt.nim, nim); strcpy((*L).data[indeks].elmt.nama, nama); strcpy((*L).data[indeks].elmt.nilai, nilai);
if((*L).first == -1){
/*jika list kosong*/
(*L).data[indeks].next = -1;
}
else{
/*jika list tidak kosong*/
(*L).data[indeks].next = (*L).data[(*L).first].next;
}

(*L).first = indeks;
}
else{
/*proses jika array penuh*/
printf("sudah tidak dapat ditambah\n");
}

}

//----------------------
void addAfter(int prec, char nim[], char nama[], char nilai[], list *L){


if(countElement(*L) < 10){

int indeks = emptyElement(*L);

strcpy((*L).data[indeks].elmt.nim, nim);
strcpy((*L).data[indeks].elmt.nama, nama);
strcpy((*L).data[indeks].elmt.nilai, nilai);
(*L).data[indeks].next = (*L).data[prec].next;
(*L).data[prec].next = indeks;
}
else{
/*proses jika array penuh*/
printf("sudah tidak dapat ditambah\n");
}

}

//----------------------
void addLast(char nim[], char nama[], char nilai[], list *L){


if((*L).first == -1){
/*proses jika list masih kosong*/
int indeks = 0;
strcpy((*L).data[indeks].elmt.nim, nim);
strcpy((*L).data[indeks].elmt.nama, nama);
strcpy((*L).data[indeks].elmt.nilai, nilai);
(*L).data[indeks].next = -1;
(*L).first = indeks;
}
else{
/*proses jika list telah berisi elemen*/
if(countElement(*L) < 10){
/*proses jika array belum penuh*/

int indeks = emptyElement(*L);

strcpy((*L).data[indeks].elmt.nim, nim);
strcpy((*L).data[indeks].elmt.nama, nama);
strcpy((*L).data[indeks].elmt.nilai, nilai);
(*L).data[indeks].next = -1;

/*proses mencari elemen terakhir*/

/*inisialisasi*/
int last = (*L).first;

while((*L).data[last].next != -1){

/*iterasi*/
last = (*L).data[last].next;

}

(*L).data[last].next = indeks;
}
else{
/*proses jika array penuh*/
printf("sudah tidak dapat ditambah\n");
}
}

}

//----------------------
void delFirst(list *L){

if((*L).first != -1){
int elmt = (*L).first;
(*L).first = (*L).data[(*L).first].next;

/*elemen awal sebelumnya dikosongkan*/
(*L).data[elmt].next = -2;
}
else{
/*proses jika list kosong*/
printf("list kosong\n");
}

}

//----------------------
void delAfter(int prec, list *L){


int elmt = (*L).data[prec].next;
(*L).data[prec].next = (*L).data[elmt].next;

/*pengosongan elemen*/
(*L).data[elmt].next = -2;

}

//----------------------
void delLast(list *L){

if((*L).first != -1){
if(countElement(*L) == 1){
/*proses jika list hanya berisi satu elemen*/
delFirst(L);
}
else{
int last = (*L).first;
int beforeLast;

while((*L).data[last].next != -1){

/*iterasi*/
beforeLast = last;

last = (*L).data[last].next;

}
/*elemen sebelum elemen terakhir menjadi elemen terakhir*/
(*L).data[beforeLast].next = -1;
/*elemen terakhir sebelumnya dikosongkan*/
(*L).data[last].next = -2;
}
}
else{
/*proses jika list kosong*/

printf("list kosong\n");
}

}

//----------------------
void printElement(list L){


if(L.first != -1){
/*inisialisasi*/
int elmt = L.first;
int i = 1;

while(elmt != -1){
/*proses*/
printf("elemen ke : %d\n", i);
printf("nim : %s\n", L.data[elmt].elmt.nim);
printf("nama : %s\n", L.data[elmt].elmt.nama);
printf("nilai : %s\n", L.data[elmt].elmt.nilai);
printf("next : %d\n", L.data[elmt].next);
printf("------------\n");

/*iterasi*/
elmt = L.data[elmt].next;
i = i + 1;
}

}
else{
/*proses jika list kosong*/
printf("list kosong\n");
}

}

//----------------------
void delAll(list *L){

int i;

for(i=countElement(*L);i>=1;i--){

/*proses menghapus elemen list*/
delLast(L);
}

}

//----------------------
int main(){

struct list L;

createList(&L);
printElement(L);
printf("=================\n");
addFirst("13501019", "Andik", "A", &L);
addAfter(L.first, "13501037", "Shalahuddin", "A", &L);
addLast("13501058", "Rosa", "A", &L);
printElement(L);
printf("=================\n");
delLast(&L);
delAfter(L.first, &L);
delFirst(&L);
printElement(L);
printf("=================\n");

return 0;

}

Cpp listoflis

#include
#include
#include

//----------------------
struct mahasiswa{
char nim[10];
char nama[50];
};

struct matKul{
char kode[10];
char nilai[2];
};

struct eBaris{
mahasiswa elmt;
struct eKolom *col;
struct eBaris *next;
};

struct eKolom{
matKul elmt;
struct eKolom *next;
};

struct list{
eBaris *first;
};

//----------------------
void createList(list *L){


(*L).first = NULL;

}

//----------------------
int countElementB(list L){


int hasil = 0;

if(L.first !=NULL){
/*list tidak kosong*/

eBaris *elmt;

/*inisialisasi*/
elmt = L.first;

while(elmt != NULL){
/*proses*/
hasil = hasil + 1;

/*iterasi*/
elmt = elmt->next;
}

}

return hasil;

}

//----------------------
int countElementK(eBaris L){


int hasil = 0;

if(L.col !=NULL){
/*list tidak kosong*/

eKolom *elmt;

/*inisialisasi*/
elmt = L.col;

while(elmt != NULL){
/*proses*/
hasil = hasil + 1;

/*iterasi*/
elmt = elmt->next;
}

}

return hasil;

}

//----------------------
void addFirstB(char nim[], char nama[], list *L){

eBaris *elmt;
elmt = (eBaris *) malloc (sizeof (eBaris));
strcpy(elmt->elmt.nim, nim);
strcpy(elmt->elmt.nama, nama);
elmt->next = (*L).first;
elmt->col = NULL;
(*L).first = elmt;
elmt = NULL;

}

//----------------------
void addFirstK(char kode[], char nilai[], eBaris *L){

eKolom *elmt;
elmt = (eKolom *) malloc (sizeof (eKolom));
strcpy(elmt->elmt.kode, kode);
strcpy(elmt->elmt.nilai, nilai);
elmt->next = (*L).col;
(*L).col = elmt;
elmt = NULL;

}

//----------------------
void addAfterB(eBaris *prec, char nim[], char nama[]){

eBaris *elmt;
elmt = (eBaris *) malloc (sizeof (eBaris));
strcpy(elmt->elmt.nim, nim);
strcpy(elmt->elmt.nama, nama);
elmt->next = prec->next;
elmt->col = NULL;
prec->next = elmt;
elmt = NULL;

}

//----------------------
void addAfterK(eKolom *prec, char kode[], char nilai[]){

eKolom *elmt;
elmt = (eKolom *) malloc (sizeof (eKolom));
strcpy(elmt->elmt.kode, kode);
strcpy(elmt->elmt.nilai, nilai);
elmt->next = prec->next;
prec->next = elmt;
elmt = NULL;

}

//----------------------
void addLastB(char nim[], char nama[], list *L){

if((*L).first == NULL){
/*jika list adalah list kosong*/
addFirstB(nim, nama, L);
}
else{
/*jika list tidak kosong*/
eBaris *elmt;
elmt = (eBaris *) malloc (sizeof (eBaris));
strcpy(elmt->elmt.nim, nim);
strcpy(elmt->elmt.nama, nama);
elmt->next = NULL;
elmt->col = NULL;

/*mencari elemen terakhir list*/
eBaris *last = (*L).first;

while(last->next != NULL){

/*iterasi*/
last = last->next;

}

last->next = elmt;
elmt = NULL;
}

}

//----------------------
void addLastK(char kode[], char nilai[], eBaris *L){

if((*L).col == NULL){
/*jika list adalah list kosong*/
addFirstK(kode, nilai, L);
}
else{
/*jika list tidak kosong*/
eKolom *elmt;
elmt = (eKolom *) malloc (sizeof (eKolom));
strcpy(elmt->elmt.kode, kode);
strcpy(elmt->elmt.nilai, nilai);
elmt->next = NULL;

/*mencari elemen terakhir list*/
eKolom *last = (*L).col;

while(last->next != NULL){

/*iterasi*/
last = last->next;

}

last->next = elmt;
elmt = NULL;
}

}

//----------------------
void delFirstB(list *L){

if((*L).first != NULL){
/*jika list bukan list kosong*/
eBaris *elmt = (*L).first;
(*L).first = (*L).first->next;
elmt->next = NULL;
free(elmt);
}

}

//----------------------
void delFirstK(eBaris *L){

if((*L).col != NULL){
/*jika list bukan list kosong*/
eKolom *elmt = (*L).col;
(*L).col = (*L).col->next;
elmt->next = NULL;
free(elmt);
}

}

//----------------------
void delAfterB(eBaris *prec){

eBaris *elmt = prec->next;
prec->next = elmt->next;
elmt->next = NULL;
free(elmt);

}

//----------------------
void delAfterK(eKolom *prec){


eKolom *elmt = prec->next;
prec->next = elmt->next;
elmt->next = NULL;
free(elmt);

}

//----------------------
void delLastB(list *L){

if((*L).first != NULL){
/*jika list tidak kosong*/
if(countElementB(*L) == 1){
/*list terdiri dari satu elemen*/
delFirstB(L);

}
else{

/*mencari elemen terakhir list*/
eBaris *last = (*L).first;
eBaris *before_last;

while(last->next != NULL){

/*iterasi*/
before_last = last;
last = last->next;

}

before_last->next = NULL;
free(last);

}
}

}

//----------------------
void delLastK(eBaris *L){

if((*L).col != NULL){
/*jika list tidak kosong*/
if(countElementK(*L) == 1){
/*list terdiri dari satu elemen*/
delFirstK(L);

}
else{

/*mencari elemen terakhir list*/
eKolom *last = (*L).col;
eKolom *before_last;

while(last->next != NULL){

/*iterasi*/
before_last = last;
last = last->next;

}

before_last->next = NULL;
free(last);

}
}

}

//----------------------
void printElement(list L){

if(L.first != NULL){
/*jika list tidak kosong*/
/*inisialisasi*/
eBaris *elmt = L.first;
int i = 1;

while(elmt != NULL){
/*proses*/
printf("elemen ke : %d\n", i);
printf("nim : %s\n", elmt->elmt.nim);
printf("nama : %s\n", elmt->elmt.nama);

eKolom *eCol = elmt->col;
while(eCol != NULL){

printf("kode kuliah : %s\n", eCol->elmt.kode);
printf("nilai : %s\n", eCol->elmt.nilai);

eCol = eCol->next;

}

printf("------------\n");

/*iterasi*/
elmt = elmt->next;
i = i + 1;
}

}
else{
/*proses jika list kosong*/
printf("list kosong\n");
}

}

//----------------------
void delAllB(list *L){

if(countElementB(*L) != 0){

int i;

for(i=countElementB(*L);i>=1;i--){
/*proses menghapus elemen list*/
delLastB(L);
}

}

}

//----------------------
void delAllK(eBaris *L){

if(countElementK(*L) != 0){

int i;

for(i=countElementK(*L);i>=1;i--){
/*proses menghapus elemen list*/
delLastK(L);
}

}

}

//----------------------
int main(){

struct list L;

createList(&L);
printElement(L);

printf("=================\n");

addFirstB("13501019", "Andik", &L);
addFirstK("IF40K1", "A", L.first);
addAfterK(L.first->col, "IF40Z1", "A");
addLastK("IF40Z2", "A", L.first);

addAfterB(L.first, "13501037", "Shalahuddin");
addFirstK("TI5141", "A", L.first->next);
addLastK("IF5021", "A", L.first->next);

addLastB("13501058", "Rosa", &L);
addFirstK("IF5321", "A", L.first->next->next);

printElement(L);

printf("=================\n");

delAllB(&L);
printElement(L);

printf("=================\n");

return 0;

}

Cpp listdinamik
#include
#include
#include

//----------------------
struct nilaiMatKul{
char nim[10];
char nama[50];
char nilai[2];
};

struct elemen{
nilaiMatKul elmt;
struct elemen *next;
};

struct list{
struct elemen *first;
};

//----------------------

void createList(list *L){


(*L).first = NULL;

}

//----------------------
int countElement(list L){


int hasil = 0;

if(L.first !=NULL){
/*list tidak kosong*/

elemen *elmt;

/*inisialisasi*/
elmt = L.first;

while(elmt != NULL){
/*proses*/
hasil = hasil + 1;

/*iterasi*/
elmt = elmt->next;
}

}

return hasil;

}

//----------------------
void addFirst(char nim[], char nama[], char nilai[], list *L){


elemen *elmt;
elmt = (elemen *) malloc (sizeof (elemen));
strcpy(elmt->elmt.nim, nim);
strcpy(elmt->elmt.nama, nama);
strcpy(elmt->elmt.nilai, nilai);
elmt->next = (*L).first;
(*L).first = elmt;
elmt = NULL;

}

//----------------------
void addAfter(elemen *prec, char nim[], char nama[], char nilai[], list *L){

elemen *elmt;
elmt = (elemen *) malloc (sizeof (elemen));
strcpy(elmt->elmt.nim, nim);
strcpy(elmt->elmt.nama, nama);
strcpy(elmt->elmt.nilai, nilai);
elmt->next = prec->next;
prec->next = elmt;
elmt = NULL;


}
//----------------------
void addLast(char nim[], char nama[], char nilai[], list *L){


if((*L).first == NULL){
/*jika list adalah list kosong*/
addFirst(nim, nama, nilai, L);
}
else{
/*jika list tidak kosong*/
elemen *elmt;
elmt = (elemen *) malloc (sizeof (elemen));
strcpy(elmt->elmt.nim, nim);
strcpy(elmt->elmt.nama, nama);
strcpy(elmt->elmt.nilai, nilai);
elmt->next = NULL;

/*mencari elemen terakhir list*/
elemen *last = (*L).first;

while(last->next != NULL){

/*iterasi*/
last = last->next;

}

last->next = elmt;
elmt = NULL;
}

}

//----------------------
void delFirst(list *L){

if((*L).first != NULL){
/*jika list bukan list kosong*/
elemen *elmt = (*L).first;
(*L).first = (*L).first->next;
elmt->next = NULL;
free(elmt);
}

}

//----------------------
void delAfter(elemen *prec, list *L){


elemen *elmt = prec->next;
prec->next = elmt->next;
elmt->next = NULL;
free(elmt);

}

//----------------------
void delLast(list *L){

if((*L).first != NULL){
/*jika list tidak kosong*/
if(countElement(*L) == 1){
/*list terdiri dari satu elemen*/
delFirst(L);

}
else{

/*mencari elemen terakhir list*/
elemen *last = (*L).first;
elemen *before_last;

while(last->next != NULL){

/*iterasi*/
before_last = last;
last = last->next;

}

before_last->next = NULL;
free(last);

}
}

}

//----------------------
void printElement(list L){

if(L.first != NULL){
/*jika list tidak kosong*/
/*inisialisasi*/
elemen *elmt = L.first;
int i = 1;

while(elmt != NULL){
/*proses*/
printf("elemen ke : %d\n", i);
printf("nim : %s\n", elmt->elmt.nim);
printf("nama : %s\n", elmt->elmt.nama);
printf("nilai : %s\n", elmt->elmt.nilai);
printf("------------\n");

/*iterasi*/
elmt = elmt->next;
i = i + 1;
}

}
else{
/*proses jika list kosong*/
printf("list kosong\n");
}

}

//----------------------
void delAll(list *L){

if(countElement(*L) != 0){

int i;

for(i=countElement(*L);i>=1;i--){
/*proses menghapus elemen list*/
delLast(L);
}

}

}

//----------------------
int main(){

struct list L;

createList(&L);
printElement(L);

printf("=================\n");

addFirst("13501019", "Andik", "A", &L);
addAfter(L.first, "13501037", "Shalahuddin", "A", &L);
addLast("13501058", "Rosa", "A", &L);
printElement(L);
printf("=================\n");
delLast(&L);
delAfter(L.first, &L);
delFirst(&L);
printElement(L);
printf("=================\n");

return 0;

}

Cpp stackdinamik

#include
#include
#include

//----------------------

struct nilaiMatKul{
char nim[10];
char nama[50];
float nilai;
};

struct elemen{
nilaiMatKul elmt;
struct elemen *next;
};

struct stack{
struct elemen *top;
};

//----------------------

void createEmpty(stack *S){


(*S).top = NULL;

}

//----------------------

bool isEmpty(stack S){

bool hasil = false;

if(S.top == NULL){
hasil = true;
}

return hasil;

}

//----------------------

int countElement(stack S){


int hasil = 0;

if(S.top != NULL){
/* stack tidak kosong */

elemen *elmt;

/* inisialisasi */
elmt = S.top;

while(elmt != NULL){
/* proses */
hasil= hasil + 1;

/* iterasi */
elmt = elmt->next;
}

}

return hasil;

}

//----------------------

void push(char nim[], char nama[], float nilai, stack *S ){


elemen *elmt;
elmt = (elemen *) malloc (sizeof (elemen));
strcpy(elmt->elmt.nim, nim);
strcpy(elmt->elmt.nama, nama);
elmt->elmt.nilai = nilai;
elmt->next = (*S).top;
(*S).top = elmt;
elmt = NULL;

}

//----------------------

void pop(stack *S){

if((*S).top != NULL){
/* jika stack bukan stack kosong */
elemen *elmt = (*S).top;
(*S).top = (*S).top->next;
elmt->next = NULL;
free(elmt);
}

}

//----------------------

void printStack(stack S){

if(S.top != NULL){
printf("------isi stack------\n");
elemen *elmt = S.top;
int i = 1;

while(elmt != NULL){
printf("====================\n");
printf("elemen ke : %d\n", i);
printf("nim : %s\n", elmt->elmt.nim);
printf("nama : %s\n", elmt->elmt.nama);
printf("nilai : %f\n", elmt->elmt.nilai);

/* iterasi */
elmt = elmt->next;
i = i + 1;

}
printf("---------------------\n");
}
else{
/* proses jika stack kosong */
printf("stack kosong\n");
}

}

//----------------------

int main(){

struct stack S;

createEmpty(&S);
printStack(S);

printf("=================\n");

push("13507701", "Nana", 64.75, &S);
push("13507702", "Rudi", 75.11, &S);
push("13507703", "Dea", 84.63, &S);
printStack(S);

printf("=================\n");

pop(&S);
pop(&S);
printStack(S);

printf("=================\n");

return 0;

}

Cpp stackstatis
#include
#include

//----------------------

struct nilaiMatKul{
char nim[10];
char nama[50];
float nilai;
};

struct stack{
int top;
nilaiMatKul data[10];
};

//----------------------

void createEmpty(stack *S){


(*S).top = -1;

}

//----------------------

bool isEmpty(stack S){

bool hasil = false;

if(S.top == -1){
hasil = true;
}

return hasil;

}

//----------------------

bool isFull(stack S){

bool hasil = false;
if(S.top == 9){
hasil = true;
}

return hasil;

}

//----------------------

void push(char nim[], char nama[], float nilai, stack *S ){


if(isFull(*S) == true){
/*jika stack penuh*/
printf("stack penuh\n");
}
else{
if(isEmpty(*S) == true){
/* jika stack kosong */
(*S).top = 0;
strcpy((*S).data[0].nim, nim);
strcpy((*S).data[0].nama, nama);
(*S).data[0].nilai = nilai;
}
else{
/* jika stack tidak kosong */
(*S).top = (*S).top + 1;
strcpy((*S).data[(*S).top].nim, nim);
strcpy((*S).data[(*S).top].nama, nama);
(*S).data[(*S).top].nilai = nilai;
}
}

}

//----------------------

void pop(stack *S){

if((*S).top == 0){
/*jika stack berisi satu elemen*/
(*S).top = -1;
}
else{
if((*S).top != -1){
/*jika stack tidak kosong*/
(*S).top = (*S).top - 1;
}
}

}

//----------------------

void printStack(stack S){

if(S.top != -1){
printf("------isi stack------\n");
int i;
for(i=S.top;i>=0;i--){
printf("====================\n");
printf("elemen ke : %d\n", i);
printf("nim : %s\n", S.data[i].nim);
printf("nama : %s\n", S.data[i].nama);
printf("nilai : %f\n", S.data[i].nilai);
}
printf("---------------------\n");
}
else{
/* proses jika stack kosong */
printf("stack kosong\n");
}

}

//----------------------

int main(){

struct stack S;

createEmpty(&S);
printStack(S);

printf("=================\n");

push("13507701", "Nana", 64.75, &S);
push("13507702", "Rudi", 75.11, &S);
push("13507703", "Dea", 84.63, &S);
printStack(S);

printf("=================\n");

pop(&S);
pop(&S);
printStack(S);

printf("=================\n");

return 0;

}

Cpp queuestatik

#include
#include

//----------------------

struct nilaiMatKul{
char nim[10];
char nama[50];
float nilai;
};

struct queue{
int first;
int last;
nilaiMatKul data[10];
};

//----------------------

void createEmpty(queue *Q){


(*Q).first = -1;
(*Q).last = -1;

}

//----------------------

bool isEmpty(queue Q){

bool hasil = false;

if(Q.first == -1){
hasil = true;
}

return hasil;

}

//----------------------

bool isFull(queue Q){

bool hasil = false;
if(Q.last == 9){
hasil = true;
}

return hasil;

}

//----------------------

void add(char nim[], char nama[], float nilai, queue *Q ){


if(isEmpty(*Q) == true){
/* jika queue kosong */
(*Q).first = 0;
(*Q).last = 0;
strcpy((*Q).data[0].nim, nim);
strcpy((*Q).data[0].nama, nama);
(*Q).data[0].nilai = nilai;
}
else{
/* jika queue tidak kosong */
if(isFull(*Q) != true){
(*Q).last = (*Q).last + 1;
strcpy((*Q).data[(*Q).last].nim, nim);
strcpy((*Q).data[(*Q).last].nama, nama);
(*Q).data[(*Q).last].nilai = nilai;
}
else{
printf("queue penuh\n");
}
}

}

//----------------------

void del(queue *Q){

if((*Q).last == 0){
(*Q).first = -1;
(*Q).last = -1;
}
else{
/*menggeser elemen ke depan*/
int i;
for(i=((*Q).first + 1);i<=(*Q).last;i++){
strcpy((*Q).data[i-1].nim, (*Q).data[i].nim);
strcpy((*Q).data[i-1].nama, (*Q).data[i].nama);
(*Q).data[i-1].nilai = (*Q).data[i].nilai;
}
(*Q).last = (*Q).last - 1;
}

}

//----------------------

void printQueue(queue Q){

if(Q.first != -1){
printf("------isi queue------\n");
int i;
for(i=Q.last;i>=Q.first;i--){
printf("====================\n");
printf("elemen ke : %d\n", i);
printf("nim : %s\n", Q.data[i].nim);
printf("nama : %s\n", Q.data[i].nama);
printf("nilai : %f\n", Q.data[i].nilai);
}
printf("---------------------\n");
}
else{
/* proses jika queue kosong */
printf("queue kosong\n");
}

}

//----------------------

int main(){

queue Q;

createEmpty(&Q);
printQueue(Q);

printf("=================\n");

add("13507701", "Nana", 64.75, &Q);
add("13507702", "Rudi", 75.11, &Q);
add("13507703", "Dea", 84.63, &Q);
printQueue(Q);

printf("=================\n");

del(&Q);
del(&Q);
printQueue(Q);

printf("=================\n");

return 0;

}

Cpp queuestatik

#include
#include

//----------------------

struct nilaiMatKul{
char nim[10];
char nama[50];
float nilai;
};

struct queue{
int first;
int last;
nilaiMatKul data[10];
};

//----------------------

void createEmpty(queue *Q){


(*Q).first = -1;
(*Q).last = -1;

}

//----------------------

bool isEmpty(queue Q){

bool hasil = false;

if(Q.first == -1){
hasil = true;
}

return hasil;

}

//----------------------

bool isFull(queue Q){

bool hasil = false;
if(Q.last == 9){
hasil = true;
}

return hasil;

}

//----------------------

void add(char nim[], char nama[], float nilai, queue *Q ){


if(isEmpty(*Q) == true){
/* jika queue kosong */
(*Q).first = 0;
(*Q).last = 0;
strcpy((*Q).data[0].nim, nim);
strcpy((*Q).data[0].nama, nama);
(*Q).data[0].nilai = nilai;
}
else{
/* jika queue tidak kosong */
if(isFull(*Q) != true){
(*Q).last = (*Q).last + 1;
strcpy((*Q).data[(*Q).last].nim, nim);
strcpy((*Q).data[(*Q).last].nama, nama);
(*Q).data[(*Q).last].nilai = nilai;
}
else{
printf("queue penuh\n");
}
}

}

//----------------------

void del(queue *Q){

if((*Q).last == 0){
(*Q).first = -1;
(*Q).last = -1;
}
else{
/*menggeser elemen ke depan*/
int i;
for(i=((*Q).first + 1);i<=(*Q).last;i++){
strcpy((*Q).data[i-1].nim, (*Q).data[i].nim);
strcpy((*Q).data[i-1].nama, (*Q).data[i].nama);
(*Q).data[i-1].nilai = (*Q).data[i].nilai;
}
(*Q).last = (*Q).last - 1;
}

}

//----------------------

void printQueue(queue Q){

if(Q.first != -1){
printf("------isi queue------\n");
int i;
for(i=Q.last;i>=Q.first;i--){
printf("====================\n");
printf("elemen ke : %d\n", i);
printf("nim : %s\n", Q.data[i].nim);
printf("nama : %s\n", Q.data[i].nama);
printf("nilai : %f\n", Q.data[i].nilai);
}
printf("---------------------\n");
}
else{
/* proses jika queue kosong */
printf("queue kosong\n");
}

}

//----------------------

int main(){

queue Q;

createEmpty(&Q);
printQueue(Q);

printf("=================\n");

add("13507701", "Nana", 64.75, &Q);
add("13507702", "Rudi", 75.11, &Q);
add("13507703", "Dea", 84.63, &Q);
printQueue(Q);

printf("=================\n");

del(&Q);
del(&Q);
printQueue(Q);

printf("=================\n");

return 0;

}

Cpp queuedinamik

#include
#include
#include

//----------------------

struct nilaiMatKul{
char nim[10];
char nama[50];
float nilai;
};

struct elemen{
nilaiMatKul elmt;
struct elemen *next;
};

struct queue{
struct elemen *first;
struct elemen *last;
};

//----------------------

void createEmpty(queue *Q){


(*Q).first = NULL;
(*Q).last = NULL;

}

//----------------------

bool isEmpty(queue Q){

bool hasil = false;

if(Q.first == NULL){
hasil = true;
}

return hasil;

}

//----------------------

int countElement(queue Q){


int hasil = 0;

if(Q.first != NULL){
/* queue tidak kosong */

elemen *elmt;

/* inisialisasi */
elmt = Q.first;

while(elmt != NULL){
/* proses */
hasil= hasil + 1;

/* iterasi */
elmt = elmt->next;
}

}

return hasil;

}

//----------------------

void add(char nim[], char nama[], float nilai, queue *Q ){


elemen *elmt;
elmt = (elemen *) malloc (sizeof (elemen));
strcpy(elmt->elmt.nim, nim);
strcpy(elmt->elmt.nama, nama);
elmt->elmt.nilai = nilai;
elmt->next = NULL;
if((*Q).first == NULL){
(*Q).first = elmt;
}
else{
(*Q).last->next = elmt;
}
(*Q).last = elmt;
elmt = NULL;

}

//----------------------

void del(queue *Q){

if((*Q).first != NULL){
/* jika queue bukan queue kosong */
elemen *elmt = (*Q).first;
(*Q).first = (*Q).first->next;
elmt->next = NULL;
free(elmt);
}

}

//----------------------

void printQueue(queue Q){

if(Q.first != NULL){
printf("------isi queue------\n");
elemen *elmt = Q.first;
int i = 1;

while(elmt != NULL){
printf("====================\n");
printf("elemen ke : %d\n", i);
printf("nim : %s\n", elmt->elmt.nim);
printf("nama : %s\n", elmt->elmt.nama);
printf("nilai : %f\n", elmt->elmt.nilai);

/* iterasi */
elmt = elmt->next;
i = i + 1;

}
printf("---------------------\n");
}
else{
/* proses jika queue kosong */
printf("queue kosong\n");
}

}

//----------------------

int main(){

struct queue Q;

createEmpty(&Q);
printQueue(Q);

printf("=================\n");

add("13507701", "Nana", 64.75, &Q);
add("13507702", "Rudi", 75.11, &Q);
add("13507703", "Dea", 84.63, &Q);
printQueue(Q);

printf("=================\n");

del(&Q);
del(&Q);
printQueue(Q);

printf("=================\n");

return 0;

}

Cpp pohonbiner2

#include
#include

//----------------------

struct simpul{
char info;
struct simpul *right;
struct simpul *left;
};

struct tree{
struct simpul *root;
};

//----------------------

void makeTree(char c, tree *T){


simpul *node;
node = (simpul *) malloc (sizeof (simpul));
node->info = c;
node->right = NULL;
node->left = NULL;
(*T).root = node;

}

//----------------------

void addRight(char c, simpul **root){


if((*root)->right == NULL){
/*jika sub pohon kanan kosong*/
simpul *node;
node = (simpul *) malloc (sizeof (simpul));
node->info = c;
node->right = NULL;
node->left = NULL;
(*root)->right = node;
}
else{
printf("sub pohon kanan telah terisi \n");
}
}

//----------------------

void addLeft(char c, simpul **root){


if((*root)->left == NULL){
/*jika sub pohon kiri kosong*/
simpul *node;
node = (simpul *) malloc (sizeof (simpul));
node->info = c;
node->right = NULL;
node->left = NULL;
(*root)->left = node;
}
else{
printf("sub pohon kiri telah terisi \n");
}
}

//----------------------

void delRight(simpul **root){


simpul *node = (*root)->right;
(*root)->right = NULL;
free(node);

}

//----------------------

void delLeft(simpul **root){


simpul *node = (*root)->left;
(*root)->left = NULL;
free(node);

}

//----------------------

void printTreePreOrder(simpul *root){


if(root != NULL){
printf(" %c ", root->info);
printTreePreOrder(root->left);
printTreePreOrder(root->right);
}

}

//----------------------

void printTreeInOrder(simpul *root){


if(root != NULL){
printTreeInOrder(root->left);
printf(" %c ", root->info);
printTreeInOrder(root->right);
}

}

//----------------------

void printTreePostOrder(simpul *root){

if(root != NULL){
printTreePostOrder(root->left);
printTreePostOrder(root->right);
printf(" %c ", root->info);
}

}

//----------------------

void printTreeLevelOrderNext(simpul *root){


if(root != NULL){
if(root->left != NULL){
printf(" %c ", root->left->info);
}
if(root->right != NULL){
printf(" %c ", root->right->info);
}
if(root->left != NULL){
printTreeLevelOrderNext(root->left);
}
if(root->right != NULL){
printTreeLevelOrderNext(root->right);
}
}

}

void printTreeLevelOrder(simpul *root){

if(root != NULL){
printf(" %c ", root->info);
printTreeLevelOrderNext(root);
}

}

//----------------------

void copyTree(simpul *root1, simpul **root2){

if(root1 != NULL){
(*root2) = (simpul *) malloc (sizeof (simpul));
(*root2)->info = root1->info;
if(root1->left != NULL){
copyTree(root1->left, &(*root2)->left);
}
if(root1->right != NULL){
copyTree(root1->right, &(*root2)->right);
}
}

}

//----------------------

bool isEqual(simpul *root1, simpul *root2){

bool hasil = true;

if((root1 != NULL)&&(root2 != NULL)){
if(root1->info != root2->info){
hasil = false;
}
else{
isEqual(root1->left, root2->left);
isEqual(root1->right, root2->right);
}
}
else{
if((root1 != NULL)||(root2 != NULL)){
hasil = false;
}
}

return hasil;

}

//----------------------

int main(){

struct tree T;

makeTree('A', &T);
addLeft('B', &T.root);
addRight('C', &T.root);
addLeft('D', &T.root->left);
addRight('E', &T.root->left);
addRight('F', &T.root->right);

printf("=================\n");
printf("preOrder\n");
printTreePreOrder(T.root);
printf("\n=================\n");
printf("inOrder\n");
printTreeInOrder(T.root);
printf("\n=================\n");
printf("postOrder\n");
printTreePostOrder(T.root);
printf("\n=================\n");
printf("levelOrder\n");
printTreeLevelOrder(T.root);
printf("\n=================\n");

tree T2;

copyTree(T.root, &T2.root);
if(isEqual(T.root, T2.root) == true){

printf("pohon sama\n");
}
else{
printf("pohon tidak sama\n");
}

delRight(&T.root->left);
delLeft(&T.root->left);
printf("=================\n");
printf("preOrder setelah dihapus\n");
printTreePreOrder(T.root);
printf("\n=================\n");

return 0;

}

Cpp titik

#include

class Titik{

/*kelas yang digunakan untuk mengimplementasikan sebuah tipe titik*/

private:
int x; /*koordinat x*/
int y; /*koordinat y*/

public:
Titik(){
/*konstruktor*/
x = 0;
y = 0;
}

Titik(int xp, int yp){
/*konstruktor*/
x = xp;
y = yp;
}

void setX(int xp){
/*mengeset nilai koordinat x*/
x = xp;
}

int getX(){
/*mengembalikan nilai koordinat x*/
return x;
}

void setY(int yp){
/*mengeset nilai koordinat y*/
y = yp;
}

int getY(){
/*mengembalikan nilai koordinat y*/
return y;
}

~Titik(){
/*destruktor*/

}

};


/*fungsi main untuk mengetes kelas Titik*/

int main(){

Titik t1;
Titik t2(11, 9);

t1.setX(18);
t1.setY(28);

printf("t1 : nilai X : %d\n", t1.getX());
printf("t1 : nilai Y : %d\n", t1.getY());

printf("t2 : nilai X : %d\n", t2.getX());
printf("t2 : nilai Y : %d\n", t2.getY());

return 0;

}

Cpp graphdinamik
#include
#include

//----------------------

struct simpul{
char info;
struct simpul *next;
struct jalur *arc;
};

struct jalur{
int info;
struct jalur *next;
struct simpul *node;
};

struct graph{
struct simpul *first;
};

//----------------------

void createEmpty(graph *G){


(*G).first = NULL;

}

//----------------------

void addSimpul(char c, graph *G){


simpul *node;
node = (simpul *) malloc (sizeof (simpul));
node->info = c;
node->next = NULL;
node->arc = NULL;

if((*G).first == NULL){
/*jika graph kosong*/
(*G).first = node;
}
else{
/*menambahkan simpul baru pada akhir graph*/
simpul *last = (*G).first;

while(last->next != NULL){
last = last->next;
}

last->next = node;

}

}

//----------------------

void addJalur(simpul *tujuan, int beban, simpul **awal){


jalur *arc;
arc = (jalur *) malloc (sizeof (jalur));
arc->info = beban;
arc->next = NULL;
arc->node = tujuan;

if((*awal)->arc == NULL){
/*jika list jalur kosong*/
(*awal)->arc = arc;
}
else{
/*menambahkan jalur baru pada akhir list jalur*/
jalur *last = (*awal)->arc;

while(last->next != NULL){
last = last->next;
}

last->next = arc;

}

}

//----------------------

void delSimpul(char c, graph *G){


simpul *elmt = (*G).first;

if(elmt != NULL){

simpul *prec = NULL;

/*mencari simpul yang akan dihapus*/

bool ketemu = false;
while((elmt != NULL) && (ketemu == false)){
if(elmt->info == c){
ketemu = true;
}
else{
prec = elmt;
elmt = elmt->next;
}
}

if(ketemu == true){
if(prec == NULL){
/*hapus simpul pertama*/
(*G).first = elmt->next;
}
else{
if(elmt->next == NULL){
/*hapus simpul terakhir*/
prec->next = NULL;
}
else{
/*hapus simpul di tengah*/
prec->next = elmt->next;
elmt->next = NULL;
}
}
free(elmt);
}
else{
printf("tidak ada simpul dengan info karakter masukan\n");
}
}
else{
printf("tidak ada simpul dengan info karakter masukan\n");
}

}

//----------------------

simpul* findSimpul(char c, graph G){


simpul *hasil = NULL;
simpul *node = G.first;

int ketemu = 0;
while((node != NULL) && (ketemu == 0)){
if(node->info == c){
hasil = node;
ketemu = 1;
}
else{
node = node->next;
}
}

return hasil;

}

//----------------------

void delJalur(char ctujuan, simpul **awal){

jalur *arc = (*awal)->arc;

if(arc != NULL){

jalur *prec = NULL;

/*mencari jalur yang akan dihapus*/
int ketemu = 0;
while((arc != NULL) && (ketemu == 0)){
if(arc->node->info == ctujuan){

ketemu = 1;
}
else{
prec = arc;
arc = arc->next;
}
}

if(ketemu == 1){
if(prec == NULL){
/*hapus jalur pertama*/
(*awal)->arc = arc->next;
}
else{
if(arc->next == NULL){
/*hapus jalur terakhir*/
prec->next = NULL;
}
else{
/*hapus jalur di tengah*/
prec->next = arc->next;
arc->next = NULL;
}
}
free(arc);
}
else{
printf("tidak ada jalur dengan simpul tujuan\n");
}
}
else{
printf("tidak ada jalur dengan simpul tujuan\n");
}

}

//----------------------

void printGraph(graph G){

simpul *node = G.first;

if(node != NULL){

while(node != NULL){

printf("simpul : %c\n", node->info);
jalur *arc = node->arc;

while(arc != NULL){

printf(" - ada jalur ke simpul : %c dengan beban : %d\n", arc->node->info, arc->info);

arc = arc->next;

}

node = node->next;

}
}
else{
printf("graph kosong\n");
}

}

//----------------------

int main(){

struct graph G;

createEmpty(&G);
addSimpul('A', &G);
addSimpul('B', &G);
addSimpul('C', &G);
addSimpul('D', &G);
addSimpul('E', &G);
addSimpul('F', &G);

simpul *begin = findSimpul('A', G);
simpul *end = findSimpul('B', G);
if((begin != NULL) && (end != NULL)){
addJalur(end, 3, &begin);
}

begin = findSimpul('B', G);
end = findSimpul('D', G);
if((begin != NULL) && (end != NULL)){
addJalur(end, 3, &begin);
}

end = findSimpul('E', G);
if((begin != NULL) && (end != NULL)){
addJalur(end, 7, &begin);
}

begin = findSimpul('C', G);
end = findSimpul('A', G);
if((begin != NULL) && (end != NULL)){
addJalur(end, 3, &begin);
}

begin = findSimpul('D', G);
if((begin != NULL) && (end != NULL)){
addJalur(end, 8, &begin);
}

end = findSimpul('C', G);
if((begin != NULL) && (end != NULL)){
addJalur(end, 3, &begin);
}

begin = findSimpul('E', G);
end = findSimpul('D', G);
if((begin != NULL) && (end != NULL)){
addJalur(end, 4, &begin);
}

end = findSimpul('F', G);
if((begin != NULL) && (end != NULL)){
addJalur(end, 4, &begin);
}

begin = findSimpul('F', G);
end = findSimpul('D', G);
if((begin != NULL) && (end != NULL)){
addJalur(end, 2, &begin);
}

printf("=================\n");
printGraph(G);
printf("\n=================\n");

begin = findSimpul('A', G);
if(begin != NULL){
delJalur('B', &begin);
}

printf("=================\n");
printf("setelah dihapus\n");
printGraph(G);
printf("\n=================\n");

return 0;

}


Cpp pohonbiner
#include
#include

//----------------------

struct simpul{
char info;
struct simpul *sibling;
struct simpul *child;
};

struct tree{
struct simpul *root;
};

//----------------------

void makeTree(char c, tree *T){


simpul *node;
node = (simpul *) malloc (sizeof (simpul));
node->info = c;
node->sibling = NULL;
node->child = NULL;
(*T).root = node;

}

//----------------------

void addChild(char c, simpul **root){


if((*root) != NULL){
/*jika root tidak kosong*/
simpul *node;
node = (simpul *) malloc (sizeof (simpul));
node->info = c;
node->child = NULL;

if((*root)->child == NULL){
/*simpul baru menjadi anak pertama*/
node->sibling = NULL;
(*root)->child = node;
}
else{
if((*root)->child->sibling == NULL){
/*jika simpul baru menjadi anak kedua*/
node->sibling = (*root)->child;
(*root)->child->sibling = node;
}
else{
simpul *last = (*root)->child;

/*mencari simpul anak terakhir*/
while(last->sibling != (*root)->child){
last = last->sibling;
}

node->sibling = (*root)->child;
last->sibling = node;

}
}
}
}

//----------------------

void delChild(char c, simpul **root){


simpul *node = (*root)->child;

if(node != NULL){
if(node->sibling == NULL){
/*jika hanya mempunyai satu anak*/
if((*root)->child->info == c){
(*root)->child = NULL;
free(node);
}
else{
printf("tidak ada simpul anak dengan info karakter masukan\n");
}
}
else{
/*jika memiliki banyak anak*/
simpul *prec = NULL;

/*mencari simpul yang akan dihapus*/

bool ketemu = false;
while((node->sibling != (*root)->child)&&(ketemu == false)){
if(node->info == c){
ketemu = true;
}
else{
prec = node;
node = node->sibling;
}
}

/*memproses simpul anak terakhir karena belum terproses dalam perulangan*/
if((ketemu == false)&&(node->info == c)){
ketemu = true;
}

if(ketemu == true){
simpul *last = (*root)->child;

/*mencari simpul anak terakhir*/
while(last->sibling != (*root)->child){
last = last->sibling;
}

if(prec == NULL){
/*jika simpul yang dihapus anak pertama*/
if((node->sibling == last)&&(last->sibling == (*root)->child)){
/*jika hanya ada 2 anak*/
(*root)->child = last;
last->sibling = NULL;
}
else{
(*root)->child = node->sibling;
last->sibling = (*root)->child;
}
}
else{
if((prec == (*root)->child)&&(last->sibling == (*root)->child)){
/*jika hanya ada 2 simpul anak, yang dihapus anak kedua*/
(*root)->child->sibling = NULL;
}
else{
prec->sibling = node->sibling;
node->sibling = NULL;
}
}

free(node);
}
else{
printf("tidak ada simpul anak dengan info karakter masukan\n");
}
}
}

}

//----------------------

simpul* findSimpul(char c, simpul *root){

simpul *hasil = NULL;

if(root != NULL){
if(root->info == c){
hasil = root;
}
else{

simpul *node = root->child;

if(node != NULL){
if(node->sibling == NULL){
/*jika memiliki satu anak*/
if(node->info == c){
hasil = node;
}
else{
hasil = findSimpul(c, node);
}
}
else{
/*jika memiliki banyak anak*/
int ketemu = 0;
while((node->sibling != root->child)&&(ketemu == 0)){
if(node->info == c){
hasil = node;
ketemu = 1;
}
else{
hasil = findSimpul(c, node);
node = node->sibling;
}
}

/*memproses simpul anak terakhir karena belum terproses dalam perulangan*/
if(ketemu == 0){
if(node->info == c){
hasil = node;
}
else{
hasil = findSimpul(c, node);
}
}
}
}
}
}

return hasil;

}

//----------------------

void printTreePreOrder(simpul *root){


if(root != NULL){
printf(" %c ", root->info);

simpul *node = root->child;

if(node != NULL){
if(node->sibling == NULL){
/*jika memiliki satu anak*/
printTreePreOrder(node);
}
else{
/*jika memiliki banyak anak*/

/*mencetak simpul anak*/
while(node->sibling != root->child){
printTreePreOrder(node);
node = node->sibling;
}

/*memproses simpul anak terakhir karena belum terproses dalam perulangan*/
printTreePreOrder(node);
}
}
}

}

//----------------------

void printTreePostOrder(simpul *root){

if(root != NULL){

simpul *node = root->child;

if(node != NULL){
if(node->sibling == NULL){
/*jika memiliki satu anak*/
printTreePostOrder(node);
}
else{
/*jika memiliki banyak anak*/

/*mencetak simpul anak*/
while(node->sibling != root->child){
printTreePostOrder(node);
node = node->sibling;
}

/*memproses simpul anak terakhir karena belum terproses dalam perulangan*/
printTreePostOrder(node);
}
}

printf(" %c ", root->info);
}

}

//----------------------

void printTreeLevelOrderNext(simpul *root){


if(root != NULL){

simpul *node = root->child;

if(node != NULL){
if(node->sibling == NULL){
/*jika memiliki satu anak*/
printf(" %c ", node->info);

printTreeLevelOrderNext(node);
}
else{
while(node->sibling != root->child){
printf(" %c ", node->info);
node = node->sibling;
}

/*memproses simpul anak terakhir karena belum terproses dalam perulangan*/
printf(" %c ", node->info);

node = root->child;

while(node->sibling != root->child){

printTreeLevelOrderNext(node);
node = node->sibling;
}

/*memproses simpul anak terakhir karena belum terproses dalam perulangan*/

printTreeLevelOrderNext(node);

}
}

}

}

void printTreeLevelOrder(simpul *root){

if(root != NULL){
printf(" %c ", root->info);
printTreeLevelOrderNext(root);
}

}

//----------------------

void copyTree(simpul *root1, simpul **root2){

if(root1 != NULL){
(*root2) = (simpul *) malloc (sizeof (simpul));
(*root2)->info = root1->info;
(*root2)->sibling = NULL;
(*root2)->child = NULL;

if(root1->child != NULL){
if(root1->child->sibling == NULL){
/*jika memiliki satu anak*/
copyTree(root1->child, &(*root2)->child);
}
else{
/*jika memiliki banyak anak*/
simpul *node1 = root1->child;
simpul *node2 = (*root2)->child;
while(node1->sibling != root1->child){
copyTree(node1, &node2);
node1 = node1->sibling;
node2 = node2->sibling;
}

/*memproses simpul anak terakhir karena belum terproses dalam perulangan*/
copyTree(node1, &node2);

}

}

}

}

//----------------------

int isEqual(simpul *root1, simpul *root2){

int hasil = 1;

if((root1 != NULL)&&(root2 != NULL)){
if(root1->info != root2->info){
hasil = 0;
}
else{
if((root1->child != NULL)&&(root2->child != NULL)){
if(root1->child->sibling == NULL){
/*jika memiliki satu anak*/
hasil = isEqual(root1->child, root2->child);
}
else{
/*jika memiliki banyak anak*/
simpul *node1 = root1->child;
simpul *node2 = root2->child;

while(node1->sibling != root1->child){
if((node1 != NULL)&&(node2 != NULL)){
hasil = isEqual(node1, node2);
node1 = node1->sibling;
node2 = node2->sibling;
}
else{
hasil = 0;
break;
}
}

/*memproses simpul anak terakhir karena belum terproses dalam perulangan*/
hasil = isEqual(node1, node2);
}
}
}
}
else{
if((root1 != NULL)||(root2 != NULL)){
hasil = 0;
}
}

return hasil;

}

//----------------------

int main(){

struct tree T;

makeTree('A', &T);
addChild('B', &T.root);
addChild('C', &T.root);
addChild('D', &T.root);

simpul *node = findSimpul('B', T.root);
if(node != NULL){
addChild('E', &node);
addChild('F', &node);
}

node = findSimpul('C', T.root);
if(node != NULL){
addChild('G', &node);
}

node = findSimpul('D', T.root);
if(node != NULL){
addChild('H', &node);
addChild('I', &node);
addChild('J', &node);
}

node = findSimpul('J', T.root);
if(node != NULL){
addChild('K', &node);
addChild('L', &node);
addChild('M', &node);
}

printf("=================\n");
printf("preOrder\n");
printTreePreOrder(T.root);
printf("\n=================\n");
printf("postOrder\n");
printTreePostOrder(T.root);
printf("\n=================\n");
printf("levelOrder\n");
printTreeLevelOrder(T.root);
printf("\n=================\n");

tree T2;

copyTree(T.root, &T2.root);
if(isEqual(T.root, T2.root) == true){

printf("pohon sama\n");
}
else{
printf("pohon tidak sama\n");
}

node = findSimpul('J', T.root);
if(node != NULL){
delChild('K', &node);
delChild('L', &node);
delChild('M', &node);
}

printf("=================\n");
printf("preOrder setelah dihapus\n");
printTreePreOrder(T.root);
printf("\n=================\n");

return 0;

}

Cpp titik2

#include "titik.h"

Titik::Titik(){
/*konstruktor*/
Titik::x = 0;
Titik::y = 0;
}

Titik::Titik(int xp, int yp){
/*konstruktor*/
Titik::x = xp;
Titik::y = yp;
}

void Titik::setX(int xp){
/*mengeset nilai koordinat x*/
Titik::x = xp;
}

int Titik::getX(){
/*mengembalikan nilai koordinat x*/
return Titik::x;
}

void Titik::setY(int yp){
/*mengeset nilai koordinat y*/
Titik::y = yp;
}

int Titik::getY(){
/*mengembalikan nilai koordinat y*/
return Titik::y;
}

Titik::~Titik(){
/*destruktor*/

}

/*fungsi main untuk mengetes kelas Titik*/

int main(){

Titik t1;
Titik t2(11, 9);

t1.setX(18);
t1.setY(28);

printf("t1 : nilai X : %d\n", t1.getX());
printf("t1 : nilai Y : %d\n", t1.getY());

printf("t2 : nilai X : %d\n", t2.getX());
printf("t2 : nilai Y : %d\n", t2.getY());

return 0;

}

Cpp ttitikp

#include

class Titik{

/*kelas yang digunakan untuk mengimplementasikan sebuah tipe titik*/

private:
int x; /*koordinat x*/
int y; /*koordinat y*/

public:
Titik(){
/*konstruktor*/
x = 0;
y = 0;
}

Titik(int xp, int yp){
/*konstruktor*/
x = xp;
y = yp;
}

void setX(int xp){
/*mengeset nilai koordinat x*/
x = xp;
}

int getX(){
/*mengembalikan nilai koordinat x*/
return x;
}

void setY(int yp){
/*mengeset nilai koordinat y*/
y = yp;
}

int getY(){
/*mengembalikan nilai koordinat y*/
return y;
}

~Titik(){
/*destruktor*/

}

};

class Titik3D : public Titik{

/*kelas turunan kelas Titik*/

private:
int z; /*koordinat z*/

public:
Titik3D(){
/*konstruktor*/
z = 0;
}

Titik3D(int xp, int yp, int zp){

/*konstruktor*/
setX(xp);
setY(yp);
z = zp;
}

void setZ(int zp){
/*mengeset nilai koordinat z*/
z = zp;
}

int getZ(){
/*mengembalikan nilai koordinat z*/
return z;
}

};


/*fungsi main untuk mengetes kelas Titik dan kelas Titik3D*/

int main(){

Titik3D t(0, 0, 7);

t.setX(28);
t.setY(1);

printf("t : nilai X : %d\n", t.getX());
printf("t : nilai Y : %d\n", t.getY());
printf("t : nilai Z : %d\n", t.getZ());

return 0;

}

Cpp titikb

#include

class Titik{

/*kelas yang digunakan untuk mengimplementasikan sebuah tipe titik*/

private:
int x; /*koordinat x*/
int y; /*koordinat y*/

public:
Titik(){
/*konstruktor*/
x = 0;
y = 0;
}

Titik(int xp, int yp){
/*konstruktor*/
x = xp;
y = yp;
}

void setX(int xp){
/*mengeset nilai koordinat x*/
x = xp;
}

int getX(){
/*mengembalikan nilai koordinat x*/
return x;
}

void setY(int yp){
/*mengeset nilai koordinat y*/
y = yp;
}

int getY(){
/*mengembalikan nilai koordinat y*/
return y;
}

virtual void printTitik(){
/*menampilkan nilai koordinat titik*/
printf("nilai X : %d\n", getX());
printf("nilai Y : %d\n", getY());
}

~Titik(){
/*destruktor*/

}

};

class Titik3D : public Titik{

/*kelas turunan kelas Titik*/

private:
int z; /*koordinat z*/

public:
Titik3D(){
/*konstruktor*/
z = 0;
}

Titik3D(int xp, int yp, int zp){

/*konstruktor*/
setX(xp);
setY(yp);
z = zp;
}

void setZ(int zp){
/*mengeset nilai koordinat z*/
z = zp;
}

int getZ(){
/*mengembalikan nilai koordinat z*/
return z;
}

virtual void printTitik(){
/*menampilkan nilai koordinat titik*/
printf("nilai X : %d\n", getX());
printf("nilai Y : %d\n", getY());
printf("nilai Z : %d\n", getZ());
}

};


/*fungsi main untuk mengetes kelas Titik dan kelas Titik3D */

int main(){

Titik3D t(0, 0, 7);

t.setX(28);
t.setY(1);

t.printTitik();

Titik *t1;

printf("====================\n");

t1 = &t;

t1->printTitik();

return 0;

}