What am I doing wrong? working with classes

I was told to write a program that gets from a file, a first name, last name and age. I was also told to break it up into 3 parts. When i run my function i get an error (entry point not defined)...not recognizing my int main()? Hmm not sure what i'm doing wrong.


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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

//part 1

class personInfo

{

Public:
		void retrieveFirstName();
		void retrieveLastName();
		void retrieveAge();
		void store_info(string& , string&, int& );
		int returnAge();
		personInfo();
		personInfo(int, int, int); 

Private:
		string firstName;
		string lastName;
		int age;
};

 

//part 2

#include <iostream>
#include <fstream>
#include <string>
#include "personInfo.h"

using namespace std; 

void personalInfo::retrieveFirstName()
{
	return firstName;
}
void personalInfo::retrieveLastName()
{
	return lastName;
}
void personalInfo::retrieveAge()
{
	return age;
}

void personalInfo::storeInfo (string& first, string& last, int& personAge)
{
	firstName = first;
	lastName = last; 
	age = personAge; 

}

int personalInfo::returnAge ()
{
return age;

}


// part 3 

#include <iostream>
#include <fstream>
#include <string>
#include "personInfo.cpp"

const int MAX = 10; 

using namespace std; 

int main()
{
string first;
string last;
int personAge;
personalInfo IdentifierInfo;
IdentifierInfo array[MAX];

ifstream fin;
fin.open("input.txt"); 

if(!fin)
	cout << "Input file error." << endl; 

getline(fin,first);
getline(fin,last);
fin.get(age);

while(fin)
{

getline(fin,first);
getline(fin,last);
fin.get(age);
}

return 0;

}




Last edited on
Your class is called personInfo but you refer to it throughout the program as personalInfo. This may be part of the problem.

You also have many functions that are void, but also return something. I don't know much about classes (I'm still learning) but this seems wrong.
Last edited on
Thank you i missed that! I changed it to personalInfo.

I'm trying to think of a way to create a function to retrieve the name and age while gathering it from int main()


1
2
3
4
5
6
7
8
9

void personalInfo::retrieveInfo (string first, string last, int personAge)
{


}


Last edited on
A member function of personalInfo?
personalInfo person

get input

person.retrieveInfo(string1, string2, age);

That will allow you to change your variables if that's what you want, but if you want it to return something, you'll have to make it a value returning function.

I've also noticed all your retrieve functions are labeled void and you put a return in each of them, which doesn't work.
yea, I want to create a member function of personalInfo, but i'm confused how to retrieve the info. I was told i should have a retrieve function in personalInfo but loop through my file in int main()
Retrieve info as input or from the object?
Topic archived. No new replies allowed.