الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مساعدة كتابة البرنامج التالي باستخدام التوابع

بدأه yawaloa في 9 مايو 2010 · 5 رد · 509 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

طلبات البرنامج هي كالتالي :

Write a program that takes as input a set of characters. The program

should do the following:

1. Calculate the number of lowercase alphabetical characters (‘a’, ‘c’,

’k’…etc).

2. Calculate the number of uppercase alphabetical characters (‘A’,

‘M’ …etc).

3. Calculate the number of numerical characters (‘1’, ‘2’,’3’ …etc).

4. Calculate the sum and average of numerical characters, after

transforming each one into an integer.

5. After Calculating the sum of the numerical characters, uses this

sum s to calculate the formula:

? ?/?

?

???

6. Keeps displaying the following menu to the user until he\she

chooses to exit the program:

1) Display the number of lowercase alphabetical characters

2) Display the number of uppercase alphabetical characters

3) Display the sum and average of numerical characters

4) Display formula.

5) Exit program

والبرنامج حله هو كالتالي :

#include<iostream>

using namespace std;

int main()

{

float formula=1,avg;

int uppercase=0,lowercase=0,digits=0,digitsSum=0;

char input;

int i;

int m = 0;

cout<<"Please enter your characters, press . to end" <<endl;

while (input!='.')

{

cin>>input;

if(input>='0' && input<='9')

{

i = input - 48;

digitsSum +=i;

digits++;

}

else if (input>='a' && input<='z')

{

lowercase++;

}

else if (input>='A' && input<='Z')

{

uppercase++;

}

}

for (int k=1;k<digitsSum;k++)

{

formula+= (float)k/digitsSum;

}

while(m!=5)

{

cout << "Press"<<endl;

cout << "1) Display the number of lowercase alphabetical characters"<<endl;

cout << "2) Display the number of uppercase alphabetical characters"<<endl;

cout << "3) Display the sum and average of numerical characters"<<endl;

cout << "4) Display formula"<<endl;

cout << "5) Exit program"<<endl;

cin>>m;

switch(m)

{

case 1:

cout <<"the number of lowercase characters is: " << lowercase <<endl;

break;

case 2:

cout <<"the number of uppercase characters is: " << uppercase <<endl;

break;

case 3:

if(digits == 0)

{

cout <<"Sorry! no numeric characters were entered!"<<endl;

}

else

{

avg = (float)digitsSum/digits;

cout <<"the sum of numberic characters is: " << digitsSum <<endl;

cout <<"the average of numberic characters is: " << avg <<endl;

}

break;

case 4:

if(digits == 0)

{

cout <<"Sorry! no numeric characters were entered!"<<endl;

}

else

{

cout <<"the formula is: " << formula <<endl;

}

break;

case 5:

cout << "Program will exit..."<<endl;

break;

default:

cout <<"Wrong input!"<<endl;

}

}

system("pause");

return 0;

}

وهلء يا اخوان بدي مساعدتكن بكتابة البرنامج نفسه بس فقط باضافة التوابع له

واكون من الشاكرين لكم .

مجدي

#2

تفضل التعديل على البرنامج

لم اقم بإضافة الفورمولا Formula الاختيار الخامس .. لانها غير واضحه في السؤال .

#include<iostream>

#include<ctype.h>



using namespace std;



int main()

{

float formula=1,avg;

int uppercase=0,lowercase=0,digits=0,digitsSum=0;

char input[255];

int i,m;

cout<<"Please enter your string set:" <<endl;

//get the line of charector.

cin.getline(input,255);



//do the operation for the input string.

for(i=0;input!='\0';i++)

{

   //if is alpha

  	if(isalpha(input))

   {

  		if(islower(input))

       	lowercase++;

        	else

      	uppercase++;

   }

  	//if is it digit

  	else if(isdigit(input))

  	{

       	digits++;

       	digitsSum+=(int) input;

  	}



}



//calulate avrage.



avg=(float) digitsSum/digits;



do

{ 



  	 cout << "1) Display the number of lowercase alphabetical characters"<<endl;

  	 cout << "2) Display the number of uppercase alphabetical characters"<<endl;

  	 cout << "3) Display the sum and average of numerical characters"<<endl; 

  	 cout << "4) Display formula"<<endl; 

  	 cout << "5) Exit program"<<endl;



  	 cin>>m;



  	 switch(m)

  	 {

        	 case 1:

              	 cout<<"There are "<<lowercase<<" lower case character(s) in the string"<<endl;

              	 cin.get();

              	 break;

        	 case 2:

              	 cout<<"There are "<<uppercase<<" Upper case character(s) in the string"<<endl;

              	 cin.get();

              	 break;

        	 case 3:

              	 cout<<" SUM of digits="<< digitsSum <<" and Avrage is:"<<avg<<endl;

              	 cin.get();

              	 break;

        	 default:

              	 if(m!=5)

                    	 cout<<" Wrong intery.! Try Again"<<endl;

                    	 cin.get();

  	 }//end of case select 



}while(m!=5);



system("pause");

return 0;

}

تحياتي

تم تعديل هذه المشاركة بواسطة omani في 9 مايو 2010 في 15:16

2

OMANI FOR EVER

-------------------------------------------------

post-12787-12780191801974.jpg

-------------------------------------------------

#3

جازاك الله اخي عماني

الله يخليك تسلم دياتك وإن شاء الله ماننحرم من خدماتك

يعطيك ألف الف عافية يارب :clapping:

:ty:

#4

اخ عماني

الطلب الخامس هاد هوي بالملف المرفق

ياريت اذا بتشرحلي كيف حليتو

لان انا بصراحه بدرس الماده لحالي من كتاب

post-175935-12734198994462_thumb.jpg

#5

المعادلة لا ادري ان كنت علمتها صح ام لا .

هي تعتبر كما واضح الشرح بالكود .

#include<iostream>

#include<ctype.h>

#include<cstring>



using namespace std;

int main()

{

	float formula=1,avg;

	int uppercase=0,lowercase=0,digits=0,digitsSum=0,i,m;

	char input[255];

cout<<"Please enter your string set:" <<endl;

//get the line of charector.

cin.getline(input,255);

//do the operation for the input string.

for(i=0;input!='\0';i++)

{

   //if is alpha

    	if(isalpha(input))

   {

            	if(islower(input))

                           lowercase++;

            	else

          	    		uppercase++;

   }

    	//if is it digit

    	else if(isdigit(input))

    	{

      	digits++;

      	digitsSum+=(int)(input-'0');//to get the Number Not ascii

    	}

}// end of For loop



//calulate avrage.

avg=(float) digitsSum/digits;



/* Calculate formula

formula =(1/sum) * (2/sum) * (3/sum) * ... *(sum/sum)

*/ 

for(i=1;i<=digitsSum;i++)

    	formula *=(i/digitsSum);





do

{ 

 		cout << "1) Display the number of lowercase alphabetical characters"<<endl;

     	cout << "2) Display the number of uppercase alphabetical characters"<<endl;

 		cout << "3) Display the sum and average of numerical characters"<<endl; 

 		cout << "4) Display formula"<<endl; 

 		cout << "5) Exit program"<<endl;

	cin>>m;

 		switch(m)

 		{

         		case 1:

             		cout<<"There are "<<lowercase<<" lower case character(s) in the string"<<endl;

                          	cin.get();

         		break;

         		case 2:

                   	cout<<"There are "<<uppercase<<" Upper case character(s) in the string"<<endl;

                          	cin.get();

         		break;

         		case 3:

                   	cout<<" SUM of digits="<< digitsSum <<" and Avrage is:"<<avg<<endl;

                   	cin.get();

             	break;

                         case 4:

                               cout<<" Formula="<< formula <<endl;

                     	cin.get();

                         break;

                         default:

                   	if(m!=5)//if not to close

                                 {

                 		cout<<" Wrong intery.! Try Again"<<endl;

                                   cin.get();

                                	}



 		}//end of switch.

}while(m!=5);



system("pause");

return 0;

}

تحياتي

تم تعديل هذه المشاركة بواسطة omani في 10 مايو 2010 في 21:06

1

OMANI FOR EVER

-------------------------------------------------

post-12787-12780191801974.jpg

-------------------------------------------------

#6

الف شكر الك اخ عماني

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…