Which is Better

I have 2 pieces of code. Both are trying to do the same thing.I know they aren't finished and probably have holes in them butbasically I have to create a program that allows user to input details and then later on search the details up using their age/name etc. Also they should be able to delete too. I will implement that later on but for now which one should I go ahead with or should I scrap both and take a different approach. I plan to have a menu and such .



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
	#include <iostream> 
	#include <string>
	#include <math.h> 
	#include <fstream>
	using namespace std;

	class Storage
	{
	public:
	Storage();
	string information[10][7];
	void SetInformation(int);
	void GetInformation(int);
	};	
	Storage::Storage(){cout<<"\nStorage Activated\n";}
	void Storage::SetInformation(int i){
		//input
		i--;
		for (int j=0;j<7;j++){
		
			switch(j+1){
				case 1: cout << "\nFirst Name: "; break;
				case 2: cout << "\nLast Name: "; break;
				case 3: cout << "\nAge: "; break;
				case 4: cout << "\nEmail: "; break;
				case 5: cout << "\nDoor Number: "; break;
				case 6: cout << "\nRoad Name: "; break;
				case 7: cout << "\nPost Code: "; break;
				default: break;
				}

			cin >> information[i][j];
			}
	}
	void Storage::GetInformation(int i){
	// output
		i--;
		for (int j=0;j<7;j++){	

			switch(j+1){
				case 1: cout << "\nFirst Name: "; break;
				case 2: cout << "\nLast Name: "; break;
				case 3: cout << "\nAge: "; break;
				case 4: cout << "\nEmail: "; break;
				case 5: cout << "\nDoor Number: "; break;
				case 6: cout << "\nRoad Name: "; break;
				case 7: cout << "\nPost Code: "; break;
				default: break;
				}		

			cout << information[i][j];
			}
	}
	
	
	
	int main(){


		int i;
		
		Storage Someone;
		cin >> i;
		Someone.SetInformation(i);

	return 0;
	}
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
	#include <iostream> 
	#include <string>
	#include <math.h> 
	#include <fstream>
	using namespace std;

class Details
{
public:
    Details(); 
    string FirstName;
    string LastName;
    int Age;
    string Email;
    int DoorNumber;
    string RoadName;
    string PostCode;
	
};

void SetInformation(Details &member)
{
    cout << "\nFirst Name: ";
    cin >> member.FirstName;

    cout << "\nLast Name: ";
    cin >> member.LastName;

    cout << "\nAge: ";
    cin >> member.Age;

    cout << "\nEmail: ";
    cin >> member.Email;

    cout << "\nDoor Number: ";
    cin >> member.DoorNumber;

    cout << "\nRoad Name: ";
    cin >> member.RoadName;

    cout << "\nPost Code: ";
    cin >> member.PostCode;
}

int main()
{	int i;
	Details	information[10];	
	cout << "\nWhich Slot would you like to store the informaton in ?(1-10)";
	cin >> i;
	i--;
	SetInformation(information[i]);





return 0;}



Last edited on
The Details class should implement friend operator>>(istream &in, Details &dtails) and friend operator<<(ostream &out, const Details &dtails) for proper encapsulation.
Last edited on
Topic archived. No new replies allowed.