#include
#include
//class definition
class student
{
//hidden part
private:
char* name; //for student's name
char* id; //for id
char* email; // for email
//interface
public:
//paramterless constructor
student()
{
name="Adnan";
id="Mc002563686";
email="help@vuhelp.com";
}
//parameterized constructor
student(char* name1, char* id1, char* email1)
{
name = name1;
id = id1;
email = email1;
}
//copy constructor
student(const student &other)
{
//for string lengths
int length1, length2, length3;
length1 = strlen(other. name);
length2 = strlen(other. id);
length3 = strlen(other. email);
//allocating new memory space
name = new char[length1 + 1];
id = new char[length2 + 1];
email = new char[length3+1];
//copying strings
strcpy( name, other.name );
strcpy( id, other.id );
strcpy( email, other.email);
}
//for displaying name, id and email address
void display()
{
cout< cout<<"_________________"< }
//destructor
~student(){}
};
//main function
int main(){
//object declarations
student s1;
student s2("Jawad", "mc007004005", "vuexpert@gmail.com");
student s3(s2);
//display function calls
s1.display();
s2.display();
s3.display();
}
#include
//class definition
class student
{
//hidden part
private:
char* name; //for student's name
char* id; //for id
char* email; // for email
//interface
public:
//paramterless constructor
student()
{
name="Adnan";
id="Mc002563686";
email="help@vuhelp.com";
}
//parameterized constructor
student(char* name1, char* id1, char* email1)
{
name = name1;
id = id1;
email = email1;
}
//copy constructor
student(const student &other)
{
//for string lengths
int length1, length2, length3;
length1 = strlen(other. name);
length2 = strlen(other. id);
length3 = strlen(other. email);
//allocating new memory space
name = new char[length1 + 1];
id = new char[length2 + 1];
email = new char[length3+1];
//copying strings
strcpy( name, other.name );
strcpy( id, other.id );
strcpy( email, other.email);
}
//for displaying name, id and email address
void display()
{
cout<
//destructor
~student(){}
};
//main function
int main(){
//object declarations
student s1;
student s2("Jawad", "mc007004005", "vuexpert@gmail.com");
student s3(s2);
//display function calls
s1.display();
s2.display();
s3.display();
}
Post a Comment