I'm being asked to make my default constructor "interactive" by having it prompt for an input and store the three phone number pieces you see below. They are strings, and they get called for display in main with the telnumber yournumber piece of main. How would one do that?

telnumber::telnumber()
{
	npa="";
	nxx="";
	line="";
	cout << "In Telephone Number Default Constructor" <<endl;
}


int main()
{
	telnumber yournumber;

Recommended Answers

All 6 Replies

I'm being asked to make my default constructor "interactive" by having it prompt for an input and store the three phone number pieces you see below. They are strings, and they get called for display in main with the telnumber yournumber piece of main. How would one do that?

telnumber::telnumber()
{
	npa="";
	nxx="";
	line="";
	cout << "In Telephone Number Default Constructor" <<endl;
}


int main()
{
	telnumber yournumber;

Something like this?

telnumber::telnumber()
{
        cout << "Please enter npa: ";
        cin >> npa;

        // do same for other two data members.

	cout << "In Telephone Number Default Constructor" <<endl;
}

okay, I'll try that...I tried doing it all in one lump and that didn't work out too well...caused more problems than it fixed...lol

Thanks, that seems to work very well for all three classes...I did develop a slight "feature" with my ostream print function though. I ended up with a couple of dashes around my second and third class prints. Apparently, it's running it twice and dumping the dashes I put in there in front of the next thing to go to the screen. I figure I'll try to rearrange those, or maybe a statement to tell it not to print if those are the only two characters.

okay, I give up...can't find a way to take out the dashes without affecting the rest of the numbers,

Member Avatar for iamthwee

Post your code...

I'll repost it as a separate question later, I have other code to work....lots of it...lol

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.