Program that formats phone numbers

Hi everyone,

I am having some problems compiling a program that formats phone numbers. My teacher wants us to use classes and objects, and I am having some problems with the calls and prototypes. This is what I have so far - could anyone provide some direction/help on this project, or help me with where I have gone wrong?

Thanks for your help in advance!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <string>
#include <fstream>
#include <istream>
using namespace std;

class PhoneNumber
{

	private:
	int area,
		prefix,
		suffix;
	public:
	istream& readNumber(istream&); 

	ostream& writeNumber(ostream&) const; 

}

istream& PhoneNumber::(istream& fin)
{
	return fin >> area >> prefix >> suffix;
}

ostream& PhoneNumber::(ostream& fout)
{
	fout << area << "-" << prefix << "-" << suffix;
	return fout;
}


class PhoneEntry
{
	private:
	PhoneNumber Number;
	string firstName,
			lastName;
	public:
		istream& readEntry(istream&);
			Number.ReadNumber(fin);


		ostream& writeEntry(ostream&) const; 





}

istream& PhoneEntry::readEntry (istream& fin)
{
	return fin >> firstName >> lastName;
}

ostream& PhoneEntry::writeEntry(ostream& fout)
{
	fout << lastName << ", " << firstName;
	return fout;
}








	int main()
	{
		PhoneEntry Phone;
		while (Phone.readEntry(cin))
			Phone.writeEntry(cout) << endl;
		return 0;
	}
		
You're writing out the number with - separators. But when you read the numbers in, you don't process those inserted - separators. You have to read them in and ignore them.

I don't know what line 41 does.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <string>
//#include <fstream>
//#include <istream>
using namespace std;

class PhoneNumber
{

public:
	int area,
		prefix,
		suffix;
	//friend std::ostream& operator<< (std::ostream&,const PhoneNumber&);
	inline std::ostream& writeNumber(std::ostream& fout) {
	fout << area << "-" << prefix << "-" << suffix;
	return fout;
	}

	inline std::istream& readNumber (std::istream& fin){
	return fin >> area >> prefix >> suffix;
	}
	

};


class PhoneEntry:public PhoneNumber
{
public:
	PhoneNumber Number;
	string firstName,
			lastName;
	
		inline std::istream& readEntry(std::istream& fin)
		{
			fin >> firstName >> lastName;
			
			return fin;
		}

	


		inline std::ostream& writeEntry(std::ostream& fout) 
		{
		fout << lastName << ", " << firstName;
		return fout;
		}
};



	int main()
	{
		PhoneNumber Number;
		PhoneEntry Phone;
	
		while (Phone.readEntry(cin))
			Phone.writeEntry(cout) << endl;
		system("pause");
		return 0;
	}



this will work fine in visual studio..........but what you exactly want to do i cant understand the logic .......
Thank you both for your help! Basically, I am looking to take a specifically formatted input to make another specifically formatted output. For example:

input: First Last 5555555555

output: Last, First 555-555-5555

Is there a way I can write those functions out of line and call them (that's what I attempted to do but my program won't compile)?

Thanks again for your help everyone!
Topic archived. No new replies allowed.