0% found this document useful (0 votes)
36 views35 pages

Structure 9 Prgms

The document defines four C++ structs (Student, Employee, Admin, Hr_manager) that represent different data types with attributes like name, id, salary etc. Each struct contains default and parameterized constructors to initialize objects, setter and getter methods to set and retrieve attribute values, and a display method to output the object details. The main function demonstrates creating arrays of each struct type, populating attributes, searching for ids, and displaying output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views35 pages

Structure 9 Prgms

The document defines four C++ structs (Student, Employee, Admin, Hr_manager) that represent different data types with attributes like name, id, salary etc. Each struct contains default and parameterized constructors to initialize objects, setter and getter methods to set and retrieve attribute values, and a display method to output the object details. The main function demonstrates creating arrays of each struct type, populating attributes, searching for ids, and displaying output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

1.

Student

#include<iostream>

#include<string.h>

using namespace std;

struct Student

int roll;

char name[30];

Student()

cout<<"\ndefault constructor called....";//default constructor

this->roll=0;

strcpy(this->name,"not given");

Student(int a,char*n)

cout<<"\nparameterized constructor....";//parametrized constructor

this->roll=a;

strcpy(this->name,n);

//setters

void setRoll(int a)

this->roll=a;

void setName(char* n)
{

strcpy(this->name,n);

//getters

int getRoll()

return this->roll;

char* getName()

return this->name;

void display()

cout<<"\nRoll no of student is:"<<this->roll;

cout<<"\nName of student is:"<<this->name;

};//struct ending

int search(Student* ptr,int s);

int main()

Student s1;

int roll;

int i,n;

char name[30];

cout<<"\nEnter value of n";

cin>>n;
Student* ptr;

ptr=new Student[n];

for(i=0;i<n;i++)

cout<<"\nEnter roll no.of a student:";

cin>>roll;

ptr[i].setRoll(roll);

cout<<"\nEnter name of a student:";

cin>>name;

ptr[i].setName(name);

for(i=0;i<n;i++)

ptr[i].display();

cout<<"\n";

int s;

s=search(ptr,2);

if(s!=0)

cout<<"Roll no.found";

else

cout<<"Roll no.not found";


}

int search(Student*ptr,int s)

int num;

int i;

cout<<"Enter roll no to be search:";

cin>>num;

int count=0;

for(i=0;i<2;i++)

if(ptr[i].roll==num)

count++;

break;

return count;

2.Employee

#include<iostream>

#include<string.h>

using namespace std;

struct Employee

int id;

char name[30];

double salary;
Employee()

cout<<"\ndefault constructor called:";//default constructor

this->id=0;

strcpy(this->name,"not given");

this->salary=0;

Employee(int a,char* b,double d)

cout<<"\nparameterized constructor called:";//parameterized constructor

this->id=a;

strcpy(this->name,b);

this->salary=d;

void setId(int a)//setter

this->id=a;

int getId()//getter

return this->id;

void setName(char* b)

strcpy(this->name,b);

char* getName()

return this->name;
}

void setSalary(double d)

this->salary=d;

double getSalary()

return this->salary;

void display()

cout<<"\nEmployee id:"<<this->id;

cout<<"\nEmployee name:"<<this->name;

cout<<"\nEmployee salary:"<<this->salary;

};

int search(Employee* ptr,int s);

int main()

int id;

char name[30];

double salary;

int i,n;

cout<<"Enter value of n";

cin>>n;

Employee* ptr;

ptr=new Employee[n];
for(i=0;i<n;i++)

cout<<"\nEnter employee id:";

cin>>id;

ptr[i].setId(id);

cout<<"Enter employee name:";

cin>>name;

ptr[i].setName(name);

cout<<"Enter employee salary:";

cin>>salary;

ptr[i].setSalary(salary);

for(i=0;i<n;i++)

ptr[i].display();

cout<<"\n";

int s;

s=search(ptr,2);

if(s!=0)

cout<<"ID found";

else

