Tugas C++
#include<stdio.h>
#include<conio.h>
main()
{
float JJK,upah,n,i;
printf("\nmasukkan jumlah karyawan\t:");
scanf("%f",&n);
for (i=1; i<=n; i++)
{
printf("\njumlah jam kerja\t:");
scanf("%f",&JJK);
if (JJK<=48)
{
upah=JJK*2000;
printf("\nupah karyawan \t\t:Rp.%10.2f",upah);
}
else if(JJK>48)
{
upah=48*2000+(JJK-48)*3000;
printf("\nupah karyawan \t\t:Rp.%10.2f",upah);
}
}
printf("\n\n\n\t\t\t\tichank08@rocketmail.com");
getch();
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#include <stdio.h>
#include <conio.h>
main()
{
printf("menentukan nilai index mahasiswa\n");
char nilai;
int i,n;
printf("\nmasukkan jumlah mahasiswa\t:");
scanf("%d",&n);
for (i=1; i<=n; i++)
{
printf("\nmasukan Nilai Mahasiswa\t:");
scanf("%d",&nilai);
if(nilai>=80)
printf("\n\tindex nilai \"A\"");
else
if(nilai>=70)
printf("\n\tindex nilai \"B\"");
else
if(nilai>=60)
printf("\n\tindex nilai \"C\"");
else
if(nilai>=50)
printf("\n\tindex nilai \"D\"");
else
printf("\n\tindex nilai \"E\"");
}
getch();
printf("\n\n\n\t\t\t\tichank08@rocketmail.com");
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#include <stdio.h>
#define size 100
struct barang{float jml;float harga;};
struct data{char nama[size];struct barang nil;};
struct data bar[size];
void variabel(void);
void decision(void);
void looping(void);
void fungsi(void);
void deret(void);
void string(void);
void pointer(void);
void struktur(void);
int ganjil_call (int x){
if(x%2==0)
return (0);
else
return (1);
}
int go_crazy(int *p1, int *p2){
int x = 5;
int r, q = 7;
r = 12;
*p2 = *p1 * 2;
p1 = &x;
return *p1 * 3;
void
tampil (int *i)
{
int a;
for (a=0;a<*i;a++)
{
printf ("Masukkan Nama Barang: ");
fgets (bar[a].nama,sizeof bar[a].nama,stdin);
fflush(stdin);
printf("Masukkan Jumlah barang : ");
scanf_s("%f", &bar[a].nil.jml);
fflush(stdin);
printf("Masukkan Harga Barang : ");
scanf_s("%f", &bar[a].nil.harga);
fflush(stdin);
printf("\n");
fflush(stdin);
}
for(a=0;a<*i;a++)
{
printf("%d. Nama Barang : %s", a+1, bar[a].nama);
printf(" Total Harga : %g\n", bar[a].nil.jml*bar[a].nil.harga);
printf("\n");
}
}
void print_menu(){
printf ("1.variabel \n");
printf ("2.decision \n");
printf ("3.looping \n");
printf ("4.fungsi \n");
printf ("5.array \n");
printf ("6.string \n");
printf ("7.pointer \n");
printf ("8.struktur \n");
}
void pilihan(){
int pil;
print_menu();
printf ("pilih menu yang di inginkan : ");
scanf_s ("%d",&pil);
puts ("");
if (pil==1){
variabel();
}
else if (pil==2){
decision();
}
else if (pil==3){
looping();
}
else if (pil==4){
fungsi();
}
else if (pil==5){
deret();
}
else if (pil==6){
string();
}
else if (pil==7){
pointer();
}
else if (pil==8){
struktur();
}
else{
pilihan();
}
}
void variabel(){
float harga;
int jml;
printf ("masukkan jumlah barang :");
scanf_s ("%d",&jml);
printf ("masukkan harga :");
scanf_s ("%f",&harga);
harga=(jml*harga*10/100)+jml*harga;
printf ("harga barang+ppn :%.2f\n\n",harga);
}
void decision(){
int validasi=1; //validasi diinisialisaikan=1
char opr;
float bil1,bil2,hsl;
printf ("Kalkulator Sederhana\n");
printf ("Masukkan bilangan 1 :");
scanf_s ("%f",&bil1);
fflush(stdin);
printf ("Masukkan bilangan 2 :");
scanf_s ("%f",&bil2);
fflush(stdin);
printf ("Pilihan operasi\n");
printf ("1.Penjumlahan\n");
printf ("2.Pengurangan\n");
printf ("3.Pembagian\n");
printf ("4.Perkalian\n");
printf ("Masukkan operasi yang anda inginkan :");
scanf_s ("%c",&opr);
if (opr == '1')
hsl= bil1+bil2;
else if (opr== '2')
hsl= bil1-bil2;
else if (opr == '3')
hsl= bil1/bil2;
else if (opr == '4')
hsl= bil1*bil2;
else
validasi=0;
if (validasi)
printf ("Hasil operasi tsb adalah :%g\n",hsl);
else
printf ("Tidak Bisa Dihitung!!!!!.....\n");
}
void looping(){
int n,total=0,bil;
char pil='y';
while(pil=='y'||pil=='Y'){
fflush(stdin);
printf ("masukkan bilangan yang akan di hitung : ");
scanf_s ("%d",&bil);
for( n = 1; n <= bil; n=n+1 )
total=total+n;
printf("jumlah bilangan triangular adalah :%d \n",total);
fflush(stdin);
printf ("ingin menghitung lagi : ");
scanf_s ("%c",&pil);
}
}
void fungsi(){
int m,n;
printf ("Masukkan Sebuah Bilangan : ");
scanf_s ("%d",&n);
m=ganjil_call(n);
if (m==0)
printf ("Bilangan Tersebut Genap\n");
else
printf ("Bilangan Tersebut Ganjil\n");
}
void deret(){
char cocok [size];
int i, x, jumkar;
fflush(stdin);
printf("Masukkan sebuah kalimat : ");
fgets(cocok, sizeof cocok, stdin);
for(i='A'; i<='z'; i++)
{
jumkar = 0;
for(x=0; x<size; x++)
{
if (i==cocok [x])
{
jumkar++;
}
}
if(jumkar!=0)
printf("%c = %d\n", i, jumkar);
}
puts("");
}
void string(){
char kal[size];
int i=0;
fflush(stdin);
printf("Masukkan kalimat yg akan di sandikan :");
fgets(kal, sizeof kal, stdin);
while(kal[i] != '\n')
{
if(kal[i] >= 'A' && kal[i] <'Z')
kal[i] = kal[i] + 1;
else if (kal[i] == 'Z')
kal[i] = 'A';
else if (kal[i] >= 'a' && kal[i] <'z')
kal[i] = kal[i] + 1;
else if (kal[i] == 'z')
kal[i] = 'a';
else if (kal[i] >= '1' && kal[i] < '9')
kal[i] = kal[i] + 1;
else if (kal[i] == '9')
kal[i] = '1';
else if (kal[i] == ' ')
kal[i] = ' ';
i++;
}
printf("Kalimat setelah disandikan adalah :\n");
printf("%s\n", kal);
}
void pointer(){
int r, q = 7;
int *ptr1 = &q;
int *ptr2 = &q;
r = go_crazy(ptr1, ptr2);
printf("q = %d, r = %d, *ptr1 = %d, *ptr2 = %d\n", q, r,*ptr1,*ptr2);
ptr2 = &r;
go_crazy(ptr2, ptr1);
printf("q = %d, r = %d, *ptr1 = %d, *ptr2 = %d\n", q, r,*ptr1,*ptr2);
}
void struktur(){
int n;
printf("Masukkan Banyak Barang : ");
scanf_s("%d",&n);
printf("\n");
fflush(stdin);
tampil(&n);
}
main(){
pilihan();
}
getch();
}}
0 komentar:
Posting Komentar