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

مشروع نهاية الفصل

بدأه Zaianb في 18 يناير 2010 · 3 رد · 549 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

THE CLASS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EmployeeLibrary
{
    class Employee
    {
        private string Name = "";
        private int num_of_worked_months = 0;
        private double avg = 0;
        public static int[] hours_per_month;

        public string getName()
        {
            return Name;
        }
        public void setName(string value)
        {
            Name = value;
        }
        public int getNumber_Of_Worked_Months()
        {
            return num_of_worked_months;
        }
        public void setNumber_Of_Worked_Months(int value)
        {
            num_of_worked_months = value;
        }
        public double getAvg()
        {
            return avg;
        }
        public void setAvg(int value)
        {
            avg = value;
        }
        public int get_HPM(int month)
        {
            return hours_per_month[month];
        }
        public void set_HPM(int month, int value)
        {
            hours_per_month[month] = value;
        }
    }
}

THE PROGRAM

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FinalProject
{
    class Program
    {
        public static void print_report(Employee[] emps, int num)
        {
            Console.WriteLine("The name \t the Avg");
            for (int i = 0; i <= num; i++)
            {
                Console.WriteLine("the average is: emps.getName + emps.getAvg");
            }
        }
        static void Main(string[] args)
        {
            int num_of_emps = 0;
            string c = "";
            int Number_Of_Worked_Months = 0;
            Employee[] emps = new Employee[25];
            if (num_of_emps > 0 && num_of_emps <= 24)
            {
                for (int i = 0; i <= num_of_emps; i++)
                {
                    Console.Write("Welcome to our program");
                    for (int n = 0; n < emps.Length; n++)
                        emps[n] = new Employee();
                    Console.Write("Please enter employee name: ");
                    emps[n].setName(Console.ReadLine());
                    Console.Write("Please enter the number of months you have worked this year: ");
                    emps[n].setNumber_Of_Worked_Months(Int32.Parse(Console.ReadLine()));
                    Number_Of_Worked_Months = Int32.Parse(Console.ReadLine());
                    try
                    {
                        while (!num_of_worked_months > 12)
                        {
                            Console.WriteLine("Error inserting");
                            emps[n].setnumber_of_worked_months = Int32.Parse(Console.ReadLine());
                        }
                        for (int j = 0; j <= num_of_worked_months.Length - 1; j++)
                        {
                            Console.WriteLine("Enter the number of worked hores for the month num" + "  " + (j + 1));
                            EmployeeLibrary.Employee.set_HPM = Int32.Parse(Console.ReadLine());
                        }
                    }

                    catch (Exception ex1)
                    {
                        Console.WriteLine(ex1.Message);
                    }
                    finally 
                    {
                        Console.WriteLine("we are done");
                    }
                    int sort = 0;
                    for ( int b = 0; b <emps.Length; b++)
                        for (int t = 0; t < emps.Length; t++)
                        {
                            if (emps > emps[t])
                            {
                                sort = emps;
                                emps = emps[t];
                                emps[t] = sort;
                            }
                        }
                        for (int j = 0; j <= emps.num_of_worked_monthes - 1; j++)
                        {
                            temp += EmployeeLibrary.Employee.get_HPM(i);
                        }
                        emps.getAvg = (temp / emps.num_of_worked_monthes);
                        while (true)
                        {
                            Console.WriteLine("Is there any other employees, Press 'Y' for yes and 'N' if no: ");
                            c = Console.ReadLine();
                            switch (c)
                            {
                                case "y":
                                case "Y":
                                    Console.WriteLine("Enter the number of the Employees");
                                    num_of_emps = Int32.Parse(Console.ReadLine());
                                    break;
                                case "n":
                                case "N":
                                    print_report(emps, num_of_emps);
                                    break;
                            }
                            print_report(emps, num_of_emps);
                            break;
                        }
                        if (c == "N" || c == "n")
                        {
                            break;
                        }



                    }
                }
            }

    }   
}

لقد قمنا بإدخال بعض التعديلات على مشروع نهاية هذا الفصل الدراسي و هو عبارة عن عمل برنامج يوضح اسم الموظف و ساعات العمل و الشهور و ايجاد معدل ساعات العمل في كل شهر ل 25 موظف.

المشكله:

ان البرنامج لا يعمل لانه يظهر لنا بأن Employee الموجودة في ال Prpgram في البداية عند جملة الريبورت تظهر لنا أنها غير موجودة في البرنامج ولا نعلم كيف نجعل البرنامج يتعرف عليها ... و ايضا هناك هذا الاراي Employee[] emps = new Employee[25]; لا يظهر لنا باللون الاخضر ليدل على انه يستخدم الكلاس .. و واجهنا مشكلة اخرى في السلكشن سورتينج البرنامج يقول بأن emps > emps[t لايمكن تطبيقها في البرنامج ..

شاكرين لكم مساعداتكم ..

#2
Zaianb كتب:

ان البرنامج لا يعمل لانه يظهر لنا بأن Employee الموجودة في ال Prpgram في البداية عند جملة الريبورت تظهر لنا أنها غير موجودة في البرنامج ولا نعلم كيف نجعل البرنامج يتعرف عليها

السبب هو أن الكلاس Employee موجود في namespace مختلف عن الذي يوجد فيه البرنامج. للوصول إليه يجب أن تضعي الـnamespace قبل اسم الكلاس. بهذا الشكل:

EmployeeLibrary.Employee

Zaianb كتب:

و واجهنا مشكلة اخرى في السلكشن سورتينج البرنامج يقول بأن emps > emps[t لايمكن تطبيقها في البرنامج ..

هذا لأنه لا يمكن تطبيق عمليات المقارنة على الكلاسات. و لكن يتم على الـproperties و غيرها من القيم الخاصة بالكلاس. يمكن مثلاً المقارنة حسب المعدل:

emps[1].getAvg > emps[2].getAvg
#3

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

ماهي الجملة التي نكتبها لكي تحسب المعدل ؟

#4

لا توجد جملة تقوم بهذا. عليك عمل دالة يدوياً تقوم بالمرور على الأرقام و جمعها ثم قسمتها على عددها.

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