Selasa, 25 Maret 2014

Program TPT1



Soal ke 1 :
Buatlah program untuk menentukan harga makanan dari promosi “Paket Menu Makanan” yang ditawarkan di rumah makan mas mono cabang Margonda.
Listing program :
#include<iostream.h>
#include<conio.h>
#include<math.h>
main()
{
            start:
            int Pilihan;
            double P,np,Tot,etj,aj;
            clrscr();
            cout<<"Selamat Datang di Rumah Makan Ayam Bakar Mas Mono\n";
            cout<<"-------------------------------------------------\n";
            cout<<"\n";
            cout<<"Daftar Menu Makanan\n";
            cout<<"~~~~~~~~~~~~~~~~~~~\n";
            cout<<"1.Paket I Miss U 1\n";
            cout<<"2.Paket I Miss U 2\n";
            cout<<"3.Paket I Miss U 3\n";
            cout<<"-------------------\n";
            cout<<"Masukkan Menu Makanan : ";cin>>Pilihan;
            cout<<"-------------------\n";
            switch(Pilihan)
            {
                                                case 1:
                                                cout<<"Paket I Miss U 1\n";
                                    cout<<"~~~~~~~~~~~\n";
                                    cout<<"Harga : Rp25.000,00\n";
                                    cout<<"Berapa Porsi yang Anda Inginkan? : ";cin>>P;
                                    cout<<"--------------\n";
                                    int Tambahan;
                                    cout<<"1. 1 Nasi Putih\n";
                                    cout<<"2. 1 Ayam Bakar\n";
                                    cout<<"3. 1 Milkshake\n";
                                    cout<<"--------------\n";
                                    Tot=(25000*P);
                                    cout<<"Total = Rp"<<Tot<<",00\n";
                                    cout<<"\n";
                                    cout<<"Terima Kasih Telah Mengunjungi Rumah Makan Kami\n";
                                    cout<<"_______________________________________________\n";

                        break;
                        case 2:
                                                cout<<"Paket I Miss U 2\n";
                                    cout<<"~~~~~~~~~~~~\n";
                                    cout<<"Harga : Rp57.000,00\n";
                                    cout<<"Berapa Porsi yang Anda Inginkan? : ";cin>>P;
                                    cout<<"--------------\n";
                                    cout<<"1. 2 Nasi Putih\n";
                                    cout<<"2. 2 Ayam Bakar\n";
                                    cout<<"3. 1 Tumis Tauge\n";
                                    cout<<"4. 2 Milkshake\n";
                                    cout<<"--------------\n";
                                    Tot=(57000*P);
                                    cout<<"Total = Rp"<<Tot<<",00\n";
                                    cout<<"\n";
                                    cout<<"Terima Kasih Telah Mengunjungi Rumah Makan Kami\n";
                                    cout<<"_______________________________________________\n";

                        break;
                        case 3:
                                                cout<<"Paket I Miss U 3\n";
                                    cout<<"~~~~~~~~~~~~\n";
                                    cout<<"Harga : Rp130.000,00\n";
                                    cout<<"Berapa Porsi yang Anda Inginkan? : ";cin>>P;
                                    cout<<"--------------\n";
                                    cout<<"1. 4 Nasi Putih\n";
                                    cout<<"2. 4 Ayam Bakar\n";
                                    cout<<"3. Perkedel\n";
                                    cout<<"4. 2 Tumis Tauge\n";
                                    cout<<"5. 1 Sayur Asem\n";
                                    cout<<"6. 4 Milkshake\n";
                                    cout<<"--------------\n";
                                    Tot=(130000*P);
                                    cout<<"Total = Rp"<<Tot<<",00\n";
                                    cout<<"\n";
                                    cout<<"Terima Kasih Telah Mengunjungi Rumah Makan Kami\n";
                                    cout<<"_______________________________________________\n";

                        break;
            default :
                                                cout<<"Anda Hanya Bisa Memilih Paket Yang Sudah Tersedia. (Pilih 1-3)!!!\n";
            break;
            }
                                                getch();
            goto start;
}


 









                                 



Output Soal ke 1 :
Soal ke 2 :
Buatlah program  untuk membaca string yang diinput melalui keyboard dengan tampilan sebagai berikut :
Contoh : masukan string yang akan dibaca: JAKARTA
Output String : JAKARTA
                 AKARTA
     KARTA
     ARTA
     RTA
     TA
     A

Listing Program :
#include<iostream.h>
#include<conio.h>
#include<string.h>
int main(){start:
int i,j,panjang; char string [80];
clrscr();
cout << "Masukkan string yang akan dibaca : ";
cin >> string;
panjang=strlen(string);
for (i=0;i<panjang;i++)
{
for(j=i;j<panjang;j++)
cout << string[j];
cout << endl;
}
getch();
goto start;
}




Variabel Lokal
#include<iostream.h>
void main ()
{
char nama[30], alamat[40];
int usia;
cout<<”Nama anda : ”;
cin>>nama;
cout<<”Alamat anda : “;
cin>>alamat;
cout<<”Usia anda : “;
cin>>usia;
cout<<”Anda bernama “<<nama<<”, dengan alamat “<<alamat<<”, berumur ”<<usia<<” tahun. “;
}

Variabel Global
#include <iostream.h>
#include <math.h>
main()
{
int a;
float b;
cout << “Masukkan nilai a = “;
cin >> a;
b = sqrt(a);
cout << “akar dari a = ” << b;
}



#include<iostream.h>
void main()
{
 int nilai1, nilai2;
 cout<<"Masukan Nilai 1 : "; cin>>nilai1;
 cout<<"Masukan Nilai 2 : "; cin>>nilai2;
 cout<<endl;
 cout<<nilai1<<"+"<<nilai2<<"= "<<nilai1+nilai2<<endl;
 cout<<nilai1<<"-"<<nilai2<<"= "<<nilai1-nilai2<<endl;
 cout<<nilai1<<"x"<<nilai2<<"= "<<nilai1*nilai2<<endl;
 cout<<nilai1<<"/"<<nilai2<<"= "<<nilai1/nilai2<<endl;
}


Program tugas 1
#include<stdio.h>
#include<conio.h>
int jumlah (int x, int y);
void identitas (void);
int main(void)
{
start:
int x,y;
identitas();
printf("x="); scanf("%d",&x);
printf("y="); scanf("%d",&y);
printf("hasil x+y=%d\n",jumlah(x,y));
printf("tekan enter untuk melanjutkan!");
getche();
goto start;
}
void identitas(void)
{printf("-------------------------------\n");
printf("program penjumlahan bilangan    \n");
printf("dibuat oleh                                                                                                            \n");
printf(" nama:  kelompok 5                                                                            \n");
printf(" NIM :                     5                                                                                                                \n");
printf("---------------------------------\n");}
int jumlah (int x, int y)
{int hasil;
hasil=x+y;
return(hasil);}

Tidak ada komentar:

Posting Komentar