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

عاجل الله يسعدكم

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

السلام عليكم ورحمة الله وبركاته جزاكم الله خير

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

write a program that reads in a sentence of up to 100 characters and outputs the sentence with spacing corrected and with letters corrected for capitalization. In other words, in the output sentence, all string of two or more blanks should be compressed to a single blank. The sentence should start with an uppercase letter but should contain no other uppercase letters. Don’t worry about proper names, if there first letter are changed to lowercase, that is acceptable. Treat a line break as if it was a blank, in the sense that line break and any number are blanks are compress to a single blank. Assume that the sentence ends with a period and contains no other period. For example the input

the Answer to life, the universe, and everything is 42.

Should produce

The answer to life, the universe, and everything is 42]

c++واستخدم c-stringوحل هذا لجواب في function هذولي

strcpy (Target_String, Source_String

strncpy (Target_String, Source_String, Limit

strcmp (String_1, String_2

strlen (Source_String

strcat (Target_String, Source_String

strncat (Target_String, Source_String, Limit

وفي معلومة زيادة نستخدم هذول ي بيسهل الحل

1. str.insert(pos, str2)

2. str.erase(pos, length)

وممكن اللي عنده كتاب problem solving c++ ممكن يساعده صفحة 507وdisplay8.7 v

بليز ردوا علي الله يوفق اللي بيجاوبي ويسعده دنيا واخره

تم تعديل هذه المشاركة بواسطة ام خالد3 في 11 مارس 2010 في 14:56

#2
#include <stdio.h>
#include <cstring>

int main()
{
	char szBuffer[128];
	char szResult[128];
	char* pc;
	int i;
	int capital;

	//scanf("%s", szBuffer);
	strcpy(szBuffer, "the Answer to life, the universe, and everything is 42.");

	pc = szBuffer;
	i = 0;
	capital = 1; // capitalize first letter

	while (*pc) {
		if (*pc == '\n') {
			szResult[i++] = ' ';
			pc++;
		}

		szResult[i++] = capital ? toupper(*pc) : tolower(*pc);
		if (isalpha(*pc))
			capital = 0;

		switch (*pc)
		{
		case ' ':
			// skip over blank spaces
			while (*pc == ' ')
				pc++;
			break;
		case '.':
			// capitalize next letter
			capital = 1;
			// step down
		default:
			pc++;
			break;
		}
	}


	szResult = '\0';
	printf("%s\n", szResult);
}

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