Jump to content
Mohamad Afiza

Array

Recommended Posts

Salam.Tajuk Array ini saya banyak tak faham, sesiapa dapat totong saya buat program ini? Terima kasih!
*Guna program Turbo C++ 4.5

[IMG]http://i291.photobucket.com/albums/ll311/afizaex/Awam/IMAG0001.jpg[/IMG]

[IMG]http://i291.photobucket.com/albums/ll311/afizaex/Awam/IMAG0002.jpg[/IMG]

[IMG]http://i291.photobucket.com/albums/ll311/afizaex/Awam/IMAG0004.jpg[/IMG] Edited by Mohamad Afiza

Share this post


Link to post
Share on other sites
[quote name='TOYSЯUS' date='07 October 2010 - 09:09 PM' timestamp='1286456967' post='1049650']
Ni ape, C++?

Hmm, boleh je nak mintak buatkan tapi kene bayar la. Satu line code saya charge singgit. :44:
[/quote]

Ni C++ , software guna Turbo C++ 4.5

line #include<iostream.h> pun kena bayar jugak ka?
line "{" pun kena bayar juga? Kalau buat program satu line saja tak ada wrap boleh?

Share this post


Link to post
Share on other sites
ha'a kena bayar..
semua tu..
even line kosong pun saya charge..
kalau satu line tak ada wrap, lagi mahal la..
ikut length pulak..


hahaha


mana coding yg kamu dah buat sikit, xkan takde..

Share this post


Link to post
Share on other sites
nmpk sgt malasnya.
siap scan soalan assignment sebiji2 lg.
kot nak srh org buat pun olah la skit soalan assignment tu.
x payah la scan sebiji...

Share this post


Link to post
Share on other sites
Tolong betulkan program berdasarkan soalan ini ASAP, outputnya salah.Terima kasih.

[IMG]http://i291.photobucket.com/albums/ll311/afizaex/Awam/IMAG0004.jpg[/IMG]

[code]
#include<iostream.h>
#include<string.h>

int outPatientCharge();
int wardedPatientCharge();

void main()
{
char patient, codeO, codeW[10];
int charges, days;

cout << "Type of patients :" << endl;
cout << "OutPatient(O)" << endl;
cout << "WardedPatient(W)" << endl;
cout << "\nEnter type of patient : ";
cin >> patient;
if (patient == 'O')
{
cout << "\nOutPatient types :" << endl;
cout << "Serious(S)" << endl;
cout << "Mild(M)" << endl;
cout << "Normal(N)" << endl;
cout << "\nEnter OutPatient type code : ";
cin >> codeO;
charges = outPatientCharge();
cout << "\nCharges : RM " << charges << endl;
}
else
if (patient == 'W')
{
cout << "\nWardedPatient types :" << endl;
cout << "Surgery(W001)" << endl;
cout << "Orthopedic(W002)" << endl;
cout << "Medical(W003)" << endl;
cout << "\nEnter OutPatient type code : ";
cin >> codeW;
cin.get (codeW, 10);
cin.ignore (80, '\n');
charges = wardedPatientCharge();
cout << "\nCharges : RM " << charges << endl;
}
else
cout << "\nInvalid type of patient" << endl;
}

int outPatientCharge()
{
int charge;
char codeO;
if (codeO == 'S')
{
charge = 200;
}
else if (codeO == 'M')
{
charge = 100;
}
else if (codeO == 'N')
{
charge = 30;
}
return charge;
}

int wardedPatientCharge()
{
int charge, days;
char codeW[10];
cout << "Number of days : ";
cin >> days;
if (strcmp (codeW, "W001")==0)
charge = 300 * days;
if (strcmp (codeW, "W002")==0)
charge = 250 * days;
if (strcmp (codeW, "W003")==0)
charge = 200 * days;
return charge;
}
[/code]

Share this post


Link to post
Share on other sites
Boleh betulkan, highest price for magazine dalam code di bawah menjadi seperti dalam gambar output ini:
ASAP. Terima kasih.
[img]http://i291.photobucket.com/albums/ll311/afizaex/Awam/IMAG0002.jpg[/img]

