struct

3 views
Skip to first unread message

Ashvazadangahe

unread,
Jun 4, 2009, 4:23:59 AM6/4/09
to ITBP
barnameye zir tooye jabe ja kardane struct ha mosheklel are
nemitoonam moshkelo peyda konam
mamanoon misham komak konid


#include <iostream>
#include <string.h>
using namespace std;

struct employee
{
char name[20];
char family[20];
int age,code,resume;
double salary;
};
//employee temp;
//employee e_list[50];

double ave_age (employee a[],int n)
{
double t=0,temp=0;
for(int i=0;i<n;i++)
temp+=a[i].age;
t=temp/n;
return t;
}

double ave_salary(employee a[],int n)
{

double t,temp=0;
for (int i=0;i<n;i++)
temp+=a[i].salary;
t=temp/n;
return t;
}

double ave_resume(employee a[],int n)
{

double t,temp=0;
for(int i=0;i<n;i++)
temp+=a[i].resume;
t=temp/n;
return t;
}



void sort_name (employee a[], int n)
{
employee temp2;
int com;
for(int i=0; i<n ;i++)
for(int j=0 ; j<n ; j++ )
{
com=strcmp(a[j].name,a[j+1].name);
if(com>0)
{
temp2=a[j];
a[j]=a[j+1];
a[j+1]=temp2;
}
else
break;
}
}
void sort_family(employee a[],int n)
{
employee temp2;
int com;
for (int i=0 ; i<n ; i++)
for(int j=0 ; j<n ; j++)
{
com=strcmp (a[j].family , a[j+1].family);
if (com>0)
{
temp2=a[j];
a[j]=a[j+1];
a[j+1]=temp2;
}
else
break;
}
}

void sort_age(employee a[], int n)
{

employee temp2;

for (int i=0 ; i<n ; i++)
for(int j=0 ; j<n ; j++)
{

if(a[j].age > a[j+1].age)
{
temp2=a[j];
a[j]=a[j+1];
a[j+1]=temp2;
}
else
break;
}
}
void sort_code(employee a[], int n )
{
employee temp2;
for(int i=0 ; i<n ; i++)
for(int j=0 ; j<n ; j++)
{
if (a[j].code > a[j+1].code)
{
temp2=a[j];
a[j]=a[j+1];
a[j+1]=temp2;
}
else
break;
}
}
void sort_salary(employee a[] , int n )
{
employee temp2;
for(int i=0 ; i<n ; i++)
for (int j=0 ; j<n ; j++)
{
if (a[j].salary > a[j+1].salary)
{
temp2=a[j];
a[j]=a[j+1];
a[j+1]=temp2;
}
else
break;
}
}
void sort_resume( employee a[] , int n)
{
employee temp2;
for(int i=0 ; i<n ; i++)
for(int j=0 ; j<n ; j++)
{
if(a[j].resume > a[j+1].resume)
{
temp2=a[j];
a[j]=a[j+1];
a[j+1]=temp2;
}
else
break;
}
}

