You are on page 1of 6

#include

#include
#include
#include

"stdafx.h"
<iostream>
<conio.h>
<fstream>

using namespace std;


struct shampoo
{
int amountSizeS; // S-small
int amountSizeL; // L-large
int totalAmount; // total amount of production
double smallCost; // cost of producing small size shampoo for each
type
double largeCost; // cost of producing large size shampoo for each
type
double totalCost; // total cost of production for each type
};
struct search
{
int SamountSizeS[3]; // S-small
int SamountSizeL[3]; // L-large
int StotalAmount[3]; // total amount of production
double SsmallCost[3]; // cost of producing small size shampoo for
each type
double SlargeCost[3]; // cost of producing large size shampoo for
each type
double StotalCost[3]; // total cost of production for each type
}haha[3];

const int ROW=3; // type


const int COL=3; // month
void averageTotalCost(shampoo shampooInfo[][3], int col, int row, ofstream&
keluar)
{
double average=0.0;
for (int u=0; u<col; u++)
{
for (int k=0; k<row; k++)
{
shampooInfo[k][u].totalCost = shampooInfo[k]
[u].smallCost + shampooInfo[k][u].largeCost;
average=average+shampooInfo[k][u].totalCost;

}
}
cout << "Total average cost production : RM " << average/3;
keluar << "Total average cost production :RM " << average/3;
cout << endl;
keluar << endl;

void averageTotalAmount(shampoo shampooInfo[][3], int col, int row,


ofstream& keluar)
{
double averageAmount=0.0;

for (int u=0; u<col; u++)


{
for(int j=0; j<row; j++)
{
shampooInfo[j][u].totalAmount = shampooInfo[j][u].amountSizeL +
shampooInfo[j][u].amountSizeS;
averageAmount = averageAmount+shampooInfo[j][u].totalAmount;
}
}
cout << "Total average amount of production : " << averageAmount/3;
keluar << "Total average amount of production : " << averageAmount/3;
cout << endl;
keluar << endl;
}
void sortSearch(ostream& out,shampoo shampooInfo[][3], int row, int
col,char color[][10], char month[][12],char bulan[10])
{
bool found=false;
int j,h;
for (h=0; h < col; h++)
{
if(strcmp(bulan,month[h])==0)
{
found = true;
int ite,tmp,a[3]={0,1,2};
for (ite=1; ite<ROW; ite++)
{
for ( j=0; j<ROW - ite; j++)
{
if (shampooInfo[h][j].totalCost <
shampooInfo[h][j+1].totalCost)
{
tmp=a[j];
a[j]=a[j+1];
a[j+1]=tmp;
}

}
for ( j=0; j<3; j++)
{
<< endl;

cout << " Colour of Shampoo

: " << color[a[j]]

cout << " Amount for small: " << shampooInfo[h]


[a[j]].amountSizeS << endl;
cout << " Amount for big
[a[j]].amountSizeL << endl;

: " << shampooInfo[h]

cout << " Cost of production of small " <<


color[a[j]] << " shampoo : RM " << shampooInfo[h][a[j]].smallCost<<endl;

cout << " Cost of production of large " <<


color[a[j]] << " shampoo : RM " << shampooInfo[h][a[j]].largeCost <<endl;
cout << " Total amount of production : " <<
shampooInfo[h][a1[j]].totalAmount<< endl;
cout << " Total production cost
shampooInfo[h][a[j]].totalCost << endl;
cout << "\n" << endl;
out << " Colour of Shampoo

<< endl;

: RM " <<

: " << color[a[j]]

out << " Amount for small: " << shampooInfo[h]


[a[j]].amountSizeS << endl;
out << " Amount for big
[a[j]].amountSizeL << endl;

: " << shampooInfo[h]

out << " Cost of production of small " <<


color[a[j]] << " shampoo : RM " << shampooInfo[h][a[j]].smallCost<<endl;
out << " Cost of production of large " <<
color[a[j]] << " shampoo : RM " << shampooInfo[h][a[j]].largeCost

<<endl;

out << " Total amount of production : " <<


shampooInfo[h][a[j]].totalAmount<< endl;
out << " Total production cost
shampooInfo[h][a[j]].totalCost << endl;
}

: RM " <<

out << "\n" << endl;

}
}
if (strcmp(bulan,month[h])==1 || (strcmp(bulan,"n")==1 ||
strcmp(bulan,"N")==1))
cout << "\n Invalid month\n" ;
}
void findLowest(shampoo shampooInfo[][3], int row, int col, char month[]
[12], char color [][10], ofstream& keluar)
{
strcpy_s(month[0],"January");
strcpy_s(month[1],"February");
strcpy_s(month[2],"March");
strcpy_s(color[0],"Blue");
strcpy_s(color[1],"Black");
strcpy_s(color[2],"Green");
double TotalCost [3][3];
for (int a=0; a<col; a++)
{
for (int b=0; b<row; b++ )
{
TotalCost[a][b] = shampooInfo[a][b].totalCost;
}
}

double lowest = TotalCost[0][0];


char lowestMonth [12];
char lowestColour [12];
for (int a=0; a<col; a++)
{
for (int b=0; b<row; b++ )
{
if (TotalCost[a][b] < lowest)
lowest = TotalCost[a][b];
strcpy_s(lowestMonth,month[b]);
strcpy_s(lowestColour,color[b]);
}
}
cout << "The lowest total cost : RM " << lowest << endl;
keluar << "The lowest total cost : RM " << lowest << endl;
}
void findHighest(shampoo shampooInfo[][3], int row,int col,char month[]
[12], char color [][10], ofstream& keluar)
{
strcpy_s(month[0],"January");
strcpy_s(month[1],"February");
strcpy_s(month[2],"March");
strcpy_s(color[0],"Blue");
strcpy_s(color[1],"Black");
strcpy_s(color[2],"Green");
double TotalCost [3][3];
for (int a=0; a<col; a++)
{
for (int b=0; b<row; b++ )
{
TotalCost[a][b] = shampooInfo[a][b].totalCost;
}
}
double highest = TotalCost[0][0];
char highestMonth [12];
char highestColour [12];
for (int a=0; a<col; a++)
{
for (int b=0; b<row; b++ )
{
if (TotalCost[a][b] > highest )
highest = TotalCost[a][b];
}
}
cout << "The highest total cost : RM " << highest << endl;
keluar << "The highest total cost : RM " << highest << endl;
}
int main()
{
shampoo shampooInfo[3][3];
ofstream out;
out.open("receipt.txt");

ofstream keluar;
keluar.open("totalReceipt.txt");
int countMonth=0;
char bulan[10];
char month[3][12];
strcpy_s(month[0],"January");
strcpy_s(month[1],"February");
strcpy_s(month[2],"March");
char color[3][10];
strcpy_s(color[0],"Blue");
strcpy_s(color[1],"Black");
strcpy_s(color[2],"Green");
double priceInput[2];
ifstream input;
input.open("priceInput.txt");
input >> priceInput[0];
input >> priceInput[1];
keluar << " Sinar Rambut Shampoo " << endl;
keluar << " ==================== \n" << endl;
for(int j=0; j < COL; j++)
{
cout << " Month : " << month[j] << endl;
keluar << " Month : " << month[j] << endl;
for(int i=0; i < ROW; i++)
{
cout << " Colour of Shampoo
: " << color[i] << endl;
keluar << " Colour of Shampoo : " << color[i] << endl;
keluar << endl;
cout << " Input amount for small: ";
cin >> shampooInfo[j][i].amountSizeS;
shampooInfo[j][i].smallCost = shampooInfo[j]
[i].amountSizeS * priceInput[0]; // to calculate cost of producig the small
size packaging for each type
keluar << " Amount for small size: " << shampooInfo[j]
[i].amountSizeS;
keluar << endl;
cout << " Input amount for big : ";
cin >> shampooInfo[j][i].amountSizeL;
shampooInfo[j][i].largeCost = shampooInfo[j]
[i].amountSizeL * priceInput[1];
keluar << " Amount for big size: " << shampooInfo[j]
[i].amountSizeL;
keluar << endl;

cout << " Cost of production of small " << color[j] << "
shampooInfo[j][i].smallCost<<endl;
keluar << " Cost of production of small " << color[j] <<
" shampoo : RM " << shampooInfo[j][i].smallCost<<endl;
keluar << endl;
shampoo : RM " <<

cout << " Cost of production of large " << color[j] << "
shampooInfo[j][i].largeCost <<endl;
keluar << " Cost of production of large " << color[j] <<
" shampoo : RM " << shampooInfo[j][i].largeCost <<endl;
keluar << endl;
shampoo : RM " <<

shampooInfo[j][i].totalAmount = shampooInfo[j]
[i].amountSizeL + shampooInfo[j][i].amountSizeS;
cout << " Total amount of production : " <<
shampooInfo[j][i].totalAmount << endl;
keluar << " Total amount of production : " <<
shampooInfo[j][i].totalAmount << endl;
keluar << endl;
shampooInfo[j][i].totalCost = shampooInfo[j][i].smallCost
+ shampooInfo[j][i].largeCost;
cout << "
shampooInfo[j][i].totalCost
keluar <<
shampooInfo[j][i].totalCost
keluar <<

Total production cost


<< endl;
" Total production cost
<< endl;
endl;

: RM " <<
: RM " <<

cout << "\n" << endl;


keluar << "\n" << endl;
}
countMonth++;
}
averageTotalCost(shampooInfo, COL, ROW, keluar);
averageTotalAmount(shampooInfo, COL, ROW, keluar);
findLowest(shampooInfo, ROW, COL, month, color, keluar);
findHighest(shampooInfo, ROW, COL, month, color, keluar);
while (strcmp(bulan,"n")!=0 && strcmp(bulan,"N")!=0 )
{
cout << "Search month : ";
cin >> ws;
cin.getline(bulan,10);
cout << endl;
sortSearch(out,shampooInfo,ROW, COL, color, month,
}
out.close();
keluar.close();
_getch();
return 0;
}

bulan);

You might also like