TUGAS 1.3 ALGORITMA DAN STRUKTUR DATA
ALGORITMA DAN STRUKTUR DATA
UNIVERSITAS ISLAM AS-SYAFI'IYAH
Assalamualaikum wr.wb
Nama : Bagaskara Bayu Nugraha
NIM : 3420210026
Prodi : Teknik Informatika
Lampiran Tugas 1 Menggunakan Borland C++
//Nama : Bagaskara Bayu Nugraha
//NIM : 3420210026
//Prodi : Teknik Informatika
#includ <stdio.h>
#include <iostream.h>
#include <conio.h>
void main()
{
//Deklarasi Variable
int absen,tugas,uts,uas;
float total;
puts("Program Menghitung Nilai Mahasiswa");
puts("=====================================");
printf("Masukan nilai absen: ");scanf("%d",&absen);
cout<<("Masukan nilai tugas: ");cin>>tugas;
printf("Masukan nilai uts : ");scanf("%i",&uts);
cout<<("Masukan nilai uas: ");cin>>uas;
//Proses Perhitungan
total = (absen*0.1)+(tugas*0.2)+(uts*0.3)+(uas*0.4);
puts("=====================================");
cout<<"Total adalah: "<<total<<" (bentuk tidak terformat)\n";
printf("Total adalah: %.2f (bentuk yang terformat)\n",total);
puts("=====================================");
//Kondisi
if (total >=75 )
{ cout<<"Selamat anda lulus."; }
else
{ cout<<"Maaf anda tidak lulus."; }
getch();
}
Lampiran Tugas 2.1 Menggunakan Borland C++
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <iostream.h>
void main()
{
int pilih;
char huruf[20];
printf("Silahkan pilih program [1/2]: ");cin>>pilih;
//scanf("%d",&pilih);
/*
There are two problems with using scanf() to get a number:
First, Validation/error handling is poor.
The second problems is that of leaving characters in the buffer.
Sumber: http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?anever-1043372399sid=1043284385
*/
if (pilih == 1)
{
clrscr();
puts("=====================================");
puts("\tContoh Program Strlen");
puts("=====================================");
cout<<"Masukan Sembarang Kata = ";gets(huruf);
cout<<"Panjang Kata Yang Diinputkan = "<<strlen(huruf);
getch();
}
Lampiran Tugas 2.2 Menggunakan Borland C++
else if (pilih == 2)
{
clrscr();
puts("=====================================");
puts("\tContoh Program Strcmp");
puts("=====================================");
char a1[ ] = "S";
char a2[ ] = "s";
char b1[ ] = "S";
cout<<"Hasil Perbandingan "<<a1<<" dan "<<a2<<"->";
cout<<strcmp(a1,a2)<<endl;
cout<<"Hasil Perbandingan "<<a2<<" dan "<<a1<<"->";
cout<<strcmp(a2,a1)<<endl;
cout<<"Hasil Perbandingan "<<a1<<" dan "<<b1<<"->";
cout<<strcmp(a1,b1)<<endl;
}
else
{
printf("Maaf pilihan anda anda salah..");
getch();
}
}
Lampiran Tugas 3 Menggunakan Borland C++
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
void main()
{
char gol,jab[10];
long gapok;
cout<<endl<<"Data Jabatan"<<endl
<<"= = = = = = = = = = = = = = = = "<<endl;
cout<<"Masukan Golongan [1/2]: ";cin>>gol;
if(gol=='1')
{
strcpy(jab,"Direktur");
gapok=5000000;
}
else if(gol=='2')
{
strcpy(jab,"Manajer");
gapok=4000000;
}
else
{
printf("Golongan %c tidak terdaftar.\n",gol);
strcpy(jab,"None");
gapok=0;
}
cout<<"Jabatan = "<<jab<<endl;
cout<<"Gaji Pokok = "<<gapok<<endl;
getch();
}
Lampiran Tugas 4 Menggunakan Borland C++
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
void main()
{
char kode,ukuran,merk[15]="None";
long harga=0;
cout<<"Kode Baju [1/2] : ";cin>>kode;
cout<<"Ukuran [S/M] : ";cin>>ukuran;
if(kode=='1')
{
strcpy(merk," NIKE");
if (ukuran=='S' || ukuran =='s') { harga=53000; } else { harga=85000; }
}
else if(kode=='2')
{
strcpy(merk," PUMA");
//Bentuk penulisan if versi singkat
if (ukuran=='S' || ukuran =='s') harga=45000; else harga=80000;
}
else
{
cout<<"Salah Kode Baju"<<endl;
}
cout<<"Merk Baju : "<<merk<<endl;
cout<<"Harga Baju : "<<harga<<endl;
getch();
}
Sekian dan Terimakasih.
Wassalamualaikum wr.wb
Warning : Not Copyright !

.png)
.png)
.png)
.png)
.png)
.png)
.png)
Komentar
Posting Komentar