
23-09-2007, 09:19
|
 |
|
|
חבר מתאריך: 10.06.06
הודעות: 452
|
|
|
בעיה בתוכנית בC++
שלום כתבתי תוכנית שמכילה שני מחלקות אחת זה ציון שיש שם שם וציון. המחלקה השנייה מכילה את שם הסטודנט ואוסף הציונים שלו. עכשיו יש לי בעיה בפונקציה שאמורה לבדוק האם בקורס מסויים יש לסטודנט ציון. כתבתי אותה אך הוא מציג לי שאין לי גישה לבדוק את הפרמטרים כי הם במחלקה אחרת אני מצרף את הקוד אשמח לשמוע תיקונים
הבעיה היא בפונקציה האחרונה.
קוד:
#include<iostream>
usingnamespace std;
#define n 5
class Mark{
protected:
char * name;
int mark;
public:
Mark(){name="NULL";mark=0;};
Mark(char & newname ,int newmark){mark=newmark;name=&newname;};
bool check(char &);//if the name in the list of kyrsis
void setmark(char & newname ,int newmark);
voidoperator=(Mark & );
friend ostream & operator<<(ostream &,const Mark &);
};
bool Mark::check(char &name){
char * kyrs=newchar[n];
for(int i=0;i<n;i++)
cin>>kyrs[i];
for(int i=0;i<n;i++)
if (kyrs[i]==name) returntrue;
returnfalse;
}
void Mark::setmark(char & newname ,int newmark){
if ((newmark<0) || (newmark>101)){
cout<<"error mark"<<endl;
mark=0;
}
if (this->check(newname)==false) {
cout<<"error name"<<endl;
name="NULL";
}
}
void Mark::operator=(Mark & newmark){
mark=newmark.mark;
}
ostream & operator<<(ostream & out,const Mark & a)
{cout<<"the name of the cours:"<<a.name<<endl;
cout<<"the mark of the cours:"<<a.mark<<endl;
return out;
}
class student{
staticint m;
int id;
char * nameStudent;
Mark * pMark;
int numMarks;
public:
student(char & newnameStudent){nameStudent=&newnameStudent;id=m;m++;};
bool checkMark(char &)const;
};
int student::m=0;
bool student::checkMark(char & checkname)const{
for(int i=0;i<numMarks;i++)
if (pMark[i].Mark::check(checkname)==false) {
cout<<"the cours isnt correct"<<endl;
returnfalse;
}
for(int i=0;i<numMarks;i++)
if ((pMark[i].mark!=0) && (pMark[i].name==&checkname))
returntrue;
}
int main()
{
}
_____________________________________

לגלריה
|