Pointers assignment

Pages: 123
Hello, I need help with this pointers assignment. I'm a beginner at c++. So please don't have high expectations of my knowledge. I have attached what I started but it's all wrong and i need help

For this assignment, you will use pointers to write a program that asks the user to enter the name, birth city and year of birth for five (5) family members. Be sure to include comments throughout your code where appropriate. The data should be stored in dynamically created parallel arrays. Users are assumed to be born between the years 1900 and 2018, and should enter the year of birth in one of the two formats 19XX and 20XX. Output the data from the arrays in a formatted table.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  #include <iostream>
#include <string>
#include <iomanip>

int main() {
	string * name=nullptr;
	string * birthcity=nullptr;
	string * birthyear=nullptr;

		cout << "Enter your name" << endl;
	getline(cin, *firstname);
	cout << "Enter your birth city" << endl;
	getline(cin, *lastname);

	char* person[3]{
		"name", "Birthplace", "Birthyear"
	}
		char* charles[3] = {
		"Charles Blackwell", "12/2/1980", "michigan"
	}
	return 0;
}
A start, you should be able to comment and complete it. if not have a read of the tutorials on this site. You might also like to find out why the ignore(...) line is required in order to explaining it to your prof/teacher/tutor when they ask??

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
26
27
28
29
30
31
32
#include <iostream>
#include <string>
#include <iomanip>

using namespace std; // <-- last resort

const int LIMIT{5};

int main()
{
    string* name = new string[LIMIT];
    string* birthcity = new string[LIMIT];
    int* birthyear = new int[LIMIT];
    
    for(int i = 0; i < LIMIT; i++)
    {
        cout << "      Enter your name: ";
        getline(cin, name[i]);
        
        cout << "Enter your birth city: ";
        getline(cin, birthcity[i]);
        
        cout << "Enter your birth year: ";
        cin >> birthyear[i];
        
        cin.ignore(1000, '\n');
    }
    
    // blah blah
    
    return 0;
}
Hello

Thank you so much for your help. How would I get it to Output the data from the arrays in a formatted table ?
How would I get it to Output the data from the arrays in a formatted table ?


This is where <iomanip> comes into play.

You will need to use setw() function at least.
See: http://www.cplusplus.com/reference/iomanip/setw/

cout << setw(20) << name[3] << setw[5] << birthcity[3] blah blah

You can use the right/left functions in <iomanip> to right/left justify the entries.
http://www.cplusplus.com/reference/ios/right/?kw=right
BTW Once you see you way clear on that you can then go on and thoroughly work through
Users are assumed to be born between the years 1900 and 2018, and should enter the year of birth in one of the two formats 19XX and 20XX.


There's obviously a test involved and a string might be useful instead of an int. But then again ...
As I mentioned, I’m a very new beginner. So I’m still stuck. I don’t know how to proceed. I’ll have to get more help from someplace else
OK, best wishes ... bye :)
Bye
cblack618 wrote:
Bye

Good riddance.
The data should be stored in dynamically created parallel arrays.

I think your teacher meant C-style char arrays (I may be wrong).
HTF would you know what the teacher is thinking?
I was right he didn't know after all - not a schmik - just wounded pride :)
Hello cblack618,

Using againtry's code as a starting place I did manage to come up with output:

             Table Title Change as Needed
======================================================

        Name               Birth City       Birth Year
------------------------------------------------------
            John Doe        Columbus, OH       1950
            Jane Doe        Columbus, OH       1651
          Bob Smithe      Marysville, OH       1965
          Jack Sprat      Portsmouth, OH       1980
       Mary Horowitz        Deleware, OH       1990



 Press Enter to continue:

So there is still hope.

Andy
How though ? What code did you use
How though ? What code did you use

I SAID GOOD DAY, SIR!
aint nobody talking to you
aint nobody talking to you

Ain't nobody writing your code for you, you pathetic fucking leach!
ok tough keyboard warrior
Listen clack618, just green tick the thread and go. People have been very kind to you but the free ride is over.
Hello cblack618,

againtry has given you some very nice code to start with along with some links to help with the output.

Now it is your time to write some code and present it if you are having problems.

I do not think that you will find anyone that will write the whole program for you.

Looking at the instructions that you posted I feel that there is a lot missing. The missing parts would help to figure out what the program should instead of having to guess at it.

As far as the output goes first you need to collect the input before you can deal with the output. That is where http://www.cplusplus.com/reference/iomanip/setw/ becomes useful.

Andy
Pages: 123