Feb 22, 2013 at 12:29am UTC
this doesnt work whats wrong?
im a begginer please help
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
struct agenda{
char name[30],address[30],email[15],phone[10];
};
class person{
private:
struct agenda *ap;
int n;
public:
person();
void read(struct agenda *ap, int n);
void show(struct agenda *ap, int n);
};
person::person()
{
cout<<"¿Number of persons?: "<<endl;
cin>>n;
ap=new agenda[n];
}
void person::read(agenda *ap)
{
agenda *aux=ap;
for(int i=0;i<n;i++)
{
cout<<"¿Name?: "<<endl;
cin.getline(ap->name,30);
cout<<"¿Address: "<<endl;
cin.getline(ap->address,30);
cout<<"¿E-mail?"<<endl;
cin.getline(ap->email,15);
cout<<"¿Phone?"<<endl;
cin.getline(ap->phone,10);
ap++;
}
ap=aux;
}
void person::show(agenda *ap)
{
for(int j=0;j<n;j++)
{
cout<<"Name: "<<ap->name<<endl;
cout<<"Address: "<<ap->address<<endl;
cout<<"E-mail: "<<ap->email<<endl;
cout<<"Phone: "<<ap->phone<<endl;
ap++;
}
}
int main(){
person P1;
P1.read();
system("pause");
return 0;
}
Feb 22, 2013 at 12:38am UTC
The member function prototypes of
person::read and
person::show do not have the same parameters as the member function's definitions. You then call an unknown member function with the identifier 'read' that takes no arguments. You can choose to overload these member functions or change their current parameters. You should also write a destructor to deallocate the memory that was allocated in the constructor.
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
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
struct agenda{
char name[30],address[30],email[15],phone[10];
};
class person{
private :
struct agenda *ap;
int n;
public :
person();
~person();
void read(struct agenda *ap);
void show(struct agenda *ap);
void show();
void read();
};
person::person()
{
cout<<"¿Number of persons?: " <<endl;
cin>>n;
ap=new agenda[n];
}
person::~person()
{
delete []ap;
}
void person::read(agenda *ap)
{
agenda *aux=ap;
for (int i=0;i<n;i++)
{
cout<<"¿Name?: " <<endl;
cin.getline(ap->name,30);
cout<<"¿Address: " <<endl;
cin.getline(ap->address,30);
cout<<"¿E-mail?" <<endl;
cin.getline(ap->email,15);
cout<<"¿Phone?" <<endl;
cin.getline(ap->phone,10);
ap++;
}
ap=aux;
}
void person::show(agenda *ap)
{
for (int j=0;j<n;j++)
{
cout<<"Name: " <<ap->name<<endl;
cout<<"Address: " <<ap->address<<endl;
cout<<"E-mail: " <<ap->email<<endl;
cout<<"Phone: " <<ap->phone<<endl;
ap++;
}
}
void person::read() {
}
void person::show() {
}
int main(){
person P1;
P1.read();
return 0;
}
Last edited on Feb 22, 2013 at 12:50am UTC
Feb 22, 2013 at 12:56am UTC
i did that but it doesnt fill the name and the other variables
Last edited on Feb 22, 2013 at 12:56am UTC
Feb 22, 2013 at 1:05am UTC
You're going to have to show your revised code.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
The code in vivre 's post calls read() with no parameters (line 75).
The read function with no parameters (line 65) does nothing.
Feb 22, 2013 at 1:59am UTC
Sorry im new here.
The code is the same than the.vivres and it doesnt fill nothing.and really dont know whats wrong