ملتقى البرمجة
اهلا بك زائرنا الكريم ..
اذا كانت هذه هيالزيارة الاولى لك فاننا ندعوك الى التسجيل بالمنتدى او التعريف بنفسك
مع العلم ان الزوار لا يستطيعون مشاهدة كل المواضيع المطروحة بالمنتدى


انضم إلى المنتدى ، فالأمر سريع وسهل

ملتقى البرمجة
اهلا بك زائرنا الكريم ..
اذا كانت هذه هيالزيارة الاولى لك فاننا ندعوك الى التسجيل بالمنتدى او التعريف بنفسك
مع العلم ان الزوار لا يستطيعون مشاهدة كل المواضيع المطروحة بالمنتدى
ملتقى البرمجة
هل تريد التفاعل مع هذه المساهمة؟ كل ما عليك هو إنشاء حساب جديد ببضع خطوات أو تسجيل الدخول للمتابعة.

سؤال على ال parallel arrays

اذهب الى الأسفل

سؤال على ال parallel arrays Empty سؤال على ال parallel arrays

مُساهمة من طرف Basel Tamimi 1/5/2011, 5:06 am

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 Shocked Shocked

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 ^__^
Basel Tamimi
Basel Tamimi

عدد المساهمات : 44
تاريخ التسجيل : 09/03/2011
العمر : 32
الموقع : الخليل

https://is-it1.alafdal.net/

الرجوع الى أعلى الصفحة اذهب الى الأسفل

الرجوع الى أعلى الصفحة

- مواضيع مماثلة

 
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى