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

Calender Code

مغلق
بدأه sugar88 في 6 يناير 2008 · 1 رد · 1,501 مشاهدة · في C++.Net
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

كود للتقويم الميلادي

بتمنى يعجبكم

# include <iostream.h>
int  main(){
int Year,Day,Month,LastDay=0,Marks=1;
cout<<"Enter month number"<<endl;  //asks the user to enter month of year
cin>>Month;
cout<<"Enter the year you want to show it's calender  "<<endl;
cin>>Year;
cout<<"Enter the first day of the month you entered";
cin>>Day;

 if (Year%4)   //cheak if it's leap year or not  , not a leap year

  if(Month==4||Month==6||Month==9||Month==11)	   // if conditional if it's not a leap year
	{ LastDay=30;	// show the last day of the 4,6,9,11 month which is =30

  }
  else
   { LastDay=31;	// show the last day of the rest of the month which is =31

	}
 else
  if(Year%400)	  //cheak if it's leap year or not  ,it's  a leap year

  {
   if(Year%100)   // it's leap year for month 2 which has 29 days in Fbr
	if(Month==2)
	{LastDay=29;
	}
   else if(Month==4||Month==6||Month==9||Month==11)
   {LastDay=30;

   }
   else
   {LastDay=31;

   }
   else

	if(Month==2)
	{LastDay=28;

	}
   else if(Month==4||Month==6||Month==9||Month==11)
   {LastDay=30;

   }
	else
	{LastDay=31;

	}

  }
 else

   if(Month==4||Month==6||Month==9||Month==11)
   {LastDay=31;

   }

  else
   {LastDay=31;

   }
switch(Month){
 case 1:
  cout<<"   January  "<<Year<<endl;

  break;
 case 2:
  cout<<"   February  "<<Year<<endl;

  break;
 case 3:
  cout<<"   March  "<<Year<<endl;

  break;
 case 4:
  cout<<"   April  "<<Year<<endl;

  break;
 case 5:
  cout<<"   May  "<<Year<<endl;

  break;
 case 6:
  cout<<"   June  "<<Year<<endl;

  break;
 case 7:
  cout<<"   July  "<<Year<<endl;

  break;
 case 8:
  cout<<"   August  "<<Year<<endl;

  break;
 case 9:
  cout<<"   September  "<<Year<<endl;

  break;
 case 10:
  cout<<"   October  "<<Year<<endl;

  break;
 case 11:
  cout<<"   November, "<<Year<<endl;

  break;
 case 12:
  cout<<"   December, "<<Year<<endl;

  break;
 default:
  cout<<"Out of Range"<<endl;
}							  //end switch statment

cout<<"Su Mo Tu We Th Fr Sa"<<endl;


for(int X=2;X<=Day;X++){		   //Helping to print spaces depend on day that he user enterd

 cout<<"   ";
 Marks++;
}

for(int Y=1;Y<=LastDay;Y++){		// if conditional  it is between 1 and 9
 if(Y>=1 && Y<=9) {
 cout<<" "<<Y<<" ";
 }
 else {
  cout<<Y<<" ";
 }

 Marks++;
 if(Marks%7==1)
  cout<<endl;				 //print new line depending on the marks
}
cout<<endl;

اشتغلت عليه انا وصاحبتي .. ان شالله تستفيدو منه

#2

جميل و محاولة جيدة جدا, الخطوة التالية هى إستخدام ال arrays بقا فى نفس البرنامج علشان تقلل عدد سطور الكود. ربنا يوفقك.

هذا الموضوع مغلق.

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