4 Replies - 368 Views - Last Post: 07 November 2011 - 10:14 PM Rate Topic: -----

#1 yotic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 11-October 11

why does this code not work anymore?

Posted 07 November 2011 - 11:53 AM

#include <iostream>
#include <string>
using namespace std;

class Customer;
class City;


class Customer
{
	protected:
		int number;
		string zipcode;
	public:
		Customer(int, string);

	friend void displayCust(const Customer&, const City&);
};

Customer::Customer(int num = 0, string zcode = "")
{
	number = num;
	zipcode = zcode;
}

class City: public Customer
{
	public:
		string cityname;
		string citystate;
		string zipcode2;
	public:
		City(string, string, string);
	friend void displayCust(const Customer&, const City&);
};

City::City(string cname = "", string cstate = "", string zcode2 = "")
{
	cityname = cname;
	citystate = cstate;
	zipcode2 = zcode2;
}


void displayCust(const Customer& cus, const City& cit)
{
	cout << "the number of customer: ";
	cus.number;
	cout << "\nThe customers city: ";
	cit.cityname;
	cout << "\nThe customers state is: ";
	cit.citystate;
	cout << "\nThe customers zipcode is: ";
	cit.zipcode2;
}

void main()
{
	Customer aCust(1572, "60013");
	City aTown("Cary", "Illinois", "60013");
	displayCust(aCust, aTown);
}



im so confused right now, i dont understand why this code wont work NOW, it worked before and i have not changed it at all, id like to understand why it doesnt work, i matched the public void function up with the friend functions in both the base class and the derived class, it will even output the text but not the selected data that is called in the public void function. i need help badly. thanks

Is This A Good Question/Topic? 0
  • +

Replies To: why does this code not work anymore?

#2 yotic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 11-October 11

Re: why does this code not work anymore?

Posted 07 November 2011 - 12:30 PM

also for the record, the
void main() 
thing is somthing my teacher requires of me, i know that int is the better format for the main function, it confuses me as well.
Was This Post Helpful? 0
  • +
  • -

#3 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1635
  • View blog
  • Posts: 3,111
  • Joined: 30-May 10

Re: why does this code not work anymore?

Posted 07 November 2011 - 12:50 PM

> 48 cus.number;
Do you want say
cout << cus.number;
Was This Post Helpful? 1
  • +
  • -

#4 tbandtg1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 03-September 08

Re: why does this code not work anymore?

Posted 07 November 2011 - 01:00 PM

I think this is more what you want.
cout << "the number of customer: " << cus.number << endl;
cout << "\nThe customers city: " << cit.cityname << endl;


your not actually doing anything with those variables. read the warnings.

oh ignore the endl i see your \n. I would probably drop those too though.

so your lines would look like
cout << "the number of customer: " << cus.number << endl;
cout << "The customers city: " << cit.cityname << endl;
Was This Post Helpful? 1
  • +
  • -

#5 yotic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 11-October 11

Re: why does this code not work anymore?

Posted 07 November 2011 - 10:14 PM

thank you both, i was panicking and didn't look at the code calmly. I apologize for the high concentration of ignorance, that was a beyond basic mistake that i made, i need to slow down lol.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1