b_acs
asked on
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.
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;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> I got it!!!
Correct :)
Correct :)
ASKER
Open in new window