How do you use a pointer to a class object??

I am in my second term of pogramming (nubie).  I am writing a code for a class assignment.  I am supposed to create a class and ask the user to enter stuff in the constructor. Then I am supposed to create a Print function that outputs that stuff.  In main I am supposed to create a group object and a pointer this group object.  My program is supposed to print using both the object name and the pointer name.

My problem is the pointer.....I'm not sure how to do this.   I will post what I have and ask for your guidance again.
// Day7.cpp : Defines the entry point for the console application.
//
 
#include <iostream>
 
using namespace std;
//declaration section
 
class Group
{
public:
	Group();
	void Print();
 
private:
	int NumberInGroup;
	char Name[75];
};
//implementation section
Group::Group()
{
	cout << "Enter the number in the group: ";
	cin >> NumberInGroup;
	cout << "Enter the name of the group: ";
	cin.getline(Name,74, '\n');
}
void Group::Print()
{
	cout << "The group called \"" << Name << "\" has " << NumberInGroup << "members.\n";
}
int main()
{
	Group obj;
	Group *ptr = 0;
 
	obj.Print();
 
	*ptr = obj;
 
	Group *ptr.Print();
 
	
	return 0;
}

Open in new window

b_acsAsked:
Who is Participating?
 
b_acsConnect With a Mentor Author Commented:
I got it!!!
int main()
{
	Group obj;
	Group *ptr;
 
	obj.Print();
 
	ptr = &obj;
 
	ptr->Print();
 	
	return 0;
}

Open in new window

0
 
b_acsAuthor Commented:
Ok I think it should be more like this, but still not right......
// Day7.cpp : Defines the entry point for the console application.
//
 
#include <iostream>
 
using namespace std;
//declaration section
 
class Group
{
public:
	Group();
	void Print();
 
private:
	int NumberInGroup;
	char Name[75];
};
//implementation section
Group::Group()
{
	cout << "Enter the number in the group: ";
	cin >> NumberInGroup;
	cout << "Enter the name of the group: ";
	cin >> Name;
}
void Group::Print()
{
	if(NumberInGroup != 1)
	cout << "The group called \"" << Name << "\" has " << NumberInGroup << " members.\n";
	else
		cout << "The group called \"" << Name << "\" has " << NumberInGroup << " member.\n";
}
int main()
{
	Group obj;
	Group *ptr = 0;
 
	obj.Print();
 
	*ptr = obj;
 
	ptr->Print();
 
	
	return 0;
}

Open in new window

0
 
Infinity08Commented:
>> I got it!!!

Correct :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.