I'm on pointers and structs now and I have these Practice Problems on structures:
Practice problems
1. Write a program that lets the user fill in a single structure with the name, address, and phone
number of a single person
2. Create an array of space ship objects and write a program that continually updates their
positions until they all go off the screen. Assume that the size of the screen
is 1024 pixels by 768
pixels.
3. Create an address book program that builds on problem #1—this time, the user should be able
to not just fill out a single structure, but should be able to add new entries, each with a separate
name and phone number. Let the user add as many entries as he or she wants—is this easy to
do? It is even possible? Add the ability to display all, or some of the entries, letting the user
browse the list of entries.
4. Write a program that allows a user to enter high scores of a game, keeping tracking of the name
of the user and the score. Add the ability to show the highest score for each user, all scores for a
particular user, all scores from all users, and the list of users.
I've got some code here for the first one, which isn't able to compile.
Here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <iostream>
using namespace std;
struct PersonalInfo
{
string person_name;
string person_address;
int person_phone_number;
};
int main()
{
cout << "Personal Information Form:\n";
cout << "\n";
cout << "Please provide your name: ";
getline(PersonalInfo->person_name, cin, '\n');
cout << "Please provide your home address: ";
getline(PersonalInfo->person_address, cin, '\n');
cout << "Please provide your phone number: ";
cin >> PersonalInfo->person_phone_number;
cout << "Hello, " << PersonalInfo->person_name << " your phone number and address have successfully been noted.";
cout << " Thank you.\n";
}
|
I'm getting an error like this for lines 17, 19, 21 and 23:
|17|error: expected primary-expression before '->' token|
Please help me out here. What am I doing wrong?
If possible, please out with the other practice problems, too.