I am supposed to write a program that holds holds the following personal data: name, address, age, and phone number. Write appropriate accessor and mutator functions. Then demonstrate the class by writing a program that creates three instances of it. One instance should hold your information,and the other two should hold your friends' or family members' information.
The problem is I am stuck in the int main(). I do not know what to put to be able to ask the user the person's information and then display it. Then ask the user again for the other two information. My apologies if this a very amateur question. I am not a very good programmer. Thank you for the help.
Thank you for the great help. The program runs properly but when I press space, such as "James Smith", the program skips a question based on how many spaced i entered on the previous question. Also, when I input more than 7 digits for the phone number, it skips the all the other inputs.
Ok, I solved the skipping problem by changing cin >> name; and cin >> address; to getline (cin, name); and getline (cin, address); but the phone number is still experiencing some problems as stated above.
This is a common problem in simple programs - how to represent data. Everything in the world is not either a 'string', 'int', 'double', etc. Phone number, social security, even a generic 'ID' are good examples. Is your phone number an integer? If I told you my phone number is 123-456-7890, you could parse out the dashes, and eventually store it in an int. What if it's not a US number tho: 12-345-678-9012? Can still strip out the dashes, but now the number is likely too large to store in an int (which has a fixed size). So you may think you need a 'BigInt' object - then consider how to store a number like 011-1234-56789. Might fit in a BigInt, but if you view this as an integer, you are going to strip off the '0' at the front! The solution is either to have a dedicated 'phone number' class, or more simply just store it as a string. I prefer by far to reserve int for numbers that represent counts (number of miles, speeds, etc)
I have put the phonenumber as a string but the result is still the same. Even if I only enter 1 digit it skips the next input. I even tried using getline (cin, phonenumber) but this just totally skips the phone number input.