Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mirajehossain/a82799777f98e5845b19489cb1a09214 to your computer and use it in GitHub Desktop.
Save mirajehossain/a82799777f98e5845b19489cb1a09214 to your computer and use it in GitHub Desktop.
/**
* Create a student class and two overloading constructor which are takes parameters,
* create array of object and set two constructor dynamically and print information.
**/
#include<iostream>
using namespace std;
class student
{
public:
int id;
string name;
string department;
public:
student() {}
public:
student(int id)
{
this->id = id;
cout<<"from 1 - "<<id <<endl;
}
public:
void printDetail()
{
cout<< "name is: "<< name << " and ID is : "<<id<<endl;
}
public:
student(int id, string name)
{
this->id = id;
this->name = name;
}
};
int main()
{
int i;
student st[3];
for(i=0; i<=3; i++)
{
int id;
string name;
cin>> id;
cin>> name;
st[i] =
{
student(id,name)
};
}
for(i=0; i<=3; i++)
{
cout<<"ID : "<<st[i].id<<" and Name: "<<st[i].name<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment