طلبات البرنامج هي كالتالي :
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;
}
وهلء يا اخوان بدي مساعدتكن بكتابة البرنامج نفسه بس فقط باضافة التوابع له
واكون من الشاكرين لكم .
مجدي
