• Announcements

    • Peraturan Umum, Sila baca !

      1) Perbincangan illegal , seperti download , provide link muat turun, lanun sebagainya ditegah dan akan dipadam tanpa notis. Sila ambil perhatian , sebarang perbincangan mengenai download men-download, sharing link yang berkait kepada illegal material: - akan dipadam serta merta - tiada kompromi, user akan diberi warn jika melakukan kesalahan sama Contoh related : - " aku tengah sedut ni.. sejam lagi siap.. " - " kat mana ko dload laju gile.. aku lagi 14 hari nk siap" 2) Spamming, double pos, smiley semata-mata adalah satu kesalahan besar, elakkan membuat susulan pos dibawah susulan sendiri. Warning tanpa notis akan diberikan. 3) Elakkan drama fanboyism , samada berkait dengan konsol, permainan pc dan sebagainya 4) Perbincangan private server tidak dibenarkan, namun multiplayer via hamachi group dibenarkan. 5) Cheat codes dibenarkan, tetapi tidak kepada [email protected] 6) Screenshot seeloknya bersaiz 640 x 480 ke bawah, sila gunakan code spoiler sekiranya tidak resize pic anda. 7) One line posting (susulan satu baris) tanpa menjawab persoalan dan tidak memberi apa-apa manfaat dikira sebagai SPAM. SILA GUNAKAN FUNGSI REPORT JIKA TERDAPAT USER/TOPIK YANG MELANGGAR PERATURAN DI ATAS. ____________________________________________________________ _______________________________ .::. Kegagalan mematuhi terma dan syarat boleh mengakibatkan posting anda di padam dan anda mendapat warn level secara percuma .::. ____________________________________________________________ _______________________________
Sign in to follow this  
Followers 0

Tolong Check Kan

7 posts in this topic

Posted · Report post

atucara ni digunakan untuk bagi gred markah n kira purata. ada error dan pada masa yang sama kena masuk polymorphism. camner ek????????aku dh buntu ni.........btw thanks for your help

