De.coder
473 subscribers
457 photos
44 videos
191 files
300 links
Download Telegram
Channel created
قصد آموزش نداریم چون خیلی از سایت ها و کانال ها و پیج ها به بهترین شکل و به طور رایگان آموزش این زبان ها رو در اختیارتون قرار میدن

هدف ریز نکات و پروژه هایی ست که با این زبان ها انجام شدند
با قرار دادن سورس کد های آن ها و توضیح راجع به آن به یادگیری حرفه ای ( Intermediate ) می پردازیم
@de_coder
1.ساخت هرم
زبان نوشتاری JAVA
سطح سوال : بسیار آسان
*********//*********
// program to build pyramid with x in n stages
import java.util.Scanner;
public class pyramid
{
public static void main(String[] args) {
int i,n,m,k,j=1;
Scanner obj=new Scanner(System.in);
System.out.println("enter the no. stages in pyramid ");
System.out.println("u entered");
n=obj.nextInt();
System.out.println("ur beautiful Egypt pyramid is here");
m=n;
for(i=1;i<=n;i++)
{
while(j<m)
{
System.out.print(" ");
j++;
}
for(k=1;k<=i;k++)
{
System.out.print("x");
}
System.out.println(" ");
m=m-1;
j=1;
}


}
}


@de_coder
به عنوان مثال اگر عدد 5 را وارد کنید چنین خروجی را مشاهده می کنید
@de_coder
2. بازی کماندار در مقابل اُرگ
زبان نوشتاری ++C
سطح برنامه : متوسط
*********//*********
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;

class hero
{
protected:
string name;
double life;
double attack;
double defense;

public:
virtual void myattack(hero&)=0;

double get_life() const
{
return this->life;
}
string get_name() const
{
return this->name;
}
double get_defense() const
{
return this->defense;
}
void set_life(double x)
{
this->life = x;
}
void set_attack(double x)
{
this->attack = x;
}
};

class orc : public hero
{
public:
orc() {
this->name = "Ushk";
this->life = 60;
this->defense = 25;
}
~orc(){}

void myattack (hero &h)
{

double aux;
cout<<this->name<<" made an Axe attack - ";

if(this->attack > h.get_defense())
{
aux = (this->attack - h.get_defense());

cout<< h.get_name() <<" received "<< aux <<" damage\n";

aux = h.get_life() - aux;
h.set_life(aux);
}
else
cout<<" **Attack miss** \n";
}
};

class archer : public hero
{
public:
archer(){
this->name = "Legolas";
this->life = 40;
this->defense = 10;
}
~archer(){}

void myattack (hero& h)
{

double aux;
cout<< this->name <<" throw an Arrow - ";

if(this->attack > h. get_defense())
{
aux = (this->attack - h.get_defense());

cout<< h.get_name() <<" received "<< aux <<" damage\n";

aux = h.get_life() - aux;
h.set_life(aux);
}
else
cout<<" **Attack miss**\n";
}
};

int main() {
srand(time(NULL));
orc orc1;
archer arch1;
double num;

while(1)
{
num = rand()%13+13;

orc1.set_attack(num);
orc1.myattack(arch1);

if(arch1.get_life() <= 0){
cout<<arch1.get_name()
<< " **Died**";
break;
}

num = rand()%30+23;
arch1.set_attack(num);
arch1.myattack(orc1);

if(orc1.get_life() <= 0){
cout<<orc1.get_name()
<<" **Died**";
break;
}
}
return 0;
}

@de_coder
این بازی برای یک نمونه ی داده شده توسط خود برنامه نویس نوشته شده
شما می توانید نوع اجرای برنامه را باب میل خود تغییر دهید

در ضمن برای فراگیری این برنامه نیاز هست که بخش شئ گرایی زبان ++C را بلد باشید

@de_coder
3. محاسبه ی عدد پی
زبان نوشتای Ruby
سطح برنامه : آسان
*********//*********
num = 4.0
pi = 0
plus = true

den = 1
while den < 10000000
if plus
pi = pi + num/den
plus = false
else
pi = pi - num/den
plus = true
end
den = den + 2
end

puts "PI = #{pi}" # calculated value of pi
puts "Math::PI = #{Math::PI}" # pi from the math class

@de_coder
خروجی برنامه ی بالا
همان طور که مشاهده می کنید
عدد اولی محاسبه شده
و عدد دومی عدد پی ( با تعریف جهانی )

در آینده بیشتر راجع به زبان Ruby صحبت خواهیم کرد
@de_coder
4. مرتب سازی Insertion sort
زبان نوشتاری JAVA
سطح سوال : آسان
*********//*********

public class Main
{

public static void main(String[] args)
{
System.out.println(" The Number Before sorting :");
int[] ay = {
5,6,7,3,5,7,8,8,6,4,2,6,8,6,3,2,6,6,8,8,4,3,6,8,
5,4,3,2,1,6,4,2,4,6,7,7,9,7,5,4,6,7,9,7,5,3,3,46,7,8,9,6,5,3,4,6,7,7,8,9,5,6,4,3,5,7,7
,5,6,7,3,2,5,6,3,6,4,6,5,4,3,35,5,5,2,5,3,4,66,3,5,3,5,3,5,5,3,5,3,5,4,5,4,7,5,4,5,5,5,4,3,3,1,2,1
};
print(ay);
System.out.println("\n\n\n");
int[] l = insertionsrt(ay);
System.out.println("After sorting with Insertion Sort :");
print(l);
System.out.println("\n\n\n");


}
static int c = 0;
public static void print(int[] arr){
if(c<arr.length){
System.out.print(arr[c++]+",");
print(arr);
}
else{
c=0;
return;
}}

private static int[] sorter;
private static void swap(int post1,int post2){
int val1 = sorter[post1],

val2 = sorter[post2];
sorter[post1] = val2;
sorter[post2] = val1;
}
public static int[] insertionsrt(int[] arr){
sorter = arr;
int x1 = 0,
x2 = 0,
y1 = 0,
y2 = 0,
idx = sorter.length-1,
post1 = 0;
boolean done = true;
while(done) {
if(x1 <idx){
x2 = x1+1;
if(x1 == 0 && x2 == 1){
if(sorter[x2]<sorter[x1])swap(x1,x2);
post1++;
x1++;
}
else{
//TODO
if(post1 == 1){
//TODO
if(sorter[x2]<sorter[x1])swap(x1,x2);
post1++;

}
else if(post1 == 2){
//TODO
y1 = x1;
y2 = y1-1;
while(y2 > -1)
{
if(sorter[y1] < sorter[y2]){
swap(y2,y1);
}
y2--;y1--;
}

post1--;
x1++;
}
//TODO
}
}
else done = false;
}
return sorter;
}
}

@de_coder
این برنامه با یک ورودی به صورت پیشفرض نوشته شده است و شما می توانید نوع ورودی را بنا بر خواسته ی خود تغییر داده
در آینده راجع به کامنت TODO صحبت خواهیم کرد

@de_coder
قبل از مرتب سازی

@de_coder
بعد از مرتب سازی

@de_coder