Jump to content
Sign in to follow this  
khairiez

Tolong Solve Kn C++ Ni.......

Recommended Posts

// input
Tasik Kenyir, 937, 456, 900, 879
Pulau Tioman, 810, 80, 589, 456
Bukit Tinggi, 2500, 900, 6789, 459
..... and so on

//output
----------------------------Annual Malaysian Tourism Report---------------------------
Attraction QT1('09) QT2('09) QT3('09) QT4('09) Total
Tasik Kenyir 937 456 900 879 XXXXX
Pulau Tioman 810 80 589 456 XXXXX
Bukit Tinggi 2500 900 6789 458 XXXXX
......
Total XXXXX XXXX XXXX XXXX XXXXX


// questions
Develop a program that uses an array of structures that store the following information:
- attractionName
- totalVisitors
- visitorsByQuarter

function getData
-loads the data into the array

function visitorByQuarter
-finds the attraction's total visitors for each quarter.

function totalvisitorByAttraction
-find each attraction's yearly number of visitors

function printReport
-print the annual report in the format specified above.

kepada sesiapa yang mahu sudi membantu...... Edited by khairiez90

Share this post


Link to post
Share on other sites
Tolong [b]Solve[/b]? Memang tak dapat la jack.
Kalau tolong tunjuk ajar tu mungkin boleh consider lagi.
Tapi masalahnya sekarang, soalan pun aku tak faham camne nak bantu.
Elok scan je la question paper tu kalau malas nak taip balik.

Share this post


Link to post
Share on other sites
haha... okeyh... kepada sape2 yg phm tu t0long la sementara aku scan kn soalan die... ^_^
masalah nye skang aku nak loop kn string.... string tu
nak store sbg array aku xbape reti la... lg satu kalo string kite call blk mzti die
pggl word pertama.... contoh: aku cin john smith then aku called blk mzti kuar john sahaje..


nie contoh yg aku da buat la...

#include <iostream>
#include <string>
using namespace std;

const int QRTR = 4;

struct Visitors
{
string attractionName[3];
long totalVisitors;
int visitorByQuarter[QRTR];
};

void getData(Visitors &);
void printReport(Visitors &);


int main()
{
Visitors v;

getData(v);
printReport(v);

system ("pause");
return 0;
}

void getData(Visitors &x) // yg ni utk input data
{

for (int a = 0; a < 3; a++)
{
cout << "Please insert your attraction name: ";
cin >> x.attractionName[a]; // yg ni confius
for (int b = 0; b < QRTR; b++)
{
cout << "Please insert your quarter " << (1 + B) << ": ";
cin >> x.visitorByQuarter[b];
}
cout << endl;
}

}

void printReport(Visitors &y) // yg nie utk output data
{
for (int c = 0; c < 9; c++)
{
cout << y.attractionName[c] << "\t";
for (int d = 0; d < QRTR; d++)
{
cout << y.visitorByQuarter[d] << " ";
}
cout << endl;
}
}

Share this post


Link to post
Share on other sites
aku tak berapa nak ingat about coding C++ ni.. tapi kalau ko nak retrieve String yang akan ada space tak boleh pakai [b]cin[/b] tu.. kena pakai buffer.. or ada yang coding [b]getline[/b]

maaf la kalau tak membantu sangat.. :blush:

EDIT:
kalau boleh buh dalam code snippet coding tu.. :) Edited by ahaksz28

Share this post


Link to post
Share on other sites
[quote name='khairiez90' date='16 February 2010 - 10:03 AM' timestamp='1266285801' post='1016953']
oo.. tu la pasal.. kene pkai getline... tp x tau carenye.... puas selak buku tony gaddis nie...
huhuhu...

nak buat snippet tu mcm ne plak?
[/quote]

snippet maksud aku code yang ko paste kat post ko tu buh dalam code tags.. ^_^

lagi proper..and lagi senang nak copy paste dalam compiler kalau ada orang nak tolong.. ;)

btw ni link.. boleh cuba visit [url="http://www.cplusplus.com/reference/string/getline/"]CPlusPlus[/url].. mungkin boleh bantu.. B)

Share this post


Link to post
Share on other sites
oooo..
okeyh3...

thankx... nie pon skang ngah ask google... :lol:

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

const int QRTR = 4;

struct Visitors
{
string attractionName[2];
long totalVisitors;
int visitorByQuarter[QRTR];
};

int getData(Visitors &);
void printReport(Visitors &);


int main()
{
Visitors v;

getData(v);
printReport(v);

system ("pause");
return 0;
}