[CODE]#include<iostream.h>
#include<string.h>
#include<math.h>



float SumItemPrice(float,int);
float aveStationaryPrice(float, int);



void main()
{

float totalprice[40], pricestationary=0;
int totalstationary=0, totalmagazine=0;
char name[40][30], category[40];
double price[40];
int quantity[40],num_stationary=0,num_magazine=0;
double average=0, priceall=0;
int num_item=0;

cout<<"\tThe Bijak Bistari Shop"<<endl;
cout<<"\tNumber of item : ";
cin>>num_item;
cout<<endl;

cin.ignore(80,'\n');

for(int i=0; i<num_item; i++)
{
cout<<"\tItem : ";
cin.get(name[i],30);
cin.ignore(80,'\n');

cout<<"\tCategory : ";
cin>>category[i];
cin.ignore(80,'\n');

cout<<"\tPrice (RM) : ";
cin>>price[i];
cin.ignore(80,'\n');

cout<<"\tQuantity : ";
cin>>quantity[i];
cin.ignore(80,'\n');



totalprice[i]=SumItemPrice(price[i],quantity[i]);

cout<<"\tTotal Price (RM) : "<<totalprice[i]<<endl;
cout<<endl;

if( category[i]=='S' )
{
num_stationary++;
totalstationary=totalstationary+totalprice[i];
pricestationary=pricestationary+price[i];
}

else if ( category[i]=='M')
{
num_magazine++;
totalmagazine=totalmagazine+totalprice[i];
}
}

cout<<"\tThe total number of stationary\t\t: "<<num_stationary<<endl;
cout<<"\tThe total number of magazine \t\t: "<<num_magazine<<endl;
cout<<endl;



average=aveStationaryPrice(pricestationary,num_stationary);

cout<<"\tThe average price for stationary \t: RM "<<average<<endl;
cout<<endl;


double max=totalprice[0];
for(i=0; i<num_magazine; i++)
{
if(totalprice[i]>max)
max=totalprice[i];
}




int index=0;

for(i=0; i<num_item; i++)
{
if(category[i]=='M')
{
if(max==totalprice[i])
index=i;
}
}




cout<<"\tThe highest price for magazine :"<<endl;
cout<<"\tItem\t\t\t: "<<name[index]<<endl;
cout<<"\tCategory\t\t: "<<category[index]<<endl;
cout<<"\tPrice (RM)\t\t: "<<price[index]<<endl;
cout<<endl;


priceall=totalstationary+totalmagazine;

cout<<"\tThe total price of stationary : RM "<<totalstationary<<endl;
cout<<"\tThe total price of magazine : RM "<<totalmagazine<<endl;
cout<<"\tThe total price of all item : RM "<<priceall<<endl;

}




float SumItemPrice(float price,int quantity)
{
float totalprice;
totalprice=price*quantity;
return totalprice;
}





float aveStationaryPrice(float priceOfStationary, int NumberOfStationary)
{
float average;
average=priceOfStationary / NumberOfStationary;
return average;
}[/CODE] Edited by Mohamad Afiza

Share this post


Link to post
Share on other sites
amboi sesedap mak yeh je mamat ni srh org siapkan assignment dia sblm ptg ni.
nak cepat boleh tp biasa la mesti ada pengerasnya.
nah amik jawapan soalan no 2 ni dulu.
rajin2 aku wat yg no 1 nya laks.

[code]
#include<iostream>
using namespace std;

int outPatientCharge(char x);
int wardedPatientCharge(char y, int z);

void main()
{
char patient, code0, code1[4];
int days;

cout<<"Type of patients :"<<endl;
cout<<"OutPatient (O)"<<endl;
cout<<"WardedPatient (W)"<< endl;
cout<<"Enter type of patient : ";
cin>>patient;

if (patient == 'O' || patient == 'o')
{
cout<<"\nOutPatient types :"<<endl;
cout<<"Serious (S)"<<endl;
cout<<"Mild (M)"<<endl;
cout<<"Normal (N)"<<endl;
cout<<"Enter OutPatient type code : ";
cin>>code0;
cout<<"\nCharges : RM "<<outPatientCharge(code0)<<endl;
}

else if (patient == 'W' || patient == 'w')
{
cout<<"\nWardedPatient types :"<< endl;
cout<<"Surgery (W001)"<<endl;
cout<<"Orthopedic (W002)"<<endl;
cout<<"Medical (W003)"<<endl;
cout<<"Enter OutPatient type code : ";
cin>>code1;
cout<<"Number of days : ";
cin>> days;
cout<<"\nCharges : RM "<<wardedPatientCharge(code1[3], days)<<endl;
}

else cout<<"\nInvalid type of patient"<<endl;
}

