473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

please i need your help in this program

11
Hi every one :)

would any one help me in this program:
I have a base class called "Person" and two derived classes "Student" and "teacher"
i have a function in class Student called getStudents takes one parameter which is a name and returns an array of objects
that their names similer to the argument.the same function in the class Teachers called getTeachers.
Also, there is a function in another class "School" called getBoth , which takes one parameter " the name" and returns an array of abjects of type Person contains both types and prints their names depending on their type.
i know how i am going to include the classes in the Shool class,all what i want it is the implement of the functions.I tryed to implement it .. but errors occuring spcially in the function getBoth..

please.. i need your help..

class Person{
string name;
public:
string getName(){return name;}
};
class Student : public Person{
Student* getStudents(string name);
}
class Teacher : public Person{
Teacher *getTeachers(string name);
}
class School{
Person* getBoth(string name);
}
Dec 31 '06 #1
3 1679
willakawill
1,646 1GB
Hi every one :)

would any one help me in this program:
I have a base class called "Person" and two derived classes "Student" and "teacher"
i have a function in class Student called getStudents takes one parameter which is a name and returns an array of objects
that their names similer to the argument.the same function in the class Teachers called getTeachers.
Also, there is a function in another class "School" called getBoth , which takes one parameter " the name" and returns an array of abjects of type Person contains both types and prints their names depending on their type.
i know how i am going to include the classes in the Shool class,all what i want it is the implement of the functions.I tryed to implement it .. but errors occuring spcially in the function getBoth..

please.. i need your help..

class Person{
string name;
public:
string getName(){return name;}
};
class Student : public Person{
Student* getStudents(string name);
}
class Teacher : public Person{
Teacher *getTeachers(string name);
}
class School{
Person* getBoth(string name);
}
Hi. Could you please post the code with the errors?
Dec 31 '06 #2
dreams
11
this is the code

Student* School::getStudents(string name)
{
n=0; // global variable used in main to print the array
Student *student;
student = new Student[index1]; //index1 is the number of students
for (int i = 0 ; i<index1 ; i++)
if (students[i]->getName()==name)//students is an array
//contains all students
{
student[n]=*students[i];
n++;
}
return student;
}

Teacher* School::getTeachers(string name)
{
n=0;
Teacher *teacher;
teacher = new Teacher[index2];
for (int i = 0 ; i<index2 ; i++)
if (teacher[i]->geName()==name)
{
teacher[n]=*teachers[i];
n++;
}
return teacher;
}

Person* School::getBoth(string name)
{
Person *person;
index=index1+index2;
person=new Person [index];
for( int i=0; i<index1;i++)
{
if (students[i]->getName()==name)
{

person[index]=*students[i];
index++;
}
for ( int j=0; j<index2; j++)
if (teachers[j]->getName()==name)
{
person[index]=*teachers[j];
index++;
}

}// end for


return person;
}


and the error occur during the run time when i print the array returned from getBoth function in main
i know i cann't store in base class array objects of derived class type and there is away which is use apointer as Person **person but i don't know how to deal with it,, other thing i tryed to use the function getStudents() and getTeachers in the last fuction as an easier way.. but the same error occur.....
thank you :)
Dec 31 '06 #3
Could you please paste the class declarations (including member variable and member functions).

I guess there is a problem in the statment
person[index]=*teachers[j]; /// what do u want to say

If u want u can store derived class object in the base class pointer.

So, it might be a better way to store derived objects in base class array of pointers.

Hope this would help.

Cheers!
Jan 2 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: sunfox | last post by:
Please help!! I have a difficulty in writing an assignment which is related to Visual C++ V6.0. Can anybody here assist me to write a program which is able to run under DOS? The program will be...
7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
2
by: Bsnpr8 | last post by:
I need help guys, i have to many stuff to do, because i am in my last 2 weeks of the university, my last assignment is to do a spell checker in C++, i have an idea but nothing is coming out. I really...
2
by: clouddragon | last post by:
Hi, i am in desperate need for any help regarding one of my assignments. I am to write a python program that lists the numbers that are composite from 1 to n(input) and write it to an external...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.