#include <iostream>
#include "Person.h"
using namespace std;
int main()
{
Person p;
p.getName();
p.setAge(
14);
p.getAge();
return 0;
}
#include <iostream>
using namespace std;
class Person{
public:
void setAge(
int newAge);
void getAge();
void getName();
Person(
int a,
char n){
age=a;
name=n;
}
Person(Person &p);
int geta(){
return age;}
char getn(){
return name;}
private:
int age;
char name;
};
Person::Person(Person &p)
{
age=p.age;
name=p.name;
cout<<
"copy"<<endl;
}
void Person::setAge(
int newAge)
{
age=newAge;
}
void Person::getAge()
{
cout<<age<<endl;
}
void Person::getName()
{
cout<<name<<endl;
}
int main()
{
Person p(
14,
's');
Person b(p);
cout<<b.geta()<<endl;
cout<<b.getn()<<endl;
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
class Person{
public:
void setAge(
int newAge);
void getAge();
void getName();
Person(
int a,
char n){
age=a;
name=n;
}
Person(Person &p);
int geta(){
return age;}
char getn(){
return name;}
private:
int age;
char name;
};
Person::Person(Person &p)
{
age=p.age;
name=p.name;
cout<<
"copy"<<endl;
}
void Person::setAge(
int newAge)
{
age=newAge;
}
void Person::getAge()
{
cout<<age<<endl;
}
void Person::getName()
{
cout<<name<<endl;
}
int main()
{
int i=
0;
vector <int>h;
Person p(
14,
's');
Person b(p);
h.resize(
3);
h[
0]=b.geta();
Person t(
15,
'g');
Person r(t);
h[
1]=r.geta();
Person s(
16,
'q');
Person w(s);
h[
2]=w.geta();
for(i=
0;i<
3;i++)
{
cout<<h[i]<<endl;
}
return 0;
}
#include <iostream>
using namespace std;
class Person{
public:
void setAge(
int newAge);
void getAge();
void getName();
Person(
int a,
char n){
age=a;
name=n;
}
Person();
Person(Person &p);
int geta(){
return age;}
char getn(){
return name;}
int age;
char name;
};
Person::Person(Person &p)
{
age=p.age;
name=p.name;
cout<<
"copy"<<endl;
}
void Person::setAge(
int newAge)
{
age=newAge;
}
void Person::getAge()
{
cout<<age<<endl;
}
void Person::getName()
{
cout<<name<<endl;
}
int main()
{
Person *q=
new Person(
3,
's');
cout<<q->geta()<<endl;
cout<<q->getn()<<endl;
delete []q;
return 0;
}
转载请注明原文地址: https://ju.6miu.com/read-16859.html