حل سؤال الموظفين والرواتب
4 مشترك
صفحة 1 من اصل 1
حل سؤال الموظفين والرواتب
- الكود:
#include <iostream>
#include <string>
using namespace std;
int main(){
int emp[5][3],i,j,sum=0,max,index;
float avg;
string s[5];
cout<<"enter names\n";
for (i = 0; i < 5; i++)
getline(cin,s[i]);
for(i=0;i<5;i++)
{cout<<"enter the sal and month for emp # "<<i+1<<endl;
for(j=0;j<2;j++)
{
cin>>emp[i][j];
}
}
for(i=0;i<5;i++)
{
emp[i][2]=emp[i][0]*emp[i][1];
}
max=emp[0][0];
for(i=0;i<5;i++)
{ if (emp[i][0]>max)
{
max=emp[i][0];
index=i;
}
sum=sum+emp[i][0];
}
avg=sum/5.0;
cout<<"\n the avg = "<<avg<<endl;
cout<<"max sal ="<<max<<endl;
cout<<"name of max sal "<<s[index];
for(i=0;i<5;i++)
{
for(j=0;j<3;j++)
{
cout<<emp[i][j]<<"\t";
}
cout<<endl;
}
system("pause");
return 0;
}
رد: حل سؤال الموظفين والرواتب
شكرا الك اخ انس
hana- عدد المساهمات : 2
تاريخ التسجيل : 09/03/2011
العمر : 35
رد: حل سؤال الموظفين والرواتب
او الحل على طريقتي
ملاحظة :- فقط ل 3 موظفين ليس 5
- الكود:
#include <iostream>
#include <string>
using namespace std;
int main(){
int emp[4][3],i,j,sum=0,max,index,x,w;
float avg;
string name[4];
cout<<"enter names\n";
//input name:-
for (i=0;i<3;i++)
cin>>name[i];
//input salary and count of month:-
for (i=0;i<3;i++)
{cout<<"\nenter salary and count month to \t"<<name[i]<<"\n";
cout<<"sulsry =\t";
cin>>emp[i][0];
cout<<"count month =\t";
cin>>emp[i][1];
}
for(i=0;i<3;i++)
emp[i][2]=(emp[i][0]*emp[i][1]);
cout<<"\n\n\n***************************************\n";
cout<<"\t^_^name\tsalary\tmonth\ttotal ^_^\n";
cout<<"***************************************\n";
for (i=0;i<3;i++){
cout<<"\t"<<name[i]<<"\t";
for(j=0;j<3;j++)
cout<<emp[i][j]<<"\t";
cout<<endl;
}
cout<<"***************************************\n";
//avareg salarys
for (i=0;i<3;i++)
sum=sum+emp[i][0];
avg=sum/3;
cout<<"\n\navareg salary = "<<avg;
// maximam sulary
max=emp[0][0];
for (i=0;i<3;i++)
if (emp[i][0]>max){
max=emp[i][0];
index=i;
}
cout<<"\n\nmaximam salary \t"<<name[index]<<"\t";
cout<<emp[index][0]<<"\t\n\n";
cout<<"swap\nenter swap betwen\t note: *enter index*\n";
cin>>x;
cout<<"and\n";
cin>>w;
name[3]=name[x];
name[x]=name[w];
name[w]=name[3];
for (i=0;i<3;i++)
emp[3][i]=emp[x][i];
for (i=0;i<3;i++)
emp[x][i]=emp[w][i];
for (i=0;i<3;i++)
emp[w][i]=emp[3][i];
cout<<"\n\n\n***************************************\n";
cout<<"\t^_^name\tsalary\tmonth\ttotal ^_^\n";
cout<<"***************************************\n";
for (i=0;i<3;i++){
cout<<"\t"<<name[i]<<"\t";
for(j=0;j<3;j++)
cout<<emp[i][j]<<"\t";
cout<<endl;
}
cout<<"***************************************\n";
system("pause");
return 0;
}
ملاحظة :- فقط ل 3 موظفين ليس 5
رد: حل سؤال الموظفين والرواتب
او الحل على طريقتي ^__^
الحل لخمسة موظفين
بالتوفيق
- الكود:
#include <iostream>
#include <string>
#define w 50
#define row 5
#define column 3
using namespace std;
int main(){
int i,j,info[row][column],maxsalary,s=0,tempsalary,tempmonth,temptotalsalary,x,y;
char name[row][w],tempname[1][w];
float avgsalary=0,avgmonths=0;
cout<<"enter 5 names of emploees: ";
for(i=0;i<row;i++)
{
cin>>name[i];
}
cout<<"enter the salary and num of worked month\n";
cout<<"name "<<"salary "<<"months"<<endl;
cout<<"---- "<<"------ "<<"------"<<endl;
for (i=0;i<row;i++){
cout<<name[i]<<"\t";
for(j=0;j<column-1;j++){
cin>> info[i][j];}
info[i][column-1]=info[i][0]*info[i][1];
}
cout<<endl;
cout<<"All information you enter as the following:\n"
<<"*******************************************\n";
cout<<"name "<<"salary "<<"months "<<"total salary"<<endl;
cout<<"---- "<<"------ "<<"------ "<<"------------"<<endl;
for(i=0;i<row;i++){
cout<<name[i]<<" ";
for(j=0;j<column;j++){
cout<<info[i][j]<<" ";}
cout<<endl;}
for(i=0;i<row;i++){
avgsalary=avgsalary+info[i][0];
avgmonths=avgmonths+info[i][1];}
cout<<endl;
cout<<"other details:\n"
<<"-------------\n"
<<"the avrrage salary of all emploees= "<<float(avgsalary/row)<<endl
<<"the avrrage number of months worked by emploees= "<<float(avgmonths/row)<<endl;
maxsalary=info[0][0];
for(i=1;i<row;i++){
if(maxsalary<info[i][0]){
maxsalary=info[i][0];
s=i;}
}
cout<<"the name of the employee who has the maximum salary is; "<<name[s]<<endl;
cout<<endl<<endl;
cout<<"choose two emploees index to swap them: ";
cin>>x>>y;
strcpy(tempname[x],name[x]);
strcpy(name[x],name[y]);
strcpy(name[y],tempname[x]);
tempsalary=info[x][0];
info[x][0]=info[y][0];
info[y][0]=tempsalary;
tempmonth=info[x][1];
info[x][1]=info[y][1];
info[y][1]=tempmonth;
temptotalsalary=info[x][2];
info[x][2]=info[y][2];
info[y][2]=temptotalsalary;
cout<<"the informations after swaping are:\n"
<<"-----------------------------------\n";
cout<<"name "<<"salary "<<"months "<<"total salary"<<endl;
cout<<"---- "<<"------ "<<"------ "<<"------------"<<endl;
for(i=0;i<row;i++){
cout<<name[i]<<" ";
for(j=0;j<column;j++){
cout<<info[i][j]<<" ";}
cout<<endl;}
cout<<endl;
system ("pause");
}
الحل لخمسة موظفين
بالتوفيق
رد: حل سؤال الموظفين والرواتب
شكرا لكم لهذه الموضوع
باعامر- عدد المساهمات : 1
تاريخ التسجيل : 21/05/2011
رد: حل سؤال الموظفين والرواتب
العفو اخي الكريمباعامر كتب:شكرا لكم لهذه الموضوع
وكل التحية لاهل اليمن وطلاب الحديدة
بس شو بالنسبة لعلي مطول عندكم ولا لا
مواضيع مماثلة
» سؤال على ال parallel arrays
» حل سؤال حروف العلة
» سؤال طباعة الاسم الاول والحرف الاول من الاسم الثاني والثالث
» حل سؤال حروف العلة
» سؤال طباعة الاسم الاول والحرف الاول من الاسم الثاني والثالث
صفحة 1 من اصل 1
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى
3/7/2011, 11:05 pm من طرف anas mohtaseb
» امتحان الفاينال لمختبر برمجة الحاسوب
26/5/2011, 1:45 pm من طرف Basel Tamimi
» حل سؤال الموظفين والرواتب
22/5/2011, 3:17 pm من طرف Basel Tamimi
» sum program with parameters
22/5/2011, 9:33 am من طرف Basel Tamimi
» مختبر 9
18/5/2011, 5:43 pm من طرف Basel Tamimi
» سلايدات الكتاب للاقسام 4 5 7
6/5/2011, 2:07 pm من طرف Basel Tamimi
» شكرا لكم
4/5/2011, 8:51 pm من طرف anas mohtaseb
» Programming Assignment الحل الثاني
2/5/2011, 7:58 am من طرف Basel Tamimi
» سؤال على ال parallel arrays
1/5/2011, 5:06 am من طرف Basel Tamimi