Tugas Algoritma dan Pemrograman / CPP(C++) – Majalah

#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
main()
{
            struct
   {
            char np[20],majalah[15],kode;
      int ambil,kembali,terjual,harga,subtotal;
   }
   laris[20];
   clrscr();
   char hr[15];
   int i,data,tmt=0,tph=0;
   cout<<“\nAGEN MAJALAH \”LARIS MANIS\””<<endl;
   cout<<“__________________________”<<endl<<endl<<endl;
   cout<<“Masukkan Hari   = “;cin>>hr;
   cout<<“Banyak Pengecer = “;cin>>data;
   for(i=1;i<=data;i++)
            {
            cout<<endl;
         cout<<“Transaksi Ke- “<<i<<endl;
         cout<<“Nama Pengecer           = “;cin>>laris[i].np;
         cout<<“Kode Majalah [1/2/3]    = “;cin>>laris[i].kode;
         cout<<“Jumlah Ambil            = “;cin>>laris[i].ambil;
         cout<<“Jumlah Kembali          = “;cin>>laris[i].kembali;
         switch(laris[i].kode)
                                    {
                                                case ‘1’:
                                                strcpy(laris[i].majalah,”GADIS       “);
                                                laris[i].harga=9500;
                                                break;
                                                case ‘2’:
                                                strcpy(laris[i].majalah,”COSMOPOLITAN”);
                                                laris[i].harga=18000;
            break;
            case ‘3’:
            strcpy(laris[i].majalah,”TRUBUS      “);
            laris[i].harga=20000;
                                                break;
                                    }
      }
      clrscr();
      cout<<“\n\n\t\t\tLaporan Pendapatan Harian”<<endl;
      cout<<“\t\t\t_________________________”<<endl<<endl;
            cout<<“Hari : “<<hr<<endl;
         cout<<“_______________________________________________________________________________”<<endl;
         cout<<“No |   Nama    |   Majalah   |   Harga   | Ambil | Kembali | Terjual | Subtotal”<<endl;
         cout<<“_______________________________________________________________________________”<<endl;
   for(i=1;i<=data;i++)
            {
            cout<<” “<<setiosflags(ios::right)<<setw(1)<<i<<”   “;
         cout<<setiosflags(ios::left)<<setw(2)<<laris[i].np<<”      “;
         cout<<setiosflags(ios::left)<<setw(3)<<laris[i].majalah<<”  “;
         cout<<“Rp. “<<setiosflags(ios::left)<<setw(4)<<laris[i].harga<<”      “;
         cout<<setiosflags(ios::left)<<setw(5)<<laris[i].ambil<<”     “;
         cout<<setiosflags(ios::left)<<setw(6)<<laris[i].kembali<<”   “;
         laris[i].terjual=laris[i].ambil-laris[i].kembali;
         cout<<setiosflags(ios::left)<<setw(7)<<laris[i].terjual<<”  “;
         laris[i].subtotal=laris[i].harga*laris[i].terjual;
         cout<<setiosflags(ios::left)<<setw(8)<<laris[i].subtotal<<endl;
         tmt=tmt+laris[i].terjual;
         tph=tph+laris[i].subtotal;
      }
                  cout<<“_______________________________________________________________________________”<<endl;
         cout<<“Total Majalah Terjual Hari Ini = “<<tmt<<endl;
         cout<<“Total Pendapatan Harian        = Rp. “<<tph<<endl<<endl<<endl<<endl<<endl;
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s