int outPatientCharge(char x)
{
int charge;
if (x == 'S' || x == 's') charge = 200;
else if (x == 'M' || x == 'm') charge = 100;
else if (x == 'N' || x == 'n') charge = 30;
return charge;
}

int wardedPatientCharge(char y, int z)
{
int charge;

/*cout<<"Jumlah hari ialah "<<z<<endl;
cout<<"data y ialah "<<y;*/

if (y == '1') charge = 300*z;
else if (y == '2') charge = 250*z;
else if (y == '3') charge = 200*z;
return charge;
}
[/code] Edited by otai_g

Share this post


Link to post
Share on other sites
[quote name='otai_g' date='11 October 2010 - 10:23 PM' timestamp='1286806984' post='1049879']
amboi sesedap mak yeh je mamat ni srh org siapkan assignment dia sblm ptg ni.
nak cepat boleh tp biasa la mesti ada pengerasnya.
nah amik jawapan soalan no 2 ni dulu.
rajin2 aku wat yg no 1 nya laks.[/quote]

Minta maaf la sebab kalut nak siap cepat. Terima kasih atas repair code 2. :-)

Share this post


Link to post
Share on other sites
this answer 4 another questions.
but have some main tipu sikit.
try find by urself ;)

[code]
#include <iostream>
#include <string>
using namespace std;

double sumItemPrice(double p, int q) { return (p*q); }
float aveStationaryPrice(double a, int B) { return (a/B); }
float highestMagazinePrice(double z, int Zz);

void main()
{
int num_item, squantity=0, kambenk;
double* price;
double* quantity;
double* tprice;
char category;
//char* name[128];
double tsprice=0, sprice=0, mprice=0;
string* name;

cout<<"The Bijak Bistari Shop"<<endl;
cout<<"Number of item : ";
cin>>num_item;

price= new double[num_item];
quantity= new double[num_item];
tprice= new double[num_item];
name= new string[num_item];

for(int i=0; i<num_item; i++)
{
cout<<"\nItem: ";
cin>>name[i];
cin.ignore(128,'\n');

cout<<"Category: ";
cin>>category;

cout<<"Price (RM): ";
cin>>price[i];

cout<<"Quantity: ";
cin>>quantity[i];

cout<<"Total Price (RM): "<<sumItemPrice(price[i], quantity[i]);
cout<<endl;

if (category=='S' || category=='s')
{
sprice = sprice+sumItemPrice(price[i], quantity[i]);
tsprice = tsprice + price[i];
squantity++;
}

else if (category=='M' || category=='m')
{
kambenk = highestMagazinePrice(price[i], i);
mprice = mprice+sumItemPrice(price[i], quantity[i]);
}
}

cout<<"\nThe total number of stationary : "<<squantity<<endl;
cout<<"The total number of magazine : "<<(num_item-squantity)<<endl;
cout<<"\nThe average price of stationary : RM "<<aveStationaryPrice(tsprice, squantity)<<endl;
cout<<"\nThe highest price for magazine:"<<endl;
cout<<"Item : "<<name[kambenk]<<endl;
cout<<"Category : M"<<endl;
cout<<"Price : "<<price[kambenk]<<endl;

cout<<"\nThe total price of stationary : RM "<<sprice<<endl;
cout<<"The total price of magazine : RM "<<mprice<<endl;
cout<<"The total price of all item : RM "<<(sprice+mprice)<<endl;

}


float highestMagazinePrice (double z, int zZ)
{
double hprice=0;
int index;

if (z > hprice)
{
hprice = z;
index = zZ;
}

return index;
}
[/code]

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...