سؤال على ال parallel arrays
صفحة 1 من اصل 1
سؤال على ال parallel arrays
Write a C++ program that reads the first names of up to 10 salesmen (saleswomen), their respective genders (m=male or f=female ), as well as their total sales for the last three months. You should stop reading when the name "Enough" is entered. Your program should then find the average sales for each of the salesmen (saleswomen) and print the following to the screen:
- The names of the salesmen (saleswomen) and the average sales for each sorted in descending order based on the sales avg.
- The total average sales for males and the total average sales for females.
NOTE: You should use only arrays to do this question. Using STRUCTURES or FUNCTIONS is NOT allowed
Sol'n:
- الكود:
#include <iostream>
#include <string>
#define row 10
#define column 4
using namespace std;
int main(){
string name[ row ],temp;
char gender[row],genderTemp;
float salary[row][column],sum,sumM=0,sumF=0,temp2;
int size,Mcounter=0,Fcounter=0;
cout<<"enter the following details for 10 workers:\n"
<<"TO STOP ENTER ((Enough))\n\n"
<<"name M/F salary1 salary2 salary3\n"
<<"---- --- ------- ------- -------\n";
for(int i=0 ; i<row ; i++){
cin>>temp;
if(temp!="Enough"){
name[i]=temp;
cin>>gender[i];
gender[i]=toupper(gender[i]);
sum=0;
for(int j=0;j<(column-1);j++){
cin>>salary[i][j];
sum=sum+salary[i][j];
}
salary[i][column-1]=(float)sum/3;
}
else {size=i;
break;}
}
cout<<"\n\n The summarize of entered details as:\n"
<<"name M/F salary1 salary2 salary3 Avg salaries\n"
<<"---- --- ------- ------- ------- -------------\n";
for(int i=0;i<size;i++){
cout<<name[i]<<"\t";
cout<<gender[i]<<"\t";
for(int j=0;j<column;j++){
cout<<salary[i][j]<<"\t";}
cout<<endl;
}
cout<<"----------------------------------------------------\n";
//ordering
for(int i=0;i<size;i++)
for(int j=0;j<size;j++){
if(salary[i][column-1] > salary[j][column-1]){
temp2=salary[i][column-1];
salary[i][column-1]=salary[j][column-1];
salary[j][column-1]=temp2;
temp=name[i];
name[i]=name[j];
name[j]=temp;
genderTemp=gender[i];
gender[i]=gender[j];
gender[j]=genderTemp;
}
}
cout<<"\n\n\n";
cout<<"the descending order of the workers:\n"
<<"Name\t avg\n"
<<"----\t ---\n";
for(int i=0;i<size;i++){
cout<<name[i]<<"\t"<<salary[i][column-1];
cout<<endl;
}
//total average
for(int i=0;i<size; i++)
if(gender[i]=='M'){
sumM=sumM+salary[i][column-1];
Mcounter++;
}
else if(gender[i]=='F')
{sumF=sumF+salary[i][column-1];
Fcounter++;}
cout<<"\nThe total average sales for males= "<<sumM/Mcounter<<"\n";
cout<<"The total average sales for females= "<<sumF/Fcounter<<"\n";
cout<<endl;
system("pause");
return 0;
}
And That's It ^__^
مواضيع مماثلة
» حل سؤال حروف العلة
» حل سؤال الموظفين والرواتب
» سؤال طباعة الاسم الاول والحرف الاول من الاسم الثاني والثالث
» حل سؤال الموظفين والرواتب
» سؤال طباعة الاسم الاول والحرف الاول من الاسم الثاني والثالث
صفحة 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