File and vector

Here is the updated version.

Im posting the code below.

Hi, I have written part of this code but I am having trouble with some things that I dont know are missing. The requirement of the code is below:

Your program must include the following:
Implement all the class methods defined above
Must initialize the class object variable with initial value in the default constructor
Your program will read a file contains person’s info. The file has the following format:


FirstName LastName Sex BirthYear BirthMonth BirthDay




The file name must (sample file: personsInfo.txt personsInfo.txt) be passed in when you start the program using argc, argv: main (int argc, char* argv[])
After reading the file, your program will have an user’s menu similar to the one below:
Enter person’s information:
Print out person’s information
Exit

If user selects “1”, the program will search person’s last name, and if found, will print out person’s information. (Search for Clinton, Trump, Obama). If not found, output a message indicate the person’s information is not found. (search Bush)


If user selects “2”, the program will print out all the person’s information have entered so far (which is stored in a vector). After prints out all the person’s information, the program will print out the menu again and waiting for user’s input.
If user selects “3”, the program will exit. Class: Class section name (CS-106-02 or CS-106-03) Your program submission:
Pdf file contains all of the following:

What I have so far is below. I would appreciate it if you guys could help me understand and finish the code.

PersonInfo.txt
1
2
3
4
5
6
Hillary Clinton F 1947 10 26
Donald Trump M 1946 06 14
Bernie Sanders M 1941 09 08
Barack Obama M 1961 08 04
Melania Trump F 1970 04 26
Michelle Obama F 1964 01 17


Person.h
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
#ifndef PERSON_H_INCLUDED
#define PERSON_H_INCLUDED
#include <string>

//The code below was provided during the lab.

class Person
{
	public:
		Person();
		Person( std::string fname, std::string lname , string s, int byear, int bmth, int bday );
		std::string findName (std::string lname) const;
		void setName (std::string fname, std::String lname);
		void read (string lname);
		void printPerson () const;
		bool find (std::string a) const;
		//void setAge( int age );
		//int getAge() const;
		//void print() const;

	private:
		std::string firstName;
		std::string lastName;
		std::string sex;
		int birthYear;
		int birthMonth;
		int birthDay;
		
};

#endif // PERSON_H_INCLUDED  


Person.cpp

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
#include "Person.h"
#include <string>
#include <iostream>
using namespace std;

Person::Person()
{
	
}

Person::Person(std::string fname, std::string lname , string s, int byear, int bmth, int bday)
{
	firstName = fname;
	lastName = lname;
	sex = s;
	birthYear = byear;
	birthMonth = bmth;
	birthDay = bday;
}

void std::string Person::setName() const
{
	return name;
}

std::string Person::findName() const
{
	return name;
}

void Person::read(string lname)
{
	ifstream in;
	string line;
	bool more = true;
	in.open (fname.c.str());
	while (more)
	{
		std::in >> w;
		if(in.fail())
		more = fa;se;
	else
	{
		lname.push_back(w);
		getline (in, line);
		info.push_back(line)
	}
}
in.close()
		
}

bool Person::find (std::string a & f)
{
	{
		for (int i=0;i< lname.size();i++)
		{
			if (a==lname[i])
			{
				f = info[i]
				return true;
			}
		}
		return false;
				
}

void Person::print () const
{
	for (i=0;i<lname.size();i++)
	{
		std::cout << lname[i] << "\t";
		std::cout << info[i] << "\n";
	}
}


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namesapce std;

int main(int argc, char *argv[])
{
	if (argc < 6)
	{ std::cout << "usage" << arg[0] << lname\n";
		return 1;
	}
	Person per;
	per.read(arg v[i])
	bool name;
	while (more)
	{
		std:: cout << "enter last name";
		std::Cin >> w;
	}
} 
Last edited on
Send me a private message.
First, please post code with code tags. See: http://www.cplusplus.com/articles/jEywvCM9/
Pay attention to indentation and whitespace to make the code more readable.
You can edit your previous post.

You do already have some code: the class Person definition and the lab1 program. Your program has several distinct subtasks. Attack one at a time.

It is imperative that you do your work first. Your work is to learn by trial and error. Once you have written the program -- if it has specific issues -- you show us the code and we will help with those issues.
Topic archived. No new replies allowed.