Array Based List

Okay.. a little confused since we did this a couple of months ago... so my instructor gave us an example of an array based list basically giving us random integers (with a seed and srand functions) and asking us to do the basic functions, insert, delete and search. I got this part down.. question is the next part (which is supposed to be similar to his) asks for this:

Part Three: First define a personType class with three data members
(string name, int ID, and double grade). Second, create a list
of personType. Third, pratice the basic list operations:
insertion, search, deletion, etc.

Okay.. understand what he wants.. I'm having problems trying to do this with an array.. because, well basically in his example, he only gave us integers to work with, now he wants three members for each single value in an array? Here is the second part I did myself:

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
	
	/***************************************************************
	 Part Two: Try to create a list of strings and practice 
	 the basic list operations: insertion, search, deletion, etc. 
	 ***************************************************************/
	//add your code here
	cout<<" ******************************************\n"
		  "Part Two:"<<endl<<endl;

        //variable declarations
	string word;
	int size;
	int anotherSize;
	bool empty;
	char reply;

	cout<<" Now its our turn to create a list of strings."<<endl;
	cout<<" Please enter the number of words you want to "
		  "place in the program: ";
	cin >>size;
	arrayListType<string> stringList(100);
	if(empty = stringList.isEmpty())
		cout<<" List is empty.. time to begin"<<endl;
	else 
	{	
		cout<<" List is being deleted.."<<endl;
		stringList.destroyList();
	}

	cout<<" Please enter "<<size<<" words you want."<<endl;
	for(int i =0; i<size;i++)
	{
		string bla;
		cin>>bla;
		stringList.insertLast(bla);
	}

	cout<<" Here are the words you entered in the"
		  " order you entered them."<<endl;
	stringList.print();

	cout<<"\n Do you want to enter some words to the back or"
		  " the front of the list?\n Please enter in f for"
		  " front or b for back or n for none: ";
	cin >> reply;
		switch(reply)
		{
		case 'f':case 'F':
			{
				cout<<" Enter number of words you want to enter"
					  " into the front of the list.";
				cout<<"\n Please make sure total number of words is "
					  "less than 100, including the words already "
					  "inserted: ";
				cin >>anotherSize;
				cout<<" Now enter the words: ";
				for(int i =0; i<anotherSize; i++)
				{
					string bla;
					cin>>bla;
					stringList.insertFirst(bla);
				}
			}
		case 'b': case'B':
			{
				cout<<" Enter number words you want to enter"
					  " into the back of the list: ";
				cin >>anotherSize;
				cout<<" Now enter the words: ";
				for(int i =0; i<anotherSize; i++)
				{
					string bla;
					cin>>bla;
					stringList.insertLast(bla);
				}
			}
		default :cout<<" Okay.."; break;
		}
		do
		{
			cout<<" Time to look for a word you entered."<<endl;
			cout<<" Please enter a word to search: ";
			cin >>word;
			if (stringList.search(word))
				cout << "Found " <<word<< " in the list. " <<endl; 
			else
				cout << "Failed to find " <<word << " in the list. " <<endl; 
			cout<<" Do you want to search again?"
				" Please enter y for yes or n for no: ";
			cin>>reply;
		}while(reply=='y');
	cout<<" Do you want to delete a word? Please "
		<<"write in y for yes or n for no: ";
	cin >>reply;
	if(reply == 'y')
	{
		cout<<" Please enter the word you want deleted: ";
		cin >>word;
		stringList.deleteItem(word);
	}



so I don't understand how I can do the third part like this if he wants three members... unless I make three arrays and every time I insert a new item or delete or whichever, I would have to ask for the information for name, id, and grade and have to move everything together in order to keep all the arrays parallel? Is this what he wants? I'm sorry.. I'm confused.. Please someone explain if possible.. oh yeah and didn't include header file.. too long..
a personType class is just like a integer you used in part two, so you still need only one array, this time it is a arrray of classes, not integers.
you saved maybe 12, 15, 17 in arrayListType<string> in part two, and this time save Tom, Jack and Hyram in arrayListType<personType >. Then use Tom.name for his name, Tom.ID for his ID, and so on.
1
2
3
4
5
6
7
classs personType 
{
  private:
    string name;
    int ID;
    double grade;
}
Topic archived. No new replies allowed.