Penulis Topik: [C++] Box Division (%)  (Dibaca 10545 kali)

Offline Zai

  • Admin
  • Pro500
  • *******
  • Tulisan: 2.892
  • Reputation: 58629
  • Jenis kelamin: Pria
    • Lihat Profil
    • Zainuddin Nafarin Blog
[C++] Box Division (%)
« pada: Januari 20, 2010, 07:47:17 PM »
Algo-1 buatan saya sendiri
Algo-2, algo dari buku Ivon Horton (kurang maksimal)

Kode: [Pilih]
#include <iostream>

using namespace std;

int divbox (double a_lwv[6], int algo = 1);

int main()
{
double theboxes[6];
int i;
char exit_y;

do
{
for (i=0;i<=5;i++)
{
cout << "Enter input(" << i << ") = ";
cin >> theboxes[i];
cout << endl;
}

cout << "Max div box = " << divbox(theboxes) << endl;
cout << "Horton div box = " << divbox(theboxes,2) << endl;

cout << endl << "Exit (y) ? " ;
cin >> exit_y;

} while (exit_y != 'y');

return 0;
}

int divbox (double a_lwv[6], int algo)
{
int i,j;
int maxbox = 0, trialbox;
double lwv[3] = {a_lwv[0], a_lwv[1], a_lwv[2]};

if (algo==1)
{
for (i=0;i<=2;i++)
for (j=0;j<=2;j++)
if (i != j)
if (maxbox < (trialbox = static_cast<int>(lwv[i]/a_lwv[3]) *
static_cast<int>(lwv[j]/a_lwv[4]) *
static_cast<int>(lwv[3-(i+j)]/a_lwv[5])))
maxbox = trialbox;
} else {
int tc1 = 0;
int tc2 = 0;

tc1 = static_cast<int>(lwv[0]/a_lwv[3])*
  static_cast<int>(lwv[1]/a_lwv[4]);

tc1 = static_cast<int>(lwv[0]/a_lwv[4])*
  static_cast<int>(lwv[1]/a_lwv[3]);

maxbox = static_cast<int>(lwv[2]/a_lwv[5])*
(tc1>tc2?tc1:tc2);
}

return maxbox;

}

4 main functions of Smadav :
(1) Additional protection for your PC, 100% compatible with other Antivirus!
(2) Best USB Antivirus, no more infection from USB!
(3) Best for offline use and low resource Antivirus
(4) Manual cleaner & tools to fight malwares