{
cout<<"ID not found";

int search(Employee*ptr,int s)

int num;

int i;

cout<<"Enter ID to be search:";

cin>>num;

int count=0;

for(i=0;i<2;i++)

if(ptr[i].id==num)

count++;

break;

return count;

3.Admin

#include<iostream>

#include<string.h>

using namespace std;

struct Admin

int id;

char name[30];
double salary,allowence;

Admin(){

cout<<"\ndefault constructor called:";//default constructor

this->id=0;

strcpy(this->name,"not given");

this->salary=0;

this->allowence=0;

Admin(int a,char*b,double c,double d)

cout<<"\nparameterized constructor called:";//parameterized constructor

this->id=10;

strcpy(this->name,b);

this->salary=c;

this->allowence=d;

void setId(int a)//setter

this->id=a;

int getId()

return this->id;//getter

}
void setName(char* b)

strcpy(this->name,b);

char* getName()

return this->name;

void setSalary(double c)

this->salary=c;

double getSalary()

return this->salary;

void setAllowence(double d)

this->allowence=d;

double getAllowence()

return this->allowence;

}
void display()

cout<<"\nAdmin id:"<<this->id;

cout<<"\nAdmin name:"<<this->name;

cout<<"\nAdmin salary:"<<this->salary;

cout<<"\nAdmin allowence:"<<this->allowence;

};//structure ending

int search(Admin* ptr,int s);

int main()

int id;

char name[30];

double salary,allowence;

int i,n;

cout<<"Enter value of n";

cin>>n;

Admin* ptr;

ptr=new Admin[n];

for(i=0;i<n;i++)

cout<<"\nEnter admin id";

cin>>id;

ptr[i].setId(id);

cout<<"\nEnter admin name";

cin>>name;

ptr[i].setName(name);
cout<<"\nEnter admin salary";

cin>>salary;

ptr[i].setSalary(salary);

cout<<"\nEnter admin allowence";

cin>>allowence;

ptr[i].setAllowence(allowence);

for(i=0;i<n;i++)

ptr[i].display();

cout<<"\n";

int s;

s=search(ptr,2);

if(s!=0)

cout<<"ID found";

else

cout<<"ID not found";

int search(Admin*ptr,int s)

int num;

int i;
cout<<"Enter ID to be search:";

cin>>num;

int count=0;

for(i=0;i<2;i++)

if(ptr[i].id==num)

count++;

break;

return count;

4.HR manager

#include<iostream>

#include<string.h>

using namespace std;

struct Hr_manager

int id,target;

char name[30];

double salary,commission;

