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

أخواني الكرام ....... ارجوا المساعدة في كتابة كودات هذا البرنامج لتقويم

بدأه sami.armosh في 5 أبريل 2010 · 5 رد · 868 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

اخوتي الكرام ، ارجو منكم المساعدة في كتابة الكودات #C لهذا البرنامج وهو عبارة عن اظهار التقويم ( روزنامة ) لشهر معين وفق الشكل الاتي :

3 - 2010

-----------------------------

Sun Mon Tue Wed Thu Fri Sat

1 2 3 4 5 6

7 8 9 10 11 12 13

14 15 16 17 18 19 20

21 22 23 24 25 26 27

28 29 30 31

بالنسبة لدخل البرنامج :

- عدد يمثل العام نستخدم اسم المتحول year ( فقط الاعوام 2009،2010،2011 )

-عدد يمثل سنستخدم اسم المتحول month

خوارزمية تحديد يوم الاسبوع الموافقة لكل تاريخ (Sun Mon Tue Wed Thu Fri Sat )

[u]الفرضيات :

- نعتبر ايام الاسبوع مرقمة من 0 حتى 6 (Sun=0، Mon=1، Tue=2، Wed=3، Thu=4، Fri=5، Sat=6 )

- نعرف من التقويم ان اول يوم من العام 2009 سنسميه( d1y09 ) هو يوم الخميس : أي ان 4=d1y09

- يجب ان نعرف عدد ايام الشهر سنستخدم اسم المتحول nbdm

مثال : 31=nbdm اذا كان الشهر 3=month

[u]الخطوات :

- احسب اليوم الاول من الشهر month من العام year ( سنسميه d1m ) وفق مايلي :

- احسب عدد الايام منذ بداية العام 2009 حتى الشهر month من العام year ( سنسميه ndTo09 )

- احسب باقي قسمة العدد السابق ndTo09 على 7 و لتكن dd

d1m = (dd+d1y09)%7

اظهار الروزنامة :

اظهار ترويسة الروزنامة :

2010 3

----------------------------------------------

Sun Mon Tue Wed Thu Fri Sat

اظهار فراغات تتناسب مع d1m

اظهار 1,2,3 من ايام الشهر حتى يمتلئ السطر الاول عند القيمة d مثلا

n=0

............من أجل k=d حتى nbdm كرر

............اكتب k

.............اكتب فراغات ( للمحاذاة )

............اذا ( n من مضاعفات 7 ) نفذ

............ انتقل إلى السطر الجديد

ملا حظات عامة :

- يجب بناء البرنامج باستخدام الخطوات واسماء الالمتحولات المعرفة بالنص

- لا يستخدم في بناء البرنامج لا الجدوال array ولا البرامج الجزئية subprogram

أرجو المساعدة بأسرع وقت ممكن مع الشكر المسبق لكم.

السلام عليكم

#2

أخى هذا برنامج كنت عامله من زمااااااااااااااان ولكن محتاج بعض التنسيق فى ظهور الأيام لعله يفيدك

using System;
namespace MyNamespace
{
    class MainClass
    {
        // Main method
        public static void Main(String[] args)
        {
            PrintCalender factor = new PrintCalender();
            // the user enters year and month
            Console.WriteLine("Enter full year");
            int year = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter month in number between 1 and 12");
            int month = int.Parse(Console.ReadLine());

            // Get start day of the week for the first date in the month
            int startDay = factor.getStartDay(year, month);

            // Get number of day  in the month
            int numOfDaysInMonth = factor.getNumOfDaysInMonth(year, month);

            // Print headings
            factor.printMonthTitle(year, month);

            // Print body
            factor.printMonthBody(startDay, numOfDaysInMonth);
        }

    }
    public class PrintCalender
    {


