ALGORITMA DAN STRUKTUR DATA
Nama = VIRA AZIZAH
NIM = 3420210007
Prodi = Teknik Informatika
Lampiran Tugas 1 Menggunakan Borland C++
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
//Nama = Vira Azizah
//NIM = 3420210007
//Prodi = Teknik Informatika
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>
//Nama = Vira Azizah
//NIM = 3420210007
//Prodi = Teknik Informatika
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;
getch();
}
else
{
printf("Maaf pilihan anda anda salah..");
getch();
}
Lampiran Tugas 3 Menggunakan Borland C++
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
//Nama = Vira Azizah
//NIM = 3420210007
//Prodi = Teknik Informatika
void main()
{
char gol,jab[25];
long gapok;
cout<<endl<<"Struktur Sekolah"<<endl
<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "<<endl;
cout<<"Masukan Golongan [1/2]: ";cin>>gol;
if(gol=='1')
{
strcpy(jab,"Kepala Sekolah");
gapok=10000000;
}
else if(gol=='2')
{
strcpy(jab,"Guru");
gapok=9000000;
}
else
{
printf("Golongan %c tidak terdaftar.\n",gol);
strcpy(jab,"None");
gapok=0;
}
cout<<"Struktur Sekolah = "<<jab<<endl;
cout<<"Gaji Pokok = "<<gapok<<endl;
getch();
}
Lampiran Tugas 4 Menggunakan Borland C++
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
//Nama = Vira Azizah
//NIM = 3420210007
//Prodi = Teknik Informatika
void main()
{
char kode,RAM,merk[15]="None";
long harga=0;
cout<<"Kode Handphone [1/2] : ";cin>>kode;
cout<<"RAM [6/8] : ";cin>>RAM;
if(kode=='1')
{
strcpy(merk," Samsung");
if (RAM=='6' || RAM =='6') { harga=5300000; } else { harga=8500000; }
}
else if(kode=='2')
{
strcpy(merk," Pocco");
//Bentuk penulisan if versi singkat
if (RAM=='8' || RAM =='8') harga=6500000; else harga=10000000;
}
else
{
cout<<"Salah Kode Handphone"<<endl;
}
cout<<"Merk Handphone : "<<merk<<endl;
cout<<"Harga Handphone : "<<harga<<endl;
getch();
}
Sekian dan Terimakasih.
Wassalamualaikum wr.wb
Tidak ada komentar:
Posting Komentar