Hr_manager(){

cout<<"\ndefault constructor called:";//default constructor

this->id=0;

strcpy(this->name,"not given");
this->target=0;

this->salary=0;

this->commission=0;

Hr_manager(int a,char* b,double d,double e,int f)

cout<<"\nparameterized constructor called:";//parameterized constructor

this->id=a;

strcpy(this->name,b);

this->salary=d;

this->commission=e;

this->target=f;

void setId(int a)//setter

this->id=a;

int getId()//getter

return this->id;

void setName(char* n)

strcpy(this->name,n);

char* getName()
{

return this->name;

void setSalary(double d)

this->salary=d;

double getSalary()

return this->salary;

void setCommission(double e)

this->commission=e;

double getCommission()

return this->commission;

void setTarget(int f)

this->target=f;

int getTarget()

{
return this->target;

void display()

cout<<"\nHr manager id:"<<this->id;

cout<<"\nHr manager name:"<<this->name;

cout<<"\nHr manager salary:"<<this->salary;

cout<<"\nHr manager commission:"<<this->commission;

cout<<"\nHr manager target:"<<this->target;

};

int search(Hr_manager* ptr,int s);

int main()

int id,target;

char name[30];

double salary,commission;

int i,n;

cout<<"Enter value of n";

cin>>n;

Hr_manager* ptr;

ptr=new Hr_manager[n];

for(i=0;i<n;i++)

cout<<"\nEnter id of hr manager:";

cin>>id;

ptr[i].setId(id);

cout<<"\nEnter name of hr manager:";


cin>>name;

ptr[i].setName(name);

cout<<"\nEnter hr manager salary:";

cin>>salary;

ptr[i].setSalary(salary);

cout<<"\nEnter hr manager commission:";

cin>>commission;

ptr[i].setCommission(commission);

cout<<"\nEnter hr manager target:";

cin>>target;

ptr[i].setTarget(target);

for(i=0;i<n;i++)

ptr[i].display();

cout<<"\n";

int s;

s=search(ptr,2);

if(s!=0)

cout<<"ID found";

else

{
cout<<"ID not found";

int search(Hr_manager*ptr,int s)

int num;

int i;

cout<<"Enter ID to be search:";

cin>>num;

int count=0;

for(i=0;i<2;i++)

if(ptr[i].id==num)

count++;

break;

return count;

5.Sales manager

#include<iostream>

using namespace std;

#include<string.h>

struct Sales_manager

int id,target;
char name[30];

double salary,incentive;

Sales_manager()

cout<<"default constructor called:";//default constructor

this->id=0;

strcpy(this->name,"not given");

this->incentive=0;

this->salary=0;

this->target=0;

Sales_manager(int a,char*n,int c,double d,double e)//parameterized constructor

cout<<"\nparameterized constructor:";

this->id=a;

strcpy(this->name,n);

this->target=c;

this->salary=d;

this->incentive=e;

void setId(int a)//setters

this->id=a;

}
int getId()//getters

return this->id;

void setName(char* n)

strcpy(this->name,n);

char* getName()

return this->name;

void setSalary(double d)

this->salary=d;

double getSalary()

return this->salary;

int setTarget(int c)

this->target=c;

int getTarget()

{
return this->target;

double setIncentive(double e)

this->incentive=e;

double getIncentive()

return this->incentive;

void display()

cout<<"\nsales manager id:"<<this->id;

cout<<"\nsales manager name:"<<this->name;

cout<<"\nsales manager salary:"<<this->salary;

cout<<"\nsales manager target:"<<this->target;

cout<<"\nsales manager incentive:"<<this->incentive;

};

int search(Sales_manager* ptr,int s);

int main()

int id,target;

char name[30];

double salary,incentive;

int i,n;

cout<<"Enter value of n";

cin>>n;
Sales_manager* ptr;

ptr=new Sales_manager[n];

for(i=0;i<n;i++)

cout<<"\nEnter id of sales manager:";

cin>>id;

ptr[i].setId(id);

cout<<"\nEnter name of sales manager:";

cin>>name;

ptr[i].setName(name);

cout<<"\nEnter manager salary:";

cin>>salary;

ptr[i].setSalary(salary);

cout<<"\nEnter manager target:";

cin>>target;

ptr[i].setTarget(target);

cout<<"\nEnter manager incentive:";

cin>>incentive;

ptr[i].setIncentive(incentive);

for(i=0;i<n;i++)

ptr[i].display();

cout<<"\n";
}

int s;

s=search(ptr,2);

if(s!=0)

cout<<"ID found";

else

cout<<"ID not found";

int search(Sales_manager*ptr,int s)

int num;

int i;

cout<<"Enter ID to be search:";

cin>>num;

int count=0;

for(i=0;i<2;i++)

if(ptr[i].id==num)

count++;

break;

return count;
}

6.Date

#include<iostream>

using namespace std;

#include<string.h>

struct Date

int day,month,year;

Date()

printf("\ndefault constructor called:");//default constructor

this->day=0;

this->month=0;

this->year=0;

Date(int a,int b,int c)

printf("\nparameterized constructor called:");//parameterized constructor

this->day=10;

this->month=2;

this->year=1996;

void setDay(int a)//setter

{
this->day=a;

void setMonth(int b)

this->month=b;

void setYear(int c)

this->year=c;

int getDay()//getter

return this->day;

int getMonth()

return this->month;

int getYear()

return this->year;

void display()

cout<<"\nDay is:"<<this->day;

cout<<"\nMonth is:"<<this->month;

cout<<"\nYear is:"<<this->year;

}
};

int search(Date* ptr,int s);

int main()

int day,month,year;

int i,n;