#include<iostream>
using namespace std;
class Teacher
{
protected:
char stafname[25],stafid[10];
public:
void accept()
{
cout<<"\nEnter your name :"<<endl;
cin>>stafname;
cout<<"\nEnter staffid :"<<endl;
cin>>stafid;
}
};
class Student:public Teacher
{
private:
char Class[3],subject[12],name[25];
int a,bil,mark_bm1[ ],mark_bm2[ ],mark_math[ ],mark_science[ ],mark_bi[ ],total_bm1,total_bm2,total_math,total_science,total_bi;
int average_bm1,average_bm2,average_math,average_science,average_bi;
public:
void Accept();
void display();
};
void Student::Accept()
{
cout<<"\nEnter Class :";
cin>>Class;
cout<<"\nEnter number of student :";
cin>>bil;
for(a=0;a<bil;a++)
{
cout<<"\nEnter student name :";
cin>>name;
cout<<"\nEnter mark for Bahasa Melayu 1 :";
cin>>mark_bm1[a];
cout<<"\nEnter mark for Bahasa Melayu 2 :";
cin>>mark_bm2[a];
cout<<"\nEnter mark for Mathematics :";
cin>>mark_math[a];
cout<<"\nEnter mark for Science:";
cin>>mark_science[a];
cout<<"\nEnter mark for English:";
cin>>mark_bi[a];
total_bm1=total_bm1+mark_bm1[a];
total_bm2=total_bm2+mark_bm2[a];
total_math=total_math+mark_math[a];
total_science=total_science+mark_science[a];
total_bi=total_bi+mark_bi[a];
average_bm1=total_bm1/bil;
average_bm2=total_bm2/bil;
average_math=total_math/bil;
average_science=total_science/bil;
average_bi=total_bi/bil;
}
}
void Student::display()
{
cout<<"\nClass :"<<Class;
cout<<"\t\tBil. Student :"<<bil;
for( a=0;a=bil;a++)
{
if(mark_bm1[a]>=80)
{
cout<<"Name :"<<name;
cout<<"\n\nBahasa Melayu 1 :"<<mark_bm1[a];
cout<<"\tGred A";
}
else if(mark_bm1[a]>59||mark_bm1[a]<80)
{
cout<<"Name :"<<name;
cout<<"\n\nBahasa Melayu 1 :"<<mark_bm1[a];
cout<<"\tGred B";
}
else if(mark_bm1[a]>39||mark_bm1[a]<60)
{
cout<<"Name :"<<name;
cout<<"\n\nBahasa Melayu 1 :"<<mark_bm1[a];
cout<<"\tGred C";
}
else
{
cout<<"Name :"<<name;
cout<<"\n\nBahasa Melayu 1 :"<<mark_bm1[a];
cout<<"\tGred D";
}
if(mark_bm2[a]>=80)
{
cout<<"\n\nBahasa Melayu 2 :"<<mark_bm2[a];
cout<<"\tGred A";
}
else if(mark_bm2[a]>59||mark_bm2[a]<80)
{
cout<<"\n\nBahasa Melayu 2 :"<<mark_bm2[a];
cout<<"\tGred B";
}
else if(mark_bm2[a]>39||mark_bm2[a]<60)
{
cout<<"\n\nBahasa Melayu 2 :"<<mark_bm2[a];
cout<<"\tGred C";
}
else
{
cout<<"\n\nBahasa Melayu 2 :"<<mark_bm2[a];
cout<<"\tGred D";
}
if(mark_math[a]>=80)
{
cout<<"\n\nMathematics :"<<mark_math[a];
cout<<"\tGred A";
}
else if(mark_math[a]>59||mark_math[a]<80)
{
cout<<"\n\nMathematics :"<<mark_math[a];
cout<<"\tGred B";
}
else if(mark_math[a]>39||mark_math[a]<60)
{
cout<<"\n\nMathematics :"<<mark_math[a];
cout<<"\tGred C";
}
else
{
cout<<"\n\nMathematics :"<<mark_math[a];
cout<<"\tGred D";
}
if(mark_science[a]>=80)
{
cout<<"\n\nScience :"<<mark_science[a];
cout<<"\tGred A";
}
else if(mark_science[a]>59||mark_science[a]<80)
{
cout<<"\n\nScience :"<<mark_science[a];
cout<<"\tGred B";
}
else if(mark_science[a]>39||mark_science[a]<60)
{
cout<<"\n\nScience :"<<mark_science[a];
cout<<"\tGred C";
}
else
{
cout<<"\n\nScience :"<<mark_science[a];
cout<<"\tGred D";
}
if(mark_bi[a]>=80)
{
cout<<"\n\nBahasa Inggeris :"<<mark_bi[a];
cout<<"\tGred A";
}
else if(mark_bi[a]>59||mark_bi[a]<80)
{
cout<<"\n\nBahasa Inggeris :"<<mark_bi[a];
cout<<"\tGred B";
}
else if(mark_bi[a]>39||mark_bi[a]<59)
{
cout<<"\n\nBahasa Inggeris :"<<mark_bi[a];
cout<<"\tGred C";
}
else
{
cout<<"\n\nBahasa Inggeris :"<<mark_bi[a];
cout<<"\tGred D";
}
}
cout<<"\n Average for Bahasa Melayu 1:"<<average_bm1;
cout<<"\n Average for Bahasa Melayu 2:"<<average_bm2;
cout<<"\n Average for Mathematics:"<<average_math;
cout<<"\n Average for Science:"<<average_science;
cout<<"\n Average for English is:"<<average_bi;
}
void main()
{
Student obj1;
obj1.accept();
obj1.Accept();
obj1.display();
}

Share this post


Link to post
Share on other sites

Posted · Report post

Rasa musykil bila tengok kod...

[code] int a,bil,mark_bm1[ ],mark_bm2[ ],mark_math[ ],mark_science[ ],mark_bi[ ],total_bm1,total_bm2,total_math,total_science,total_bi;[/code]
mungkin sebab array mark_bm1, mark_bm2, dan lain2 diisytihar tanpa saiz.

Share this post


Link to post
Share on other sites

Posted · Report post

[quote name='syahmixp' timestamp='1300778205' post='1065408']
Rasa musykil bila tengok kod...

[code] int a,bil,mark_bm1[ ],mark_bm2[ ],mark_math[ ],mark_science[ ],mark_bi[ ],total_bm1,total_bm2,total_math,total_science,total_bi;[/code]
mungkin sebab array mark_bm1, mark_bm2, dan lain2 diisytihar tanpa saiz.
[/quote]

maybe..........tapi aku nk wt array yg infinate...........ade cara ke???????

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

tak boleh, array mesti ada saiz.
sila tengok malloc, realloc dan free

[url="http://www.cplusplus.com/reference/clibrary/cstdlib/malloc/"]http://www.cplusplus...cstdlib/malloc/[/url]

ubah mark_*... menjadi integer pointer
[code]int* mark_bm1, mark_bm2, mark_math ...[/code]