int getData(Visitors &x) // yg ni utk input data
{

for (int a = 0; a < 2; a++)
{
cout << "Please insert your attraction name: ";
getline(cin, x.attractionName[a]); // yg ni confius
for (int b = 0; b < QRTR; b++)
{
cout << "Please insert your quarter " << (1 + B) << ": ";
cin >> x.visitorByQuarter[b];
cin.ignore();
}
cout << endl;
}

}

void printReport(Visitors &y) // yg nie utk output data
{
for (int c = 0; c < 2; c++)
{
cout << y.attractionName[c] << "\t";
for (int d = 0; d < QRTR; d++)
{
cout << y.visitorByQuarter[d] << " ";
}
cout << endl;
}
}
[/code]

kire nie la last aku update.... bleyh execute n run... thanx kamu semua bg idea..
nie pon aku wat step by step... cari output display mcm ne baru wat care nk input..
x c0mplete nie lg... huhu.. ^_^ Edited by khairiez90

Share this post


Link to post
Share on other sites
[code]void printReport(Visitors &y) // yg nie utk output data
{
for (int c = 0; c < 2; c++)
{
cout << y.attractionName[c] << "\t";
for (int d = 0; d < QRTR; d++)
{
cout << y.visitorByQuarter[d] << " ";
}
cout << endl;
}
}[/code]

yang nie problem la... input nombor pastu kuar yg same...
mcm ne eh....??

Share this post


Link to post
Share on other sites
[code]
const int QRTR = 4;

struct Visitors
{
string attractionName[2];
long totalVisitors;
int visitorByQuarter[QRTR];
};
[/code]

aku rasa sebab sini kot..constant kan.. Edited by ahaksz28

Share this post


Link to post
Share on other sites
Kalau saya tak salah, ni beberapa kesalahan yang saya jumpa:
[code]int getData(Visitors &x) // yg ni utk input data
{

for (int a = 0; a < 2; a++)
{
cout << "Please insert your attraction name: ";
getline(cin, x.attractionName[a]); // yg ni confius
for (int b = 0; b < QRTR; b++)
{
cout << "Please insert your quarter " << (1 + B) << ": ";
cin >> x.visitorByQuarter[b];
cin.ignore();
}
cout << endl;
}

}[/code]
1. (1 + B), sepatutnya (1 + b). Variable "B" dan "b" tak sama.
2. Takde "return". [b]int[/b] kena ada "return".

Share this post


Link to post
Share on other sites
salam semua.. yg nie jawapan kpada soalan sy yg lepas...

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

struct Visitors
{
string attractionName;
long totalVisitors;
int visitorByQuarter[4];
};

void getData (Visitors []);
int *visitorByQuarter (Visitors []);
void totalVisitorByAttraction (Visitors []);
void printReport (Visitors [], int *, int, string &, int &, string &, int & );
void maxVisitorByQuarter (int *, string &, int &);
void maxVisitorByAttraction (Visitors [], string &, int &);
int getTotal (int *);

int main()
{
Visitors attract[9];
int max_num_attract, max_num_quart;
string max_name_attract, max_name_quart;
int *total_quarter;
int total;

getData (attract);
total_quarter = visitorByQuarter (attract);
totalVisitorByAttraction (attract);
total = getTotal(total_quarter);
maxVisitorByAttraction(attract, max_name_attract, max_num_attract);
maxVisitorByQuarter(total_quarter, max_name_quart, max_num_quart);
printReport(attract, total_quarter, total, max_name_attract, max_num_attract, max_name_quart, max_num_quart);

delete [] total_quarter;
total_quarter = 0;

system ("pause");
return 0;
}


void getData(Visitors v[])
{
ifstream InData ("Report of Malaysian Tourism.txt", ios::in);
for(int x=0; x<9; x++)
{
getline(InData, v[x].attractionName, ',');
for(int y=0; y<4; y++)
{
InData>>v[x].visitorByQuarter[y];
InData.get();
}
}
InData.close();
}


int *visitorByQuarter (Visitors w[])
{
int *qrtr;
qrtr = new int[4];
for(int x=0; x<4; x++)
{
qrtr[x] = 0;
for(int y=0; y<9; y++)
qrtr[x] += w[y].visitorByQuarter[x];
}

return qrtr;
}


void totalVisitorByAttraction (Visitors q[])
{
for(int x=0; x<9; x++)
{
q[x].totalVisitors=0;
for(int y=0; y<4; y++)
q[x].totalVisitors += q[x].visitorByQuarter[y];

}

}


int getTotal (int *gt)
{
int a=0;
for(int x=0; x<4; x++)
a += gt[x];
return a;
}


