المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : السي++



sondos
31-10-2005, 10:30 AM
السلام عليكم
ممكن اتوضحون لي السؤال لاني ما فهمته
كيف يمكن استخدم ال* كسطر جديد في البرمجة

وهذا نص السؤال لان عليه 30 درجة


In this question you are asked to design and write a C++ program whose purpose

is as follows. A string value is to be read in from the keyboard. The string will

comprise a name and address with the elements separated by asterisks, such as

John Smith*123 The Avenue*SomeTown*B91 1NP

The program has to write this string out in the following format.

John Smith

123 The Avenue

SomeTown

B911NP

The number of elements in the string entry (which will become the number of lines

in the written-out format) is not fixed. That is, the number of asterisks in the input

string is not known in advance.

You should base your design on first reading in the string to be formatted and then writing

out the revised string. Do not attempt to write out the characters as you read them in. Your

program should handle whatever input string is received from the user. For example, if the

user enters a string with no asterisks included, your program should write out this same

string. Every asterisk should produce a new line in the output.



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

رووبيي
31-10-2005, 06:07 PM
اللي فهمته من سؤال

ان الجمله لو كانت

hhhhh*jjjjjj*mmmmm*

تصير بعد البرنامج

hhhhh

jjjjjj

mmmmm



اتوقع ان الحل انك تسوي لوب على الجمله

بعدين لو لقيت الكاركتر = "*"

تسوي n\

في نفس الإندكس

يعني


for(i=0;i<size;i++)
if(p[i]=="*")
p[i]=\n



اتمنى يكون حلي صح

sondos
14-11-2005, 10:42 AM
شكرا لك
فهمت من الشرح
لاني كنت انمخربطة بين الجافا والسي++
لكن بفضل ردك عرفت
شكرا مرة ثانية كنت متوهقة وخايفة لا احد يرد علي

mozisse
18-11-2005, 01:31 AM
السلام عليكم
بتوقع الحل الأفضل أنك تستخدم الـ function strtok وهو موجود في الـ header file string.h
هذا الـ function بستقبل الجملة المدخلة من المستخدم وبستقبل الـ * على شكل string وبقوم بتقطيع هاي الجملة الى مقاطع كل ما يلاقي الـ * وبعدين انت بتخزن المقطع وبتطبعها كيف ما بدك
ارجو ان يكون هذا الحل الصحيح