//为什么编译有错,求帮助,我是菜鸟。
#include <set>
#include <iostream>
#include <string>
using namespace std;
class Date{
public:
Date();
Date(int age, char st[]);
void Display();
int age;
char name[20];
};
class Person{
protected:
set<Date> p;
public:
int number;
Person();
Person(int age, char *st);
//bool operator < (const Date & pe);
Date d;
void Input();
void Output();
};
void Run();
Date::Date(){
age = 0;
strcpy(name,"00");
}
Date::Date(int age, char st[]){
(*this).age = age;
strcpy(name,st);
}
void Date::Display(){
cout<<"age = "<<age<<endl;
cout<<"name = "<<name<<endl;
}
Person::Person(){
d.age = 0;
strcpy(d.name,"00");
}
Person::Person(int age,char *st){
(*this).d.age = age;
strcmp((*this).d.name,st);
}
/*
bool Person::operator < (const Date & da){
if(number < da.age) return true;
else return false;
}
*/
void Person::Input(){
int age;
char na[20];
cout<<"input age:";
cin>>age;
cout<<"input name:";
cin>>na;
Date d(age,na);
p.insert(d);
cout<<"input complete!"<<endl;
}
void Person::Output(){
set<Date>::iterator P = p.begin();
while(P != p.end())
{
P->Display();
P++;
}
}
int main(){
Run();
return 0;
}
void Run(){
Person pe;
char ch = 'y';
while(ch == 'y'){
pe.Input();
cout<<"continue?(y/n):";
cin>>ch;
}
pe.Output();
}
#include <set>
#include <iostream>
#include <string>
using namespace std;
class Date{
public:
Date();
Date(int age, char st[]);
void Display();
int age;
char name[20];
};
class Person{
protected:
set<Date> p;
public:
int number;
Person();
Person(int age, char *st);
//bool operator < (const Date & pe);
Date d;
void Input();
void Output();
};
void Run();
Date::Date(){
age = 0;
strcpy(name,"00");
}
Date::Date(int age, char st[]){
(*this).age = age;
strcpy(name,st);
}
void Date::Display(){
cout<<"age = "<<age<<endl;
cout<<"name = "<<name<<endl;
}
Person::Person(){
d.age = 0;
strcpy(d.name,"00");
}
Person::Person(int age,char *st){
(*this).d.age = age;
strcmp((*this).d.name,st);
}
/*
bool Person::operator < (const Date & da){
if(number < da.age) return true;
else return false;
}
*/
void Person::Input(){
int age;
char na[20];
cout<<"input age:";
cin>>age;
cout<<"input name:";
cin>>na;
Date d(age,na);
p.insert(d);
cout<<"input complete!"<<endl;
}
void Person::Output(){
set<Date>::iterator P = p.begin();
while(P != p.end())
{
P->Display();
P++;
}
}
int main(){
Run();
return 0;
}
void Run(){
Person pe;
char ch = 'y';
while(ch == 'y'){
pe.Input();
cout<<"continue?(y/n):";
cin>>ch;
}
pe.Output();
}