Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<conio.h>
- using namespace std;
- class Emp
- {
- public:
- int id;
- char name[30];
- void getData()
- {
- cout<<"\n Enter id of the employee: ";
- cin>>id;
- cout<<" \n Enter name of employee : ";
- cin>>name;
- }
- void display()
- {
- cout<<"\n ID of the employee : "<<this->id;
- cout<<"\n Name of the employee: "<<this->name;
- }
- };
- int main()
- {
- int choice;
- cout<<"\n\n ********* MENU **********";
- cout<<"\n1.Array of Objects";
- cout<<"\n2.Dynamic Allocation of Memory";
- cout<<"\n3.Exit";
- while(choice!=3)
- {
- cout<<"\nEnter your Choice: ";
- cin>>choice;
- switch(choice)
- {
- case 1:
- cout<<"\n\nEnter Your Choice: ";
- cin>>choice;
- Emp emp[30];
- int n,i;
- cout<<"\n Enter number of employee: ";
- cin>>n;
- for(i = 0; i<n; i++)
- {
- emp[i].getData();
- }
- for(i = 0; i<n; i++)
- {
- emp[i].display();
- }
- break;
- case 2:
- int* p = NULL;
- p = new(nothrow) int;
- if(!p)
- {
- cout<<"\n Memory is not allocated some error occured";
- }
- else
- {
- *p = 20;
- cout << "\n\nValue of p: " << *p << endl;
- }
- delete p;
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement