I think you're having some trouble understanding how classes work. ALthough there is only one User in your main function, conceptually, each User has an age, a first & last name, and a list of favorite movies. To express this, you declare those members inside the
class User
declaration:
1 2 3 4 5 6 7 8
|
class User
{
public:
int age;
std::string num[5];
std::string fname;
std::string lname;
...
|
The next point is the way that methods work. When you call a method of a class, you don't have to pass the class instance that you want to act upon. In other words, you don't have to say
user.Create(user)
. You can just say
user.Create()
. Then the create method can just be:
1 2 3 4 5 6 7 8 9 10
|
void
User::Create()
{
cout << "Enter first Name" << endl;
cin >> fname;
cout << "Enter first Name" << endl;
cin >> lname;
cout << "Your Age" << endl;
cin >> age;
}
|
Here fname, lname and age refer to the member variables of class User. So if you call
user1.Create()
, then inside the
Create()
method, fname refers to
user1.fname
, lname refers to
user1.lname
and age refers to
user1.age
. If you call
user2.Create()
then inside Create(), the names refer to
user2.lname
,
user2.fname
and
user2.age
.
So you can declare the Create method liket this:
1 2 3 4 5 6
|
class User
{
...
void Create();
...
};
|
And you define it like this:
1 2 3 4 5 6 7 8 9
|
void User::Create()
{
cout << "Enter first Name" << endl;
cin >> fname;
cout << "Enter first Name" << endl;
cin >> lname;
cout << "Your Age" << endl;
cin >> age;
}
|
Make sense?
So you want to declare class User like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
class User
{
public:
int age;
std::string num[5];
std::string fname;
std::string lname;
void Update();
void View();
void Create();
void Favoriate();;
std::string setname();
};
|
and get rid of the global variables define at lines 101-104 of your last post.
See if you can define the methods using what you know about how Create() works. You will also have to change the way you call them in main().