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

تصحيح كود لسلسلة نصية

بدأه نورة2010 في 11 مايو 2010 · 3 رد · 407 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

مساء الخير

هذا سؤال حليته لكن الرن مو مضبوط ارجو المساعده

جزاكم الله خيرا

هذا هو السؤال

Write a word processing program that reads a given text of any length no less than 100 characters, then displays a menu to choose and perform one of the following tasks:

2- Changing case: once this option is selected, a sub menu is displayed to allow user to choose the way of changing case of characters in the text:

 lower case: changes the case of all characters in the text to small letters

 UPPER CASE: changes the case of all characters in the text to capital letters

 Title Case: changes the case of first character in each word in the text to the capital letter and the remaining characters to small letters

 tOGGLE cASE: changes the case of first character in each word in the text to the small letter and the remaining characters to capital letters

وهذا هو الكود

/*

Write a word processing program that reads a given text of any length no less than 100 characters, then displays a menu to choose and perform one of the following tasks:

1- Changing case: once this option is selected, a sub menu is displayed to allow user to choose the way of changing case of characters in the text:

§ lower case: changes the case of all characters in the text to small letters

§ UPPER CASE: changes the case of all characters in the text to capital letters

§ Title Case: changes the case of first character in each word in the text to the capital letter and the remaining characters to small letters

§ tOGGLE cASE: changes the case of first character in each word in the text to the small letter and the remaining characters to capital letters

*/

#include <iostream>

#include <string>

using namespace std;

int main () {

char x [200];

bool Q=true , loop=true ;

int option ;

int counter=0;

int size=0;

cout<<"Enter u phearse .... any length no less than 100 characters : "<<endl;

cin>>x;

while (x)

{

size++;

}

while(Q){ // to must Enter 100 char ..........................

if ( !(size < 100) )

Q=true;

else

{cout<<"Enter u phearse .... any length no less than 100 characters : "<<endl;

cin>>x;}

}

cout<<"***********Plz choise from 1 to 5 ************"<<endl;

cout<<"1-lower case: changes the case of all characters in the text to small letters"<<endl;

cout<<"2-UPPER CASE: changes the case of all characters in the text to capital letters"<<endl;

cout<<"3-Title Case: changes the case of first character in each word in the text to the capital letter and the remaining characters to small letters"<<endl;

cout<<"4-tOGGLE cASE: changes the case of first character in each word in the text to the small letter and the remaining characters to capital letters"<<endl;

cout<<"5-Exit"<<endl;

cin>>option;

while(loop){

switch (option) {

case 1:

{

//lower case --------------------------

while (x[counter])

{

x[counter]=tolower(x[counter]);

counter++;

}

cout<<x<<endl;

counter=0;

//-------------------------------------

break ;

}

case 2:

{

// upper case -------------------------

while (x[counter])

{

x[counter]=toupper(x[counter]);

counter++;

}

cout<<x<<endl;

counter=0;

//-------------------------------------

break ;

}

case 3:

{

//Title Case---------------------------

while (x[counter])

{

if ( x[counter] == ' ' ){

x[counter+1]=toupper(x[counter+1]);

counter++;

}

else

x[counter]=tolower(x[counter]);

counter++;

}

cout<<x<<endl;

counter=0;

//-------------------------------------

break ;

}

case 4:

{

//tOGGLE cASE ---------------------------

while (x[counter])

{

if ( x[counter] == ' ' ){

x[counter+1]=tolower(x[counter+1]);

counter++;

}

else

x[counter]=toupper(x[counter]);

counter++;

}

cout<<x<<endl;

counter=0;

break ;

}

case 5:{

loop=false;

break;}

default :

cout << " plz Enter correct number .. try again .... " << endl;

}// end switch

}// end while ...................

return 0;

}

#2

هذا الكود بطريقه منظمه أكثر :

#include <iostream>
#include <cctype>
#include<string>
using namespace std;


void to_lower(char *str){
while(*str) *str=tolower(*str++);
}
void to_upper(char *str){
while(*str) *str=toupper(*str++); 	
}

void to_title(char* str){
to_lower(str);
*str=toupper(*str); 	

}

int main () {



 char str[100];

 int option ;

 cout<<"Enter u phearse .... any length no less than 100 characters : "<<endl;
 cin.getline(str,100);


do{
	cout<<"***********Plz choise from 1 to 5 ************"<<endl;
	cout<<"1-lower case: changes the case of all characters in the text to small letters"<<endl;
	cout<<"2-UPPER CASE: changes the case of all characters in the text to capital letters"<<endl;
	cout<<"3-Title Case: changes the case of first character in each word in the text to the capital letter and the remaining characters to small letters"<<endl;
	cout<<"4-tOGGLE cASE: changes the case of first character in each word in the text to the small letter and the remaining characters to capital letters"<<endl;
	cout<<"5-Exit"<<endl;
 	cin>>option;

	switch(option) {
	case 1:
 	to_lower(str);
 	break;
	case 2:
 	to_upper(str);
 	break;
	case 3:
 	to_title(str);
 	break;
	case 4:
 	break;
	case 5:
 	break;
 	default:
 	cout<<"Enter 1 to 5"<<endl;	


	}
	cout<<str<<endl;
 }while(option!=6);
 return 0;

}
tvquran_6.gif

#3

جزاك الله الف خير

لكن في السؤال طالب 4 (function)

جزاك ربي الفردوس الاعلى من الجنة

#4

نعم تركته متعمد كي تستفيد من الموجود وتكمل باقي الكود

tvquran_6.gif

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