Showing Page:
1/7
Data Structure Algorithm
Submitted by:
Student Name: Abdullah
Student Id: 2020F-mulbscs-154
Section: 3
rd
D semester
Submitted to:
Sir Hamza
Submission Date:
Feb,16, 2021
#include <iostream>
using namespace std;
class Person
{
private:
string name;
int age;
string CNIC;
string contact;
Showing Page:
2/7
public:
Person()
{
name = "";
age = 0;
CNIC = "";
contact = "";
}
void setName(string name)
{
this->name = name;
}
string getName()
{
return name;
}
void setAge(int age)
{
this->age= age;
}
int getAge()
{
return age;
}
Showing Page:
3/7
void setCNIC(string CNIC)
{
this->CNIC = CNIC;
}
string getCNIC()
{
return CNIC;
}
void setContact(string contact)
{
this->contact = contact;
}
string getContact()
{
return contact;
}
void display()
{
cout<<"Name: "<<getName();
cout<<"\nAge: "<<getAge();
cout<<"\nCNIC: "<<getCNIC();
cout<<"\nContact: "<<getContact()<<endl;
}
};
class Stack
Showing Page:
4/7
{
private:
Person p;
int stack_size;
Person *arr;
int size;
public:
Stack(int size)
{
this->size = size;
arr = new Person[size];
stack_size = 0;
}
void push(Person p)
{
if(stack_size == size)
{
cout<<"Error Stack is full\n\n";
}
else
{
arr[stack_size]= p;
stack_size++;
}
}
Showing Page:
5/7
void pop()
{
if(stack_size == size)
{
arr[stack_size-2] = arr[stack_size-1];
stack_size--;
}
else
{
arr[stack_size-1] = arr[stack_size];
stack_size--;
}
}
void display()
{
for(int i=0;i<=stack_size-1;i++)
{
arr[i].display();
cout<<"\n";
}
cout<<"The current size of stack is "<<stack_size;
cout<<"\n__________________\n";
}
};
Showing Page:
6/7
int main()
{
Person p1;
p1.setName("fatima");
p1.setAge(99);
p1.setCNIC("1234-25246488-7");
p1.setContact("1245678910");
Person p2;
p2.setName("batool");
p2.setAge(50);
p2.setCNIC("3309-879834321-4");
p2.setContact("0987654");
Person p3;
p3.setName("anum");
p3.setAge(75);
p3.setCNIC("3489-557647-2");
p3.setContact("0859326");
Person p4;
p4.setName("abc");
p4.setAge(60);
p4.setCNIC("3489-3334544-2");
p4.setContact("999999999");
Person p5;
p5.setName("wxy");
Showing Page:
7/7
p5.setAge(15);
p5.setCNIC("3000-19919-8");
p5.setContact("888888888");
Person p6;
p6.setName("def");
p6.setAge(25);
p6.setCNIC("3000-24657-6");
p6.setContact("888888888");
Stack s1(5);
s1.push(p1);
s1.push(p2);
s1.push(p3);
s1.push(p4);
s1.push(p5);
s1.push(p5);
s1.display();
s1.pop();
s1.pop();
s1.display();
return 0;
}

Unformatted Attachment Preview

Data Structure Algorithm Submitted by: • Student Name: Abdullah • Student Id: 2020F-mulbscs-154 • Section: 3rd D semester Submitted to: • Sir Hamza Submission Date: • Feb,16, 2021 #include using namespace std; class Person { private: string name; int age; string CNIC; string contact; public: Person() { name = ""; age = 0; CNIC = ""; contact = ""; } void setName(string name) { this->name = name; } string getName() { return name; } void setAge(int age) { this->age= age; } int getAge() { return age; } void setCNIC(string CNIC) { this->CNIC = CNIC; } string getCNIC() { return CNIC; } void setContact(string contact) { this->contact = contact; } string getContact() { return contact; } void display() { cout<<"Name: "<size = size; arr = new Person[size]; stack_size = 0; } void push(Person p) { if(stack_size == size) { cout<<"Error Stack is full\n\n"; } else { arr[stack_size]= p; stack_size++; } } void pop() { if(stack_size == size) { arr[stack_size-2] = arr[stack_size-1]; stack_size--; } else { arr[stack_size-1] = arr[stack_size]; stack_size--; } } void display() { for(int i=0;i<=stack_size-1;i++) { arr[i].display(); cout<<"\n"; } cout<<"The current size of stack is "<
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4