        // Get the start day of the first day in a month
        public int getStartDay(int year, int month)
        {
            // Get total number of days since 1/1/1800
            int startDay1800 = 3;
            long totalNumOfDays = getTotalNumOfDays(year, month);

            // Return the start day 
            return (int)((totalNumOfDays + startDay1800) % 7);
        }

        // Get total number of days since Jan 1, 1800
        public long getTotalNumOfDays(int year, int month)
        {
            long total = 0;

            // Get the total days from 1800 to year -1
            for (int i = 1800; i < year; i++)
                if (leapYear(i))
                    total = total + 366;
                else
                    total = total + 365;

            // Add days from jan to the month prior to the calender month
            for (int i = 1; i < month; i++)
                total = total + getNumOfDaysInMonth(year, i);

            return total;
        }

        // Get the number of days in a month
        public int getNumOfDaysInMonth(int year, int month)
        {
            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
                return 31;
            if (month == 4 || month == 6 || month == 9 || month == 11)
                return 30;
            if (month == 2)
                if (leapYear(year))
                    return 29;
                else
                    return 28;
            return 0; // If month is incorrect
        }

        // Determine if it is a leap year 
        public bool leapYear(int year)
        {
            if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
                return true;
            return false;
        }

        // Print month body
        public void printMonthBody(int startDay, int numofDaysInMonth)
        {
            // pad space before the first day of the month
            int i = 0;
            for (i = 0; i < startDay; i++)
                Console.WriteLine(" ");

            for (i = 1; i <= numofDaysInMonth; i++)
            {
                if (i < 10)
                    Console.Write("   " + i);
                else
                    Console.Write(" " + i);
                if ((i + startDay) % 7 == 0)
                    Console.WriteLine();
            }

            Console.WriteLine("");
        }
        // Print the month title, i.e. May, 1999
        public void printMonthTitle(int year, int month)
        {
            Console.WriteLine("        " + getMonthName(month) + ", " + year);
            Console.WriteLine("-----------------------------");
            Console.WriteLine(" Sun Mon Tue Wed Thu Fri Sat");
        }

        // Get the Enghlish name for the month 
        public String getMonthName(int month)
        {
            String monthName = null;
            switch (month)
            {
                case 1: monthName = "January"; break;
                case 2: monthName = "february"; break;
                case 3: monthName = "March"; break;
                case 4: monthName = "April"; break;
                case 5: monthName = "May"; break;
                case 6: monthName = "June"; break;
                case 7: monthName = "July"; break;
                case 8: monthName = "August"; break;
                case 9: monthName = "September"; break;
                case 10: monthName = "October"; break;
                case 11: monthName = "November"; break;
                case 12: monthName = "December"; break;
            }

            return monthName;
        }
    }

}

 وممّا زادنـــي شرفــاً وتيهــاً   **  وكدت بأخمصي أطأ الثريّا

دخولي تحت قولك يا عبادي  **   وأن صيّرت أحمد لي نبيّـاً

#3

الشكر الجزيل على ردك السريع و مساعدتك ... لو تقدر تساعدني اكثر بموضوع الايام .....

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

#4

أخى هذا تعديل للكود

using System;
namespace MyNamespace
{
    class MainClass
    {
        // Main method
        public static void Main(String[] args)
        {
            PrintCalender factor = new PrintCalender();
            // the user enters year and month
            Console.WriteLine("Enter full year");
            int year = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter month in number between 1 and 12");
            int month = int.Parse(Console.ReadLine());

            // Get start day of the week for the first date in the month
            int startDay = factor.getStartDay(year, month);

            // Get number of day  in the month
            int numOfDaysInMonth = factor.getNumOfDaysInMonth(year, month);

            // Print headings
            factor.printMonthTitle(year, month);

            // Print body
            factor.printMonthBody(startDay, numOfDaysInMonth);
        }

    }
    public class PrintCalender
    {


