Assalamu'alaikum wr.wb
Lampiran Tugas Progaming Basic Algoritma
Nama : salman alfaridzi
NIM : 3420210017
Prodi : Teknik Informatika
Tugas 1
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
#include <string.h>
//Nama: salman alfaridzi
//NIM: 3420210017
//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 ujian!."; }
else
{ cout<<"Maaf anda tidak lulus!."; }
getch();
}
Tugas 2
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <iostream.h>
//Nama = salman alfaridzi
//NIM = 3420210017
//Prodi = Teknik Informatika
void main()
{
int pilih;
char huruf[25];
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();
}
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();
}
}
Tugas 3
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
//Nama = salman alfaridzi
//NIM = 3420210017
//Prodi = Teknik Informatika
void main()
{
char gol,jab[25];
long gapok;
cout<<endl<<"Data Pegawai coffee shop"<<endl
<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl;
cout<<"Masukan Golongan [1/2/3]: ";cin>>gol;
if(gol=='1')
{
strcpy(jab,"barista");
gapok= 4500000;
}
else if(gol=='2')
{
strcpy(jab,"Kasir");
gapok= 1000000;
}
else if(gol=='3')
{
strcpy(jab,"waiters");
gapok= 2100000;
}
else
{
printf("Golongan %c tidak terdaftar.\n",gol);
strcpy(jab,"None");
gapok=0;
}
cout<<"Jabatan = "<<jab<<endl;
cout<<"Gaji Pokok = "<<gapok<<endl;
getch();
}
Tugas 4
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
//Nama = salman alfaridzi
//NIM = 3420210017
//Prodi = Teknik Informatika
void main()
{
char kode,ukuran,merk[15]="None";
long harga=0;
cout<<"pilih pakaian muslim [1/2] : ";cin>>kode;
cout<<"Ukuran [S/M/L] : ";cin>>ukuran;
if(kode=='1')
{
strcpy(merk,"gamis");
if (ukuran=='S' || ukuran =='s') { harga=275000; } else { harga=310000; }
if (ukuran=='M' || ukuran =='m') { harga=290000; } else { harga=330000; }
if (ukuran=='L' || ukuran =='l') { harga=350000; } else { harga=400000; }
}
else if(kode=='2')
{
strcpy(merk,"baju koko");
//Bentuk penulisan if versi singkat
if (ukuran=='S' || ukuran =='s') { harga=100000; } else { harga=120000; }
if (ukuran=='M' || ukuran =='m') { harga=115000; } else { harga=135000; }
if (ukuran=='L' || ukuran =='l') { harga=130000; } else { harga=150000; }
}
else
{
cout<<"Salah pakaian muslim"<<endl;
}
cout<<"Merk Baju : "<<merk<<endl;
cout<<"Harga Baju : "<<harga<<endl;
getch();
}
Komentar
Posting Komentar