samedi 4 avril 2015

adding two phone agendas toghether

I got this problem where I need to create a phone agenda where every name coresponds to a phone number. I decided to create this as a bidimensional string array. But what I do not know how to do is: I need to create 2 agendas(created in main) and then add them toghether to create one big agenda that contains the members of ag1 and ag2. Please help me create the method that does that.



#include "stdafx.h"

using namespace std;

class Agenda{
string date[20][20];
public:
Agenda();
void afisare();
};

Agenda::Agenda(){
int i, j, n;

cout << "Numarul de intrari: ";
cin >> n;

for (i = 0; i < n; i++){
for (j = 0; j < 2; j++){
cout << "Date[" << i << "][" << j << "] = ";
fflush(stdin);
getline(cin, date[i][j]);
}
cout << endl;
}

}

void Agenda::afisare(){
int i, j;

for (i = 0; i < 2; i++){
for (j = 0; j < 2; j++){
cout << "Date[" << i << "][" << j << "] = ";
cout << date[i][j] << endl;
}
cout << endl;
}
}

void main(){
Agenda ag1;
cout << "-----AGENDA 1-----" << endl;
ag1.afisare();

Agenda ag2;
cout << "-----AGENDA 2-----" << endl;
ag2.afisare();
}

Aucun commentaire:

Enregistrer un commentaire