sebelum
[code] for(a=0;a<bil;a++)[/code]
letak kod ini untuk allocate memory
[code]mark_bm1 = (int)malloc(sizeof(int)*bil);[/code] Edited by syahmixp

Share this post


Link to post
Share on other sites

Posted · Report post

[quote name='syahmixp' timestamp='1300783519' post='1065416']
tak boleh, array mesti ada saiz.
sila tengok malloc, realloc dan free

[url="http://www.cplusplus.com/reference/clibrary/cstdlib/malloc/"]http://www.cplusplus...cstdlib/malloc/[/url]

ubah mark_*... menjadi integer pointer
[code]int* mark_bm1, mark_bm2, mark_math ...[/code]

sebelum
[code] for(a=0;a<bil;a++)[/code]
letak kod ini untuk allocate memory
[code]mark_bm1 = (int)malloc(sizeof(int)*bil);[/code]
[/quote]



ok............dh try tp ade 6 error..........camni ke???????

#include<iostream>
#include <string>
using namespace std;
using std::string;
class Teacher
{
protected:
char stafname[25],stafid[10];
public:
void accept()
{
cout<<"\nEnter your name :"<<endl;
cin>>stafname;
cout<<"\nEnter staffid :"<<endl;
cin>>stafid;
}
};
class Student:public Teacher
{
private:
char Class[3],subject[12],name[25];
int *mark_bm1[100],*mark_bm2[100],*mark_math[100],*mark_science[100],*mark_bi[100];
int a,bil, total,*average[100];0
public:
void Accept();
void display();
};
void Student::Accept()
{
cout<<"****************SELAMAT DATANG KE**************************";
cout<<"\nSISTEM PENGIRAAN PURATA PERMAKAHAN DAN GRED PELAJAR UPSR";
cout<<"\n*********************************************************";
cout<<"\nEnter Class :";
cin>>Class;
cout<<"\nEnter number of student :";
cin>>bil;
mark_bm1 = (int)malloc(sizeof(int)*bil);
mark_bm2 = (int)malloc(sizeof(int)*bil);
mark_math = (int)malloc(sizeof(int)*bil);
mark_science = (int)malloc(sizeof(int)*bil);
mark_bi = (int)malloc(sizeof(int)*bil);
for(a=0;a<bil;a++)
{
cout<<"\nEnter student name :";
cin>>name;
cout<<"\nEnter mark for Bahasa Melayu 1 :";
cin>>*mark_bm1[a];
cout<<"\nEnter mark for Bahasa Melayu 2 :";
cin>>*mark_bm2[a];
cout<<"\nEnter mark for Mathematics :";
cin>>*mark_math[a];
cout<<"\nEnter mark for Science:";
cin>>*mark_science[a];
cout<<"\nEnter mark for English:";
cin>>*mark_bi[a];
total=*mark_bm1[a]+*mark_bm2[a]+*mark_math[a]+*mark_science[a]+*mark_bi[a];
*average[a]=total/5;

}
}
void Student::display()
{
cout<<"\n==========================================";
cout<<"\nClass :"<<Class;
cout<<"\t\tBil. Student :"<<bil;
for(a=0;a<bil;a++)
{
if(*mark_bm1[a]>=80)
{
cout<<"\nName :"<<name;
cout<<"\n\nBahasa Melayu 1 :"<<*mark_bm1[a];
cout<<"\tGred A";
}
else if(*mark_bm1[a]>59&&*mark_bm1[a]<80)
{
cout<<"\nName :"<<name;
cout<<"\n\nBahasa Melayu 1 :"<<*mark_bm1[a];
cout<<"\tGred B";
}
else if(*mark_bm1[a]>39&&*mark_bm1[a]<60)
{
cout<<"\nName :"<<name;
cout<<"\n\nBahasa Melayu 1 :"<<*mark_bm1[a];
cout<<"\tGred C";
}
else
{
cout<<"\nName :"<<name;
cout<<"\n\nBahasa Melayu 1 :"<<*mark_bm1[a];
cout<<"\tGred D";
}
if(*mark_bm2[a]>=80)
{
cout<<"\n\nBahasa Melayu 2 :"<<*mark_bm2[a];
cout<<"\tGred A";
}
else if(*mark_bm2[a]>59&&*mark_bm2[a]<80)
{
cout<<"\n\nBahasa Melayu 2 :"<<*mark_bm2[a];
cout<<"\tGred B";
}
else if(*mark_bm2[a]>39&&*mark_bm2[a]<60)
{
cout<<"\n\nBahasa Melayu 2 :"<<*mark_bm2[a];
cout<<"\tGred C";
}
else
{
cout<<"\n\nBahasa Melayu 2 :"<<*mark_bm2[a];
cout<<"\tGred D";
}
if(*mark_math[a]>=80)
{
cout<<"\n\nMathematics :"<<*mark_math[a];
cout<<"\t\tGred A";
}
else if(*mark_math[a]>59&&*mark_math[a]<80)
{
cout<<"\n\nMathematics :"<<*mark_math[a];
cout<<"\t\tGred B";
}
else if(*mark_math[a]>39&&*mark_math[a]<60)
{
cout<<"\n\nMathematics :"<<*mark_math[a];
cout<<"\t\tGred C";
}
else
{
cout<<"\n\nMathematics :"<<*mark_math[a];
cout<<"\t\tGred D";
}
if(*mark_science[a]>=80)
{
cout<<"\n\nScience :"<<*mark_science[a];
cout<<"\t\tGred A";
}
else if(*mark_science[a]>59&&*mark_science[a]<80)
{
cout<<"\n\nScience :"<<*mark_science[a];
cout<<"\t\tGred B";
}
else if(*mark_science[a]>39&&*mark_science[a]<60)
{
cout<<"\n\nScience :"<<*mark_science[a];
cout<<"\t\tGred C";
}
else
{
cout<<"\n\nScience :"<<*mark_science[a];
cout<<"\t\tGred D";
}
if(*mark_bi[a]>79)
{
cout<<"\n\nBahasa Inggeris :"<<*mark_bi[a];
cout<<"\tGred A";
}
else if(*mark_bi[a]>59&&*mark_bi[a]<80)
{
cout<<"\n\nBahasa Inggeris :"<<*mark_bi[a];
cout<<"\tGred B";
}
else if(*mark_bi[a]>39&&*mark_bi[a]<59)
{
cout<<"\n\nBahasa Inggeris :"<<*mark_bi[a];
cout<<"\tGred C";
}
else
{
cout<<"\n\nBahasa Inggeris :"<<*mark_bi[a];
cout<<"\tGred D";
}
cout<<"\n\nAverage :"<<*average[a];
}
cout<<"\n==========================================";

}
void main()
{
Student obj1;
obj1.accept();
obj1.Accept();
obj1.display();
}

