Need help get this working
It's probably an easy program to fix but as a newbie I'm having trouble understanding the concept of class.
I'm supposed to create a person class to represent a person. (You may call the class personType.) To simplify things, have the class have 2 variable members for the person's first and last name. Include 2 constructors. One should be a default constructor and the other should be one with parameters. Include respective functions for:
setting the name,
getting the name, and
printing the name on the screen.
This is what I did so far, but I'm having trouble running it.
Code:
#include <iostream>
#include <cstring>
#include <cstdlib>
using std::cout;
using std::cin;
using std::endl;
using namespace std;
class personType
{
public:
void print() const;
void setName(string first, string last);
void getName(string& first, string& last);
personType(string first, string last); //Constructor with parameters
private:
string firstName; //store the first name
string lastName; //store the last name};
};
int Main ()
{
personType(); //Default constructor;
{
string firstName; //store the first name
string lastName; //store the last name
}
void personType::print()
{
cout<<firstName<<" "<<lastName;
}
void personType::setName(string first, string last)
{
firstName = first;
lastName = last;
}
return 0;
}
If anyone can explain what I'm doing wrong I would greatly appreciate it.
Thanks