0% found this document useful (0 votes)
20 views9 pages

Mutator Assisgnment

The document defines 9 C++ structs representing different data types (student, employee, admin, etc.) with member variables and member functions to set and display values. Each struct is defined and tested in its own main function, with functions to set member variable values and display them. The structs demonstrate encapsulation by wrapping data and functions together to represent real world entities.
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)
20 views9 pages

Mutator Assisgnment

The document defines 9 C++ structs representing different data types (student, employee, admin, etc.) with member variables and member functions to set and display values. Each struct is defined and tested in its own main function, with functions to set member variable values and display them. The structs demonstrate encapsulation by wrapping data and functions together to represent real world entities.
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/ 9

//1.

Student:

#include<stdio.h>
#include<string.h>
struct student
{
int roll_no;
char name[20];
float marks;

void setroll_no(int rol)


{
this->roll_no = rol;
}

void setname(const char * nm)


{
strcpy(this->name, nm);
}

void setmarks(float mks)


{
this->marks = mks;
}

void display() // void display(student * this)


{
printf("\n\nStudent Roll_no is: %d\nStudent name is: %s\nStudent marks is: %.2f ",
this->roll_no,this->name,this->marks);
}
}; // Struct ends here

int main()
{
student s2;
student s1;

s1.setroll_no(23); //s1.roll_no = 23;


s1.setname("Prathamesh"); //strcpy(s1.name,"prathamesh");
s1.setmarks(96); //s1.marks = 96;

s1.display(); // display(&s1);
s2.display();

return 0;

}
//2.Employee:
#include<stdio.h>
#include<string.h>
struct employee
{
int emp_id;
char emp_name[20];
double salary;

void setemp_id(int ad)


{
this->emp_id = ad;
}

void setemp_name(const char * nm)


{
strcpy(this->emp_name, nm);
}

void setsalary(double sal)


{
this->salary = sal;
}

void display() //void display(employee* ptr)


{
printf("Empolyee id is: %d\nEmployee name is: %s\nEmployee Salary is: %.2lf Rs ",
this->emp_id,this->emp_name,this->salary);
}
};// struct ends here

int main()
{
employee e1;

e1.setemp_id(23); //e1.emp_id= 23;


e1.setemp_name("Prathamesh"); //strcpy(e1.emp_name,"Prathamesh");
e1.setsalary(46000); //e1.salary= 46000;

e1.display(); //display(&e1);

return 0;

}
//3.Admin:
#include<stdio.h>
#include<string.h>
struct admin
{
int admin_id;
char admin_name[20];
double salary,allounce;

void setadmin_id(int ad)


{''
this->admin_id = ad;
}

void setadmin_name(const char * nm)


{
strcpy(this->admin_name, nm);
}

void setsalary(double sal)


{
this->salary = sal;
}

void setallounce(double all)


{
this->allounce = all;
}

void display() // void display(admin* ptr)


{
printf("Admin id is: %d\n",this->admin_id);
printf("Admin name is: %s\n",this->admin_name);
printf("Admin Salary is: %0.2lf Rs\n",this->salary);
printf("Admin allounce is: %0.2lf Rs\n",this->allounce);

}
}; // struct ends here