int main ()
{
employee e_list[50];
const int m=3;
char s='q';
cout<<"Fill the following form for 50 emloyees"<<endl;
cout<<"after entering the enteries, to quit the program enter
X."<<endl;
for(int i=0 ; i<m ; i++)
{
cout<<"==========Employee NO."<<i+1<<"=========="<<endl;
cout<<"Name of employee "<<endl;
cin>>e_list[i].name;
cout<<"Family name of employee"<<endl;
cin>>e_list[i].family;
cout<<"Age of employee"<<endl;
cin>>e_list[i].age;
cout<<"Code of employee"<<endl;
cin>>e_list[i].code;
cout<<"Salary of employee"<<endl;
cin>>e_list[i].salary;
cout<<"Resume of employee"<<endl;
cin>>e_list[i].resume;
cout<<"=========================================="<<endl;
}

while (s!='x')
{
cout<<"With the following menu your enteries will be shown at the
selected category"<<endl;
cout<<"Enter the code of the selected category of the following menu
bellow"<<endl;
cout<<"A. Show all of the enteries."<<endl;
cout<<"B. show the name of the employees"<<endl;
cout<<"C. show the family name of the employees"<<endl;
cout<<"D. show the age of employees"<<endl;
cout<<"E. Show the code of employees"<<endl;
cout<<"F. Show the salary of employee"<<endl;
cout<<"G. show the resume of employees"<<endl;
cout<<"H. The average of employees' age"<<endl;
cout<<"I. The average of employees' salary"<<endl;
cout<<"J. The average of employes' resume"<<endl;
cout<<"K. Sort enteries by name"<<endl;
cout<<"L. Sort enteries by family name"<<endl;
cout<<"M. Sort enteries by age"<<endl;
cout<<"N. Sort enteries by code"<<endl;
cout<<"O. Sort enteries by salary"<<endl;
cout<<"P. Sort enteries by resume"<<endl;

cin>>s;
switch (s)
{
case 'a':
for(int i=0 ; i<m ; i++)
{
cout<<"\n\n============Employee No."<<i+1<<"============\n\n";
cout<<"Name:"<<e_list[i].name<<"\tFamily Name:"<<e_list
[i].family<<endl;
cout<<"Employee code:"<<e_list[i].code<<"\tResume:"<<e_list
[i].resume<<endl;
cout<<"Age:"<<e_list[i].age<<endl;
cout<<"Salary:"<<e_list[i].salary<<endl;
cout<<"\n============================================"<<endl;
}
break;


case 'b':
for(int i=0 ; i<m ; i++)
{
cout<<"\n\n============Employee No."<<i+1<<"============\n\n";
cout<<"Name of employee:"<<e_list[i].name<<endl;
cout<<"\n=================================================";

}
break;

case 'c':
for(int i=0 ; i<m ; i++)
{
cout<<"\n\n============Employee No."<<i+1<<"============\n\n";
cout<<"Family name of employee:"<<e_list[i].family<<endl;
cout<<"\n=================================================";

}
break;
case 'd':
for(int i=0 ; i<m ; i++)
{
cout<<"\n\n============Employee No."<<i+1<<"============\n\n";
cout<<"Age of employee:"<<e_list[i].age<<endl;
cout<<"\n=================================================";

}
break;
case 'e':
for(int i=0 ; i<m ; i++)
{
cout<<"\n\n============Employee No."<<i+1<<"============\n\n";
cout<<"Code of employee:"<<e_list[i].code <<endl;
cout<<"\n=================================================";

}
break;
case 'f':
for(int i=0 ; i<m ; i++)
{
cout<<"\n\n============Employee No."<<i+1<<"============\n\n";
cout<<"Salary of employee:"<<e_list[i].salary<<endl;
cout<<"\n=================================================";

}
break;
case 'g':
for(int i=0 ; i<m ; i++)
{
cout<<"\n\n============Employee No."<<i+1<<"============\n\n";
cout<<"Resume of employee:"<<e_list[i].resume<<endl;
cout<<"\n=================================================";

}
break;
case 'h':
cout<<"========================================"<<endl;
cout<<"The average of employees' age is:"<<endl;
cout<<"****\t"<<ave_age(e_list, m )<<"\t****"<<endl;
cout<<"========================================"<<endl;
break;

case 'i':
cout<<"========================================"<<endl;
cout<<"The average of employees' salary is:"<<endl;
cout<<"****\t"<<ave_salary ( e_list, m )<<"\t****"<<endl;
cout<<"========================================"<<endl;
break;
case 'j':
cout<<"========================================"<<endl;
cout<<"The average of employees' resume is:"<<endl;
cout<<"****\t"<<ave_resume( e_list, m )<<"\t****"<<endl;
cout<<"========================================"<<endl;
break;
case 'k':
cout<<"Your enteries are sorted by name in following form"<<endl;
sort_name( e_list, m );
for (int i=0 ; i<m ; i++)
{
cout<<"\n\n============Employee No."<<i+1<<"============\n\n";
cout<<"Name:"<<e_list[i].name<<"\tFamily Name:"<<e_list
[i].family<<endl;
cout<<"Employee code:"<<e_list[i].code<<"\tResume:"<<e_list
[i].resume<<endl;
cout<<"Age:"<<e_list[i].age<<endl;
cout<<"Salary:"<<e_list[i].salary<<endl;
cout<<"\n============================================"<<endl;
}
break;
case 'l':
cout<<"Your enteries are sorted by family name in following
form"<<endl;
sort_family( e_list, m );
for (int i=0 ; i<m ; i++)
{
cout<<"\n\n============Employee No."<<i+1<<"============\n\n";
cout<<"Name:"<<e_list[i].name<<"\tFamily Name:"<<e_list
[i].family<<endl;
cout<<"Employee code:"<<e_list[i].code<<"\tResume:"<<e_list
[i].resume<<endl;
cout<<"Age:"<<e_list[i].age<<endl;
cout<<"Salary:"<<e_list[i].salary<<endl;
cout<<"\n============================================"<<endl;
}
break;
case 'm':
cout<<"Your enteries are sorted by age in following form"<<endl;
sort_age( e_list, m );
for (int i=0 ; i<m ; i++)
{
cout<<"\n\n============Employee No."<<i+1<<"============\n\n";
cout<<"Name:"<<e_list[i].name<<"\nFamily Name:"<<e_list
[i].family<<endl;
cout<<"Employee code:"<<e_list[i].code<<"\tResume:"<<e_list
[i].resume<<endl;
cout<<"Age:"<<e_list[i].age<<endl;
cout<<"Salary:"<<e_list[i].salary<<endl;
cout<<"\n============================================"<<endl;
}
break;
case 'n':
cout<<"Your enteries are sorted by code in following form"<<endl;
sort_code( e_list, m );
for (int i=0 ; i<m ; i++)
{
cout<<"\n\n============Employee No."<<i+1<<"============\n\n";
cout<<"Name:"<<e_list[i].name<<"\nFamily Name:"<<e_list
[i].family<<endl;
cout<<"Employee code:"<<e_list[i].code<<"\tResume:"<<e_list
[i].resume<<endl;
cout<<"Age:"<<e_list[i].age<<endl;
cout<<"Salary:"<<e_list[i].salary<<endl;
cout<<"\n============================================"<<endl;
}
break;
case 'o':
cout<<"Your enteries are sorted by salary in following form"<<endl;
sort_salary( e_list, m );
for (int i=0 ; i<m ; i++)
{
cout<<"\n\n============Employee No."<<i+1<<"============\n\n";
cout<<"Name:"<<e_list[i].name<<"\nFamily Name:"<<e_list
[i].family<<endl;
cout<<"Employee code:"<<e_list[i].code<<"\tResume:"<<e_list
[i].resume<<endl;
cout<<"Age:"<<e_list[i].age<<endl;
cout<<"Salary:"<<e_list[i].salary<<endl;
cout<<"\n============================================"<<endl;
}
break;
case 'p':
cout<<"Your enteries are sorted by resume in following form"<<endl;
sort_resume( e_list, m );
for (int i=0 ; i<m ; i++)
{
cout<<"\n\n============Employee No."<<i+1<<"============\n\n";
cout<<"Name:"<<e_list[i].name<<"\nFamily Name:"<<e_list
[i].family<<endl;
cout<<"Employee code:"<<e_list[i].code<<"\tResume:"<<e_list
[i].resume<<endl;
cout<<"Age:"<<e_list[i].age<<endl;
cout<<"Salary:"<<e_list[i].salary<<endl;
cout<<"\n============================================"<<endl;
}
break;
default:
break;
}

cout<<"To quit the program press X"<<endl;

}
cout<<"\n\n==========================================\n\n";
cout<<"\t\tPresened by Baran Co.\n\n";
cout<<"\t\t\tCopy right 2009\n\n";
cout<<"\t\t\t\tPrepared by\n\n";
cout<<"\t\t\t\t\tMahmood Ahamdi\n\n\n";
cout<<"===================================\n\n";
return 0;
}
Reply all
Reply to author
Forward
0 new messages