        // Get the start day of the first day in a month
        public int getStartDay(int year, int month)
        {
            // Get total number of days since 1/1/1800
            int startDay1800 = 3;
            long totalNumOfDays = getTotalNumOfDays(year, month);

            // Return the start day 
            return (int)((totalNumOfDays + startDay1800) % 7);
        }

        // Get total number of days since Jan 1, 1800
        public long getTotalNumOfDays(int year, int month)
        {
            long total = 0;

            // Get the total days from 1800 to year -1
            for (int i = 1800; i < year; i++)
                if (leapYear(i))
                    total = total + 366;
                else
                    total = total + 365;

            // Add days from jan to the month prior to the calender month
            for (int i = 1; i < month; i++)
                total = total + getNumOfDaysInMonth(year, i);

            return total;
        }

        // Get the number of days in a month
        public int getNumOfDaysInMonth(int year, int month)
        {
            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
                return 31;
            if (month == 4 || month == 6 || month == 9 || month == 11)
                return 30;
            if (month == 2)
                if (leapYear(year))
                    return 29;
                else
                    return 28;
            return 0; // If month is incorrect
        }

        // Determine if it is a leap year 
        public bool leapYear(int year)
        {
            if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
                return true;
            return false;
        }

        // Print month body
        public void printMonthBody(int startDay, int numofDaysInMonth)
        {
            // pad space before the first day of the month
            int i = 0;
            for (i = 0; i < startDay; i++)
                Console.Write("    ");

            for (i = 1; i <= numofDaysInMonth; i++)
            {
                if (i < 10)
                    Console.Write("   " + i);
                else
                    Console.Write("  " + i);
                if ((i + startDay) % 7 == 0)
                    Console.WriteLine();
            }

            Console.WriteLine();
        }
        // Print the month title, i.e. May, 1999
        public void printMonthTitle(int year, int month)
        {
            Console.WriteLine("        " + getMonthName(month) + ", " + year);
            Console.WriteLine("-----------------------------");
            Console.WriteLine("  Sun Mon Tue Wed Thu Fri Sat");
        }

        // Get the Enghlish name for the month 
        public String getMonthName(int month)
        {
            String monthName = null;
            switch (month)
            {
                case 1: monthName = "January"; break;
                case 2: monthName = "february"; break;
                case 3: monthName = "March"; break;
                case 4: monthName = "April"; break;
                case 5: monthName = "May"; break;
                case 6: monthName = "June"; break;
                case 7: monthName = "July"; break;
                case 8: monthName = "August"; break;
                case 9: monthName = "September"; break;
                case 10: monthName = "October"; break;
                case 11: monthName = "November"; break;
                case 12: monthName = "December"; break;
            }

            return monthName;
        }
    }

}

post-207223-12704619357879_thumb.jpg

 وممّا زادنـــي شرفــاً وتيهــاً   **  وكدت بأخمصي أطأ الثريّا

دخولي تحت قولك يا عبادي  **   وأن صيّرت أحمد لي نبيّـاً

#5

شكرا يا أخي

ممكن استفهم منك اذا في وقت عن موضوع الملاحظات وهي :

- لا يستخدم في بناء البرنامج لا الجدوال array ولا البرامج الجزئية

ماهو المقصود بالجداول Array و البرامج الجزئية subprogram

وهل يوجد بالبرنامج الذي زوديتني به جداول وا برامج جزئية ??

#6

يقصد بال arrays المصفوفات وأنا لم أستخدم المصفوفات فى البرنامج

فالبرنامج عباره عن مجموعه من الأجراءات فقط تنفذ تلو الأخرى وفى المرفقات

كتيب عن المصفوفات فى ال C#

أما بخصوص ال subprogram فأنا لم أسمع عنها فى ال C# ربما تكون فى C++

arrays.pdf

 وممّا زادنـــي شرفــاً وتيهــاً   **  وكدت بأخمصي أطأ الثريّا

دخولي تحت قولك يا عبادي  **   وأن صيّرت أحمد لي نبيّـاً

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

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

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

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

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