3 Replies - 410 Views - Last Post: 13 June 2011 - 05:54 AM Rate Topic: -----

#1 dalelivingston2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-June 11

question about getting student to work in the main program

Posted 12 June 2011 - 10:35 PM

I have been working on trying to get the student class to work in the main program. Everytime I try it gave me an error about overload Student. I don't understand why. If I could get help it will be good.

#include <iostream>
#include <string>

using namespace std;

class Bio
{
public:
Bio();
Bio(string name, string street, string city, string state, string postalcode);
void print() const;
private:
string name, street, city, state, postalcode;
};

Bio::Bio()
{name = street = city = state = postalcode = "";}

Bio::Bio(string aName, string aStreet, string aCity, string aState, string aPostalcode)
{
	name = aName, street = aStreet, city = aCity, state = aState, postalcode = aPostalcode;
}

void Bio::print() const
{
	cout << name << " : " << street << " : " << city << " : " << state << " : " << postalcode << endl;
}


class Person
{
public:
	Person(Bio &);
	void getBio(Bio &) const;
	void setBio(Bio &);
	virtual void print() const;
	virtual string getTitle() const = 0;
private:
	Bio bio;
};

Person::Person(Bio &z)
{
	bio = z;
}

void Person::getBio(Bio &x) const
{
	x = bio;
}

void Person::setBio(Bio &x)
{
	bio = x;
}

void Person::print() const
{
	bio.print();
}


class Student : public Person
{
public:
	Student (Bio &bio, float gpa, string title);
	void print() const;
	float getGPA() const;
	void setGPA(float);
	string getTitle() const;
private:
	float gpa;
	string title;
};

Student::Student(Bio &bio, float GPA, string title) : Person(bio)
{
	bio = bio;
	gpa = gpa;
	title = title;
}

float Student::getGPA() const
{ return gpa;
}

void Student::setGPA(float GPA)
{
	gpa = GPA;
}

void Student::print() const
{
	cout << "Student starts out : Student bio for";
}


string Student::getTitle() const
{
	return title;
}


int main()
{
	cout << "Creating Bio Object for John Smith" << endl;
	Bio a("John Smith","123 Main St.", "Chicago", "IL", "12345");
	a.print();
	cout << "Changed bio for prof object." << endl;
	Bio b ("Nana Liu", "3000 N. Campbell Ave", "Chicago", "IL", "60618");
	b.print();
	return 0;
}



MOD EDIT: Fixed code tags. The right way to use code tags:

:code:

This post has been edited by JackOfAllTrades: 13 June 2011 - 03:07 AM


Is This A Good Question/Topic? 0
  • +

Replies To: question about getting student to work in the main program

#2 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 614
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: question about getting student to work in the main program

Posted 13 June 2011 - 12:15 AM

It compiles just fine for me in G++, it would help if you post your errors exactly as they appear and tell us what compiler you're using.
Was This Post Helpful? 0
  • +
  • -

#3 RetardedGenius  Icon User is offline

  • >>──(Knee)──►
  • member icon

Reputation: 126
  • View blog
  • Posts: 555
  • Joined: 30-October 10

Re: question about getting student to work in the main program

Posted 13 June 2011 - 03:04 AM

[code] [ /code] tags would be nice! :rockon:
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is online

  • member icon


Reputation: 4013
  • View blog
  • Posts: 12,384
  • Joined: 25-December 09

Re: question about getting student to work in the main program

Posted 13 June 2011 - 05:54 AM

Quote

Everytime I try it gave me an error about overload Student.

Please show the code where you try to use the Student class along with the entire error messages exactly as they appear in your development environment.

Also you may want to look at these warnings I get when I compile the above code.

Quote

main.cpp||In constructor ‘Student::Student(Bio&, float, std::string)’:|
main.cpp|76|warning: declaration of ‘title’ shadows a member of 'this'|
main.cpp|76|warning: declaration of ‘bio’ shadows a member of 'this'|

Your constructor parameters have the same name as the member variables, you should rename your parameters so you don't get this conflict.

Also these warnings:

Quote

main.cpp|31|warning: ‘class Person’ has virtual functions and accessible non-virtual destructor|
main.cpp||In constructor ‘Person::Person(Bio&)’:|
main.cpp|42|warning: ‘Person::bio’ should be initialized in the member initialization list|
main.cpp|64|warning: ‘class Student’ has virtual functions and accessible non-virtual destructor|

If you have virtual members your destructor should also be virtual.

Jim
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1