05-03-2013، 05:46 PM
کلاسی به نام کارمند تعریف کنید که کد پرسنلی،حقوق پایه،میزان هر ساعت اضافه کاری و هزینه هر ساعت اضافه کاری رادریافت کند،سپس حقوق کارمند را محاسبه و چاپ کند؟
جواب با استفاده از input :
جواب با استفاده از تابع سازنده :
کد:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace karmand
{
class Program
{
class karmand
{
private long id, bas, h, cost;
public void input()
{
id = Convert.ToInt32(Console.ReadLine());
bas = Convert.ToInt32(Console.ReadLine());
h = Convert.ToInt32(Console.ReadLine());
cost = Convert.ToInt32(Console.ReadLine());
}
public void salary()
{
long s = bas + h * cost;
Console.WriteLine(s.ToString());
}
}
static void Main(string[] args)
{
karmand c;
c = new karmand();
c.input();
c.salary();
Console.ReadKey();
}
}
}
جواب با استفاده از تابع سازنده :
کد:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace karmand_2
{
class Program
{
class karmand
{
private long id, bas, h, cost;
public karmand(long id1, long bas1, long h1, long cost1)
{
id = id1;
bas = bas1;
h = h1;
cost = cost1;
}
public void salary()
{
long s = bas + h * cost;
Console.WriteLine(s.ToString());
}
}
static void Main(string[] args)
{
karmand c;
c = new karmand(1,9,8,7);
c.salary();
Console.ReadKey();
}
}
}
*شما قادر به دیدن لینک ها نیستید ثبت نام کنید یا وارد حساب خود شوید تا بتوانید لینک ها را ببینید*
خورشید باش که اگر خواستی بر کسی نتابی نتوانی.