int main()
{

admin a1;

a1.setadmin_id(23); // a1.admin_id= 23;


a1.setadmin_name("Prathamesh"); // strcpy(a1.admin_name,"Prathamesh");
a1.setsalary(45000); // a1.salary= 45000;
a1.setallounce(5000); // a1.allounce= 5000;

a1.display(); //display(&a1);

return 0;
}
//4.HR Manager:
#include<stdio.h>
#include<string.h>
struct hr_manager
{
int id;
char name[20];
double salary,commision;

void setid(int ad)


{
this->id = ad;
}

void setname(const char * nm)


{
strcpy(this->name, nm);
}

void setsalary(double sal)


{
this->salary = sal;
}

void setcommision(double com)


{
this->commision = com;
}

void display() //void display(hr_manager * ptr)


{
printf("Hr manager id is: %d\nHr manager name is: %s\nHr manager Salary is: %0.2lf
Rs\nHr manager commision is: %0.2lf Rs ", this->id,this->name,this->salary,this->commision);
}

}; //struct ends here

int main()
{
hr_manager h1;

h1.setid(1); // h1.id= 1;
h1.setname("Prathamesh"); // strcpy(h1.name,"Prathamesh");
h1.setsalary(45000); // h1.salary = 45000;
h1.setcommision(5000); // h1.commision = 5000;

h1.display(); //display(&h1);

return 0;

}
//5.Sales Manager:
#include<stdio.h>
#include<string.h>
struct salesmanager
{
int sman_id;
char sman_name[20];
double target,salary,incentive;

void setsman_id(int ad)


{
this->sman_id = ad;
}
void setsman_name(const char * nm)
{
strcpy(this->sman_name, nm);
}
void settarget(double tar)
{
this->target = tar;
}
void setsalary(double sal)
{
this->salary = sal;
}
void setincentive(double inc)
{
this->incentive = inc;
}

void display() //void display(salesmanager * ptr)


{
printf("Salesmanager id is: %d\n",this->sman_id);
printf("Salesmanager name is: %s\n",this->sman_name);
printf("Salesmanager Salary is: %0.2lf Rs\n",this->salary);
printf("Salesmanager incentive is: %0.2lf Rs\n",this->incentive);
printf("Salesmanager Target is: %.2lf Rs\n",this->target);
}
}; //struct ends here

int main()
{
salesmanager s1;

s1.setsman_id(23); // s1.sman_id= 23;


s1.setsman_name("prathamesh"); //strcpy(s1.sman_name,"Prathamesh");
s1.settarget(45000); // s1.salary= 45000;
s1.setsalary(3000); // s1.target=3000;
s1.setincentive(6000); // s1.incentive=6000;

s1.display(); // display(&s1);

return 0;

}
//6.Date:
#include<stdio.h>
#include<string.h>
struct date
{

int day,month,year;

void setday(int d)
{
this->day = d;
}

void setmonth (int m)


{
this->month = m;
}

void setyear (int y)


{
this->year = y;
}

void display() //void display(date * ptr)


{
printf("Date : %d/%d/%d",this->day,this->month,this->year);
}

}; //struct ends here.

int main()
{
date d1;

d1.setday(10); //d1.day=10;
d1.setmonth(02); //d1.month=02;
d1.setyear(2023); //d1.year=2023;

d1.display(); //display(&d1);

return 0;
}
//7.Time:
#include<stdio.h>
struct time
{

int hr,min,sec;

void sethr(int h)
{
this->hr = h;
}

void setmin(int m)
{
this->min = m;
}

void setsec(int s)
{
this->sec = s;
}

void display() //void display(time * ptr)


{
printf("Time : %d:%d:%d",this->hr,this->min,this->sec);
}

}; // Struct ends here

int main()
{
time t1;

t1.sethr(4); // t1.hr=4;
t1.setmin(23); // t1.min=23;
t1.setsec(45); // t1.sec=45;

t1.display(); //display(&t1);

return 0;
}
//8.Distance:
#include<stdio.h>
#include<string.h>
struct distance
{
int feet,inch;

void setfeet(int fe)


{
this->feet = fe;
}

void setinch (int in)


{
this->inch = in;
}

void display() //void display(distance * ptr)


{
printf("Distance is %d feet %d inch",this->feet,this->inch);
}

}; //Struct ends here

int main()
{
distance d1;

d1.setfeet(12); //d1.feet=12;
d1.setinch(9); //d1.inch=9;

d1.display(); //display(&d1);

return 0;
}
//9.Complex:
#include<stdio.h>
#include<string.h>
struct complex
{

int real,imag;

void setreal(int c)
{
this->real = c;
}

void setimag(int img)


{
this->imag = img;
}

void display() // void display(complex * this)


{
printf("%d + %di",this->real,this->imag);
}

}; // Struct ends here

int main()
{
complex c1;

c1.setreal(10); // c1.real= 10;


c1.setimag(5); // c1.imag=5;

c1.display(); // display(&c1);

return 0;
}

You might also like