Solved

MANY TO MANY ASSOCIATION

Posted on 2003-11-14
8
209 Views
Last Modified: 2012-05-04
hello experts ,

I dont know how to implement two way association in c++ for MANY to MANY association for:

        TEACHERS<----------->STUDENTS

CLASS TEACHER{
PUBLIC:
VOID TEACHER(){
COUT<<"ENTER NAME";
CIN>>NAME;
}
CHAR *NAME;

}

CLASS STUDENT{
VOID SUDENT();
}


========================================


COULD YOU PLZ HELP ME
BECAUSE I HAVE MY FINAL TERM IN NEXT FEW DAYS
THANKS

0
Comment
Question by:zitaescobar
8 Comments
 
LVL 5

Expert Comment

by:g0rath
Comment Utility
We do not do homework, but we can assit if you have made an attempt. More then the code that you've written so far....plan what you want, write some code and then we can help direct you down the right path short of actually writing the code
0
 

Expert Comment

by:fester4
Comment Utility
If you are having trouble visualizing a simple way to do this I can help you out, but this will be psuedo code that is all untested.

For a many to many relationship between Students and Teacher.
What you are saying is the each student can be affiliated with many teachers.
Each teacher can be affiliated with many students.
For this you will need to create a data structure. The easiest to understand and implement, though not the most efficient for this would be using a linked list to implement the relationships.
Build the two classes like this: (I like structs but you can make it all in the class

struct Relation
{
Student *Student;
Student *NextStudent;
Teacher *Teacher;
Teacher *NextTeacher;
}

struct Student
{
Relation *Teacher;
}

struct Teacher
{
Relation *Student;
}

This is by far the fastest way, but what you do is fill in the structs as neccessary and what you will build for each is something as follows:
Student A:
Teacher->Teacher->Teacher->Teacher
(and you would be able to traverse this list)

Teacher B
Student->Student->Student->Student
(traverseable as well)

if you need more help I can give you some better stuff to get started.
0
 
LVL 17

Expert Comment

by:rstaveley
Comment Utility
Use a "real world" analogy to think it through. Consider a filing cabinet in which we had dossiers for students and dossiers for teachers.

First off we start with a bad idea. We say that each student's dossier should contain a dossier for each teacher he is instructed by. We also say that each teacher's dossier should contain a dossier for each student she instructs. It is a bad idea because you can see that we have lots of similar copies of records with dossiers inside dossiers inside dossiers... we realise that we are dealing with an infinite sized storage problem.

Now we decide to use two separate draws in the filing cabinet: one for student dossiers and one for teacher dossiers. Each dossier is given an identifier - perhaps the name or a unique identification number. Each student's dossier contains a list of teachers he is instructed by. Each teacher's folder contains a list of students she instructs. The lists are references to dossiers.

A dossier is analogous to an instance of a class and a list is analogous to... a list!
0
 

Author Comment

by:zitaescobar
Comment Utility
# include<iostream.h>
#include<string.h>
class teacher{
public:
teacher(char *n)
{
      strcpy(name,n);
}
void print()
{
cout<<"name is "<<name<<endl;
}
private:
char name[10];
};

class student{
public:
student(char *n)
{
      strcpy(name,n);
}
void print()
{
cout<<"name is "<<name<<endl;
}
void assign(teacher *tptr)
{
      stdteach=tptr;
}

public:
char name[10];
teacher *stdteach;
};
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:zitaescobar
Comment Utility
hello every one ,
here is the code i have tried for one to one association .
now plz help me convert it in to many to many association .I will appreciate it.
thanks


========================================================
# include<iostream.h>
#include<string.h>
class teacher{
public:
teacher(char *n)
{
      strcpy(name,n);
}
void print()
{
cout<<"name is "<<name<<endl;
}
private:
char name[10];
};

class student{
public:
student(char *n)
{
      strcpy(name,n);
}
void print()
{
cout<<"name is "<<name<<endl;
}
void assign(teacher *tptr)
{
      stdteach=tptr;
}

public:
char name[10];
teacher *stdteach;
};
0
 
LVL 17

Expert Comment

by:rstaveley
Comment Utility
The teacher needs to have a list of students. The student has a pointer to only one teacher. It would be better if teachers and students both had lists.

Rather than using pointers, why not give teachers and students a numeric identifier. You will then need to think of how you can add a list of numeric identifiers.
0
 
LVL 9

Expert Comment

by:tinchos
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ - no points refunded

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0
 

Accepted Solution

by:
modulo earned 0 total points
Comment Utility
PAQed - no points refunded (of 125)

modulo
Community Support Moderator
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now