I am trying to build a class with definitions that will output the following...

Income tax for year 2009:
Name: John Doe
Address: 1234 Alphabet Lane, City, State Zip
SSN: 111-11-1111
DOB: 11-11-1111

I have built my class and source code to define the function members. But I am running into an output problem. When I enter in the first and last name for the Name prompt in my program it skips over the Address. I am sure this is an obvious limitation in my code but because I am a noob I am recognize it. Also I am a little unsure as to how I would fix this for the Address since the address also is going to have multiple spacing contained within the string. I have posted my Personal Class, Source Code, and Main Code below. Thanks in advance.

//Personal Class Definition

#include <iostream>
#include <string>
using namespace std;

//Personal class definition
class Personal
		Personal(string, string, int, int); //constructor that initiates the Income 
		string getName();
		//void setAddress(string);
		string getAddress();
		//void setBirthday(int);
		int getBirthday() const;
		//void setSSN(int);
		int getSSN() const;
		string Name;
		string Address;
		int DOB;
		int SSN;
}; //end class Income

I took out the void functions but I also left them because I was not sure why it would be required to use them. But they are supposed to be used (if that makes sense).

//Personal Member Function Definitions

#include <iostream>
#include <string>
#include "Personal.h"
using namespace std;

//constructor initializes Name, Address, DOB, and SSN
Personal::Personal(string n, string a, int d, int s)
	Name = n;
	Address = a;
	DOB = d;
	SSN = s;

} //end Personal constructor

//function to return the name of the person
string Personal::getName()
	return Name;

}//end function getName

//function to take in the address for the person
//void Personal::setAddress(string a)
//	a = Address;

//}//end function setAddress

//function to return the address of the person
string Personal::getAddress()
	return Address;

}//end function getAddress

//function to take in the DOB of the person
//void Personal::setBirthday(int d)
//	d = DOB;

//}//end function setBirthday

//function to return the DOB of the person
int Personal::getBirthday() const
	return DOB;

}//end function getBirthday

//function to take in the SSN of the person
//void Personal::getSSN(int s)
//	s = SSN;

//}//end function getSSN

//function to return the SSN of the person
int Personal::getSSN() const
	return SSN;

}//end function getSSN
#include <iostream>
#include <string>
#include "Personal.h" //include definition of class Dividend
//#include "Donation.h" //include definition of class Donation
//#include "Income.h" //include definition of class Income
using namespace std;

//function main begins program execution
int main ()

	string n, a;
	int d, s;

	cout << "\nPlease enter your name: ";
	cin >> n;

	cout << "Please enter your address: ";
	cin >> a;

	cout << "Please enter your date of birth:  ";
	cin >> d;

	cout << "Please enter your social security number: ";
	cin >> s;

	Personal person(n, a, d, s);

	cout << "Income tax for year 2009: ";
	cout << "\nName: " << person.getName() << endl;
	cout << "Address: " << person.getAddress() << endl;
	cout << "DOB: " << person.getBirthday() << endl;
	cout << "SSN: " << person.getSSN() << endl;

}//end main
A good first post. Keep it up.
6 Years
Discussion Span
Last Post by Fbody

The >> operator stops at the first space, so if you enter "John Doe" as the name the cin will put John in name and Doe in Address. Change the >> operator to getline getline(cin, name);


AD Covered the input issue you mentioned.

Your "set..." functions are not written correctly, that's probably why you're confused.

"set..." functions are supposed to be used to modify an object's attributes/properties by storing new information to the variables in your class. The issue with the design of your "set..." functions is that you have written the assignment(s) backward. You need to store the function's parameter to the member variable. You have written the opposite statement in all cases.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.