I want to get ride off lists and vectors in this program i also dont want to use classes

I want to get ride off lists and vectors in this program i also dont want to use classes,just want to use strings functions and structures so please elp me about this.
thanks

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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
  #include <iostream>
#include <string>
#include <list>
using namespace std;
struct contact
{
	string name;
	int studentiD;
	string address1;
	string address2;
	int phonenumber;
};
std::list<contact> contacts;

int main()
{

	string  Username, Password;
	const string username = "khan";
	const string password = "112233";
	cout << "Enter the Login Details to access the database " << endl;
	cout << "Enter the Username details\n";
	cin >> Username;
	cout << "Enter the password details\n" << endl;
	cin >> Password;

	if (Password != password || Username != username)
	{
		cout << "Invailid Login Details" << endl;
		return 0;
	}

	while (1)
	{
		int choice;
		cout << "Welcome Khan" << endl;
		cout << "Enter 1 to insert a new contact." << endl;
		cout << "Enter 2 to retreive an existing contact." << endl;
		cout << "Enter 3 to remove an existing contact." << endl;
		cout << "Enter 4 to display your contact list." << endl << endl;
		cout << "Enter 5 to quit" << endl << endl;
		cout << "\nYour choice here:";
		cin >> choice;
		if (!cin.good())
		{
			cout << "Input error!";
			return 1;
		}
		switch (choice)
		{
		case 1:
		{
				  char y;
				  contact s;
				  cout << "Enter the Person Name" << endl;
				  cin >> s.name;
				  cout << "Enter the person ID" << endl;
				  cin >> s.studentiD;
				  cout << "Enter the person address Line 1" << endl;
				  cin >> s.address1;
				  cout << "Enter the person address line 2" << endl;
				  cin >> s.address2;
				  cout << "Enter the person Phone number" << endl;
				  cin >> s.phonenumber;
				  contacts.push_back(s);
				  system("cls");

		}
			break;

		case 2:
		{
				  if (contacts.size() <= 0)
					  cout << "=====No Contacts yet=====" << endl;
				  else
				  {
					  cout << "Enter the Contact index (between 0 and " << contacts.size() - 1 << ")" << endl;
					  int index;
					  cin >> index;

					  if (index >= 0 && index< contacts.size())
					  {
						  std::list<contact>::iterator it = contacts.begin();
						  for (int i = 0; i< index; i++) it++;
						  contact s = (*it);
						  cout << s.name << endl;
						  cout << s.phonenumber << endl;
						  cout << s.studentiD << endl;
						  cout << s.address1 << endl;
						  cout << s.address2 << endl;
					  }
				  }
		}
			break;

		case 3:
		{
				  if (contacts.size() <= 0)
					  cout << "=======No Contacts yet=====" << endl;
				  else
				  {
					  cout << "Enter the Contact index (between 0 and " << contacts.size() - 1 << ")" << endl;
					  int idx;
					  cin >> idx;

					  if (idx >= 0 && idx< contacts.size())
					  {
						  std::list<contact>::iterator it = contacts.begin();
						  for (int i = 0; i< idx; i++) it++;
						  contacts.erase(it);
					  }
				  }
		}
			break;

		case 4:
		{
				  if (contacts.size() <= 0)
					  cout << "====No Contacts yet=====" << endl;
				  else
				  {
					  int i = 0;
					  for (std::list<contact>::const_iterator it = contacts.begin(), end = contacts.end(); it != end; ++it)
					  {
						  contact s = (*it);
						  cout << "Contact " << i++ << endl;
						  cout << "\t" << s.name << endl;
						  cout << "\t" << s.phonenumber << endl;
						  cout << "\t" << s.studentiD << endl;
						  cout << "\t" << s.address1 << endl;
						  cout << "\t" << s.address2 << endl;
					  }
				  }
		}
			break;

		case 5:
		default:
			return 0;


		}
	}
	return 0;
}
Why?

-Albatross

P.S. Those strings you're using on lines 7, 9, 10, 18, 19, and 20 are classes too. std::cout and std::cin are objects too. From what you're saying, it sounds like you'd rather program in C.
Last edited on
Topic archived. No new replies allowed.