cout<<"Enter value of n";

cin>>n;

Date* ptr;

ptr=new Date[n];

for(i=0;i<n;i++)

cout<<"\nEnter Day:";

cin>>day;

ptr[i].setDay(day);

cout<<"Enter month:";

cin>>month;

ptr[i].setMonth(month);

cout<<"Enter year:";

cin>>year;

ptr[i].setYear(year);

for(i=0;i<n;i++)

ptr[i].display();

cout<<"\n";
}

int s;

s=search(ptr,2);

if(s!=0)

cout<<"day found";

else

cout<<"day not found";

int search(Date*ptr,int s)

int num;

int i;

cout<<"Enter day to be search:";

cin>>num;

int count=0;

for(i=0;i<2;i++)

if(ptr[i].day==num)

count++;

break;

return count;
}

8.Distance

#include<iostream>

using namespace std;

struct Distance

int feet,inches;

Distance()

cout<<"\ndefault constructor called:";//default constructor

this->feet=0;

this->inches=0;

Distance(int a,int b)

cout<<"\nparameterized constructor called:";//parameterized constructor

this->feet=a;

this->inches=b;

void setFeet(int a)//setter

this->feet=a;

void setInches(int b)

this->inches=b;

}
int getFeet()//getter

return this->feet;

int getInches()

return this->inches;

void display()

cout<<"\nDistance in feet:"<<this->feet;

cout<<"\nDistance in inches:"<<this->inches;

};

int search(Distance* ptr,int s);

int main()

int feet,inches;

int n,i;

cout<<"Enter value of n";

cin>>n;

Distance* ptr;

ptr=new Distance[n];

for(i=0;i<n;i++)

cout<<"\nEnter distance in feet:";

cin>>feet;

ptr[i].setFeet(feet);
cout<<"\nEnter distance in inches:";

cin>>inches;

ptr[i].setInches(inches);

for(i=0;i<n;i++)

ptr[i].display();

cout<<"\n";

int s;

s=search(ptr,2);

if(s!=0)

cout<<"feet found";

else

cout<<"feet not found";

int search(Distance*ptr,int s)

int num;

int i;

cout<<"Enter feet to be search:";

cin>>num;

int count=0;

for(i=0;i<2;i++)
{

if(ptr[i].feet==num)

count++;

break;

return count;

9.Time

#include<iostream>

using namespace std;

struct Time

int hrs,min,sec;

Time(){

cout<<"\ndefault constructor called:";//default constructor

this->hrs=0;

this->min=0;

this->sec=0;

Time(int a,int b,int c)

cout<<"\nparameterized constructor called:";//parameterized constructor


this->hrs=a;

this->min=b;

this->sec=c;

void setHrs(int a)//setter

this->hrs=a;

void setMin(int b)

this->min=b;

void setSec(int c)

this->sec=c;

int getHrs()//getter

return this->hrs;

int getMin()

return this->min;

int getSec()
{

return this->sec;

void display()

cout<<"\nHours are:"<<this->hrs;

cout<<"\nMins are:"<<this->min;

cout<<"\nSecs are:"<<this->sec;

};

int search(Time* ptr,int s);

int main()

int hrs,min,sec;

int i,n;

cout<<"Enter value of n";

cin>>n;

Time* ptr;

ptr=new Time[n];

for(i=0;i<n;i++)

cout<<"\nEnter time in hours:";

cin>>hrs;

ptr[i].setHrs(hrs);

cout<<"\nEnter time in minutes:";

cin>>min;

ptr[i].setMin(min);
cout<<"\nEnter time in seconds:";

cin>>sec;

ptr[i].setSec(sec);

for(i=0;i<n;i++)

ptr[i].display();

cout<<"\n";

int s;

s=search(ptr,2);

if(s!=0)

cout<<"Hours found";

else

cout<<"Hours not found";

int search(Time*ptr,int s)

int num;

int i;

cout<<"Enter hours to be search:";

cin>>num;

int count=0;

for(i=0;i<2;i++)

if(ptr[i].hrs==num)
{

count++;

break;

return count;

You might also like