Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Dynamic Linked List

[es] :: C/C++ programiranje :: Dynamic Linked List

[ Pregleda: 4303 | Odgovora: 4 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

ouros
Seattle, WA

Član broj: 342
Poruke: 275
*.uv2a.csupomona.edu

ICQ: 83493423


Profil

icon Dynamic Linked List09.03.2002. u 21:07 - pre 269 meseci
Treba mi pomoc. Imam 2 klase za sada.
Base class : Person
Derived class : Student

Treba da uradim dynamic linked list. Znaci trebaju mi funkcije tipa Add Student, Delete Student, List Students ....

Jel te funkcije treba da stavim u Student class-u ili u Person class-u.
Hteo bih da uradim BEZ templates, pa ako moze neko da mi pomogne. Otprilike znam kako da se krecem kroz listu, ali ne znam kako da pocnem :(

ovako izgledaju klase

class Person
{
friend ostream &operator <<(ostream &, const Person &);

public:
Person(char *, char *, char *);
//~Person(); //Use default destructor.
void setName(char *);
const char *getName();
void setAddress(char *);
const char *getAddress();
void setSSN(char *);
const char *getSSN();

private:
char name[40]; //Person's name
char address[60]; //Person's Address
char SSN[12]; //Person's Social Security Number
};



class Student : public Person
{
friend ostream &operator <<(ostream &, const Student &); //Allows us to print a student.

public:
Student(char *, char *, char *, char *, float, int);
void setMajor(char *);
const char *getMajor();
void setGPA(float);
float getGPA();
void setGraduationYear(int);
int getGraduationYear();
void setNextStudent(Student *);
Student *getNextStudent();

private:
char major[5];
float GPA;
int graduationYear; //4 digit year of graduation (eg. 2004)
Student *nextStudent; //Pointer to next student in list.
};


Hvala vam puno
Uros
 
Odgovor na temu

Dragi Tata
Malo ispod Kanade

Član broj: 1958
Poruke: 3906
..g-c5300-1.dialup.nethere.net



+6 Profil

icon Re: Dynamic Linked List09.03.2002. u 21:46 - pre 269 meseci
Hmmm, pa ja bih napravio posebnu klasu

Code:

class CStudentsList
{
Student* head;
Student* current;
public:
CStudentList() {}
~CStudentList() {}
void AddStudent (Student* newStudent) 
{
  newStudent->SetNextStudent(current->GetNextStudent);
  current->SetNextStudent(newStudent);
}

... itd
};


[Ovu poruku je menjao Dragi Tata dana 09.03.2002 u 07:41 PM GMT]
 
Odgovor na temu

ouros
Seattle, WA

Član broj: 342
Poruke: 275
*.uv2a.csupomona.edu

ICQ: 83493423


Profil

icon Re: Dynamic Linked List09.03.2002. u 21:57 - pre 269 meseci
I jel bi ova class-a

class CStudentsList

bila friend class-i Student ili ne ?


 
Odgovor na temu

Dragi Tata
Malo ispod Kanade

Član broj: 1958
Poruke: 3906
..g-c5300-1.dialup.nethere.net



+6 Profil

icon Re: Dynamic Linked List09.03.2002. u 22:04 - pre 269 meseci
Citat:
ouros:
I jel bi ova class-a

class CStudentsList

bila friend class-i Student ili ne ?



Nema potrebe, pošto si deklarisao setNextStudent(Student *) i getNextStudent() kao public.
 
Odgovor na temu

ouros
Seattle, WA

Član broj: 342
Poruke: 275
*.uv2a.csupomona.edu

ICQ: 83493423


Profil

icon Re: Dynamic Linked List09.03.2002. u 23:39 - pre 269 meseci

I dalje imam poteskoca. Jel ima neki site gde bih mogao da vidim primer ali da se koriste CLASS-e, a ne STRUCT.
Sve sto sam nasao na netu je bilo sa struct-om :(

 
Odgovor na temu

[es] :: C/C++ programiranje :: Dynamic Linked List

[ Pregleda: 4303 | Odgovora: 4 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.