Share this post


Link to post
Share on other sites

Posted · Report post

Hee, bukan macam tu...

Kod yang lain semuanya masih sama. Yang perlu diubah cuma semasa isytihar sahaja:
[code]int a,bil,mark_bm1[ ],mark_bm2[ ],mark_math[ ],mark_science[ ],mark_bi[ ],total_bm1,total_bm2,total_math,total_science,total_bi;[/code]menjadi
[code]int a,bil, total_bm1,total_bm2,total_math,total_science,total_bi; // ini adalah integer
int *mark_bm1, *mark_bm2, *mark_math, *mark_science, *mark_bi; // ini adalah integer pointer yang AKAN mengandungi alamat nilai sebenar
// kod dipisahkan supaya mudah baca[/code]

Kemudian sediakan satu ruang pada memori untuk penunjuk tatasusunan tadi (yang ini betul)
[code]mark_bm1 = (int)malloc(sizeof(int)*bil);
mark_bm2 = (int)malloc(sizeof(int)*bil);
mark_math = (int)malloc(sizeof(int)*bil);
mark_science = (int)malloc(sizeof(int)*bil);
mark_bi = (int)malloc(sizeof(int)*bil);[/code]

Kemudian yang lain2 semuanya masih sama seperti kod asal, contohnya:
[code]cout<<"\nEnter mark for Bahasa Melayu 1 :";
cin>>mark_bm1[a];[/code]

Kemudian apabila tamat metod, bebaskan memori yang digunakan tadi supaya bahagian memori tersebut dapat digunakan semula dan mencegah pembaziran memori:
[code]free(mark_bm1);
free(mark_bm2);
// seterusnya[/code]
letak dihujung metod

Dan lagi satu, saya tak pernah compile pun aturcara anda. Jadi minta maaf ye kalau masih ada yang silap. hehe
Dan lagi satu, kod-kod aturcara elok diletak dalam code snippet supaya mudah dibaca [code][code]Kod disini[/code ][/code]

Share this post


Link to post
Share on other sites

Posted · Report post

polymorphism == pewarisan.

so mesti ada base class n derive class. base class + derive class = polymorphism.

p/s: ada ms nanti aku alter code ko nih..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0