file program

Program to read name,age and phne nmbr of 5 person from a file and to display detailed information of the youngest person???

Please provide the solution
Well, you have to be more explicit and show us what your ideas are (and/or your already written code). Otherwise, you are very unlikely to get any help. No one is going to write the code and give it to you.

Best of wishes,
~ Raul ~
I would first create a Person class. If you want to use this approach you will need to create a Read(istream& in) to read from a valid file stream or you could also overload the >> operator for the class.

Or you could just start from scratch and do it all yourself. Why not start with some pseudocode?

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
class Person
{
public:
	Person() { }
	Person(string name, int age, string phone)
	{ 
		_name = name;
		_age = age;	
		_phone = phone;		
	}
	// setters
	void Name(string name)   { _name = name; }
	void Age(int age)        { _age = age; }
	void Phone(string phone) { _phone = phone; }

	// getters
	string Name()  { return _name; }
	int Age()      { return _age; }
	string Phone() { return _phone; }	
	
	void Print(ostream& out)
	{
		out << "Name: " << _name << endl 
		    << "Age: " << _age << endl
		    << "Phone: " << _phone << endl;
	}

private:
	string _name;
	int _age;
	string _phone;
};
Last edited on
Topic archived. No new replies allowed.