void maxVisitorByAttraction (Visitors t[], string &k, int &l)
{
int max,num;
max = t[0].totalVisitors;
num = 0;
for(int x=1; x<9; x++)
{
if(t[x].totalVisitors > max)
{
max = t[x].totalVisitors;
num = x;
}
}
k = t[num].attractionName;
l = t[num].totalVisitors;
}


void maxVisitorByQuarter (int *d, string &b, int &c)
{
int max, num;
max = d[0];
num = 0;
for(int x=1; x<4; x++)
{
if(d[x] > max)
{
max = d[x];
num = x;
}
}

switch(num)
{
case 0: b = "QT1('09)";
c = d[0];
break;
case 1: b = "QT2('09)";
c = d[1];
break;
case 2: b = "QT3('09)";
c = d[2];
break;
case 3: b = "QT4('09)";
c = d[3];
break;
}
}


void printReport (Visitors a[], int *tq, int t, string &w, int &y, string &x, int &z)
{
for(int m=0; m<25; m++)
cout<<"-";
cout<<"Annual Malaysian Tourism Report";
for(int m=0; m<24; m++)
cout<<"-";
cout<<left<<setw(20)<<"Attraction";
cout<<setw(12)<<"QT1('09)";
cout<<setw(12)<<"QT2('09)";
cout<<setw(12)<<"QT3('09)";
cout<<setw(12)<<"QT4('09)";
cout<<setw(12)<<"Total";

for(int n=0; n<9; n++)
{
cout<<left<<setw(20)<<a[n].attractionName;
cout<<setw(12)<<a[n].visitorByQuarter[0];
cout<<setw(12)<<a[n].visitorByQuarter[1];
cout<<setw(12)<<a[n].visitorByQuarter[2];
cout<<setw(12)<<a[n].visitorByQuarter[3];
cout<<setw(12)<<a[n].totalVisitors;
}

cout<<left<<setw(20)<<"Total";
cout<<setw(12)<<tq[0];
cout<<setw(12)<<tq[1];
cout<<setw(12)<<tq[2];
cout<<setw(12)<<tq[3];
cout<<setw(12)<<t;

cout<<endl<<endl;

cout<<"Max Number of Visitor by Attraction: " <<w<< ",";
cout<<"Number of Visitor = "<<y<<endl<<endl;

cout<<"Max Number of Visitor by Quarter: Quarter= " <<x<< ",";
cout<<"Number of Visitor = "<<z<<endl<<endl;
}

[/code]

saya ade masalah laen plak.. yg nie sy kene wat projek tentang hotel reservation..
compiler pkai dev c++... yg nie masalahnye, bile masuk input kat address line 2 die akan loop selepas masok input nye...
tolong ye.....

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

class hotel
{
private:
string name, occupation;
int tel_No;
char IC_No[15], address1[51], address2[51];
public:
void showMenu();
void form();
};

void hotel::showMenu()
{
cout << "\t\tHotel Reservation System\n\n";
cout << "1. Booking for room\n";
cout << "2. Display the Information\n";
cout << "3. List of Rooms\n";
cout << "4. Search\n";
cout << "5. Quit the Program\n\n";
cout << "Enter your choice: ";
}

void hotel::form()
{
cout << "Please fill up the information below: \n";
cout << "Name: ";
getline(cin, name);
cin.ignore();
cout << "IC Number: ";
cin.getline(IC_No, 15);
cin.ignore();
cout << "Occupation: ";
getline(cin, occupation);
cin.ignore();
cout << "Address line 1: ";
cin.getline(address1, 51);
cin.ignore();
cout << "Address line 2: ";
cin.getline(address2, 51); <== masuk input die akan loop memanjang..
cin.ignore();
cout << "Telephone No: ";
cin >> tel_No;

cout << "Thank you!\n";
}


int main()
{
hotel reserve;
int choice;

do
{
reserve.showMenu();
cin >> choice;
cout << endl;
while (choice < 1 && choice > 4)
{
cout << "Please enter 1, 2, 3, 4, 5: ";
cin >> choice;
}
if (choice != 4)
{
switch(choice)
{
case 1: reserve.form();
break;
}
}
} while (choice != 5);

system("PAUSE");
return 0;
}

[/code]

Share this post


Link to post
Share on other sites
ni mn satu coding nak discuss nih?
yg psl tasik kenyir ke atau hotel reservation tu?

yg coding psl hotel reservation tu mcm x complete jerk.
aku dah tau sbb apa bila input address line 2 dia berulang.
ms declare tel_no kat class hotel tu x leh jdkan dia sbg int sebaliknya jdkan dia char no_tel[15]

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...
Sign in to follow this  

×
×
  • Create New...