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

اريد شرح المطلوب من كتابة هذا البرنامج

بدأه Mr.jamss في 17 ديسمبر 2011 · 2 رد · 482 مشاهدة · في ارشيف قسم C/C++
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ..

مطلوب مني كتابة برنامج ..ولكن المشكلة ما استوعبت الافكار المطلوبة عشان اكتب .. الترجمة واضحة ..المطلوب ..وضع الأفكار المطلوبه ع شكل نقاط محدده و واضحة ..شرح بالضبط ايش خلاصة البرنامج ..

Consider the following exercises:


One month prior to elections in parliament-based governments many candidates for the parliament are making every possible effort to attract citizens’ vote. One such way is the so called “personalized letters.” Write, compile and run a program that can do the following:

1. Write to a string object the “message” of the candidate to the citizens. This message can be up to 600 characters long broken down to no more than 8 lines. The candidate for the parliament should be able to write the text himself putting XXXXX in the place where s/he believes the last and first names of the citizens should be placed (no more than 3 times in the whole text

2. Read the message from the string object and be able to make changes when the candidate feels is necessary.

3. Write to an array of objects citizens’ first and last names, gender and their age.

4. Ask the candidate what are the gender and the age of the citizens s/he wants to send the message to. Then the program reads the appropriate citizens’ object and puts their first and last names in an array of records, which is as large as the number of the citizens that should get the “message.”

5. Write to another string object a “new” message based on the “message” and replacing the XXXXX occurrences with the first and last names of the citizens that are to get the message.

6. Display the “new message” string object that includes the “personalized message” on screen.


اتمنى المساعدة ..قدر الامكان ..ودمتم ..
#2

هذه فكره + كود لرقم واحد ....

حاول أن تستعمل نفس الطريقه ...

#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

class Candidate
{
private: //constants
    static const size_t k_word_count = 60;
    static const size_t k_line_number = 8;
    static const char* k_name_ph;

private://data memebers;
    char message[k_word_count];

public:
    bool writeMessage();
    void printMessage();
};

const char* Candidate::k_name_ph = "XXXXX";

bool Candidate::writeMessage()
{
    int currlineNumber = 1;
    size_t  numReads = 0;
    size_t name_placeholder_count = 0;
    do
    {
        cin.getline(&message[numReads], k_word_count-numReads);

        strstr(&message[numReads], k_name_ph) && name_placeholder_count++;

        if (name_placeholder_count > 3)
        {
//            cout <<"Error: Usage of XXXXX placeholder excceded..." <<endl;
            message[0] = '\0';
            return false;
        }

        numReads += cin.gcount() - 1/* for the newline key */;

    }while (numReads < k_word_count && ++currlineNumber <= k_line_number);
    return true;
}

void Candidate::printMessage()
{
    cout << "\"" << message <<"\"" << endl;
}


int main(void)
{
    Candidate c;
    if (c.writeMessage())
    {
        c.printMessage();        
    }else
    {
        cout <<"Writting failed .. some problem occured!"<<endl;
    }


    system("pause");
    return 0;
}
1
#3

مشكور استاذي جزاك الله خير ..

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

static const char* k_name_ph;


 int currlineNumber = 1;
    size_t  numReads = 0;
    size_t name_placeholder_count = 0;

strstr

ممكن نستبدله بكود ثاني ابسط // numReads += cin.gcount() - 1

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

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

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

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

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