poniedziałek, 4 stycznia 2016

Date and time in Visual C++




And code:
#pragma endregion
private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
DateTime time1=DateTime::Now;
label1->Text=time1.Hour.ToString("D2")+":"+time1.Minute.ToString("D2")+
":"+time1.Second.ToString("D2");
label2->Text=time1.Year.ToString()+"-"+time1.Month.ToString()+"-"+
time1.Day.ToString()+" --- "+time1.DayOfWeek.ToString();
int second,minutes,hours,months,days;
second=time1.Second;
progressBar1->Value=second;
label6->Text=second.ToString();
minutes=time1.Minute;
progressBar2->Value=minutes;
label7->Text=minutes.ToString();
hours=time1.Hour;
progressBar3->Value=hours;
label8->Text=hours.ToString();
months=time1.Month;
dataGridView1->Rows[months-1]->DefaultCellStyle->BackColor=System::Drawing::Color::Yellow;
String^ day_of_week=time1.DayOfWeek.ToString();
if(day_of_week==Days[0])
dataGridView2->Rows[0]->DefaultCellStyle->BackColor=System::Drawing::Color::Red;
else if(day_of_week==Days[1])
dataGridView2->Rows[1]->DefaultCellStyle->BackColor=System::Drawing::Color::Red;
else if(day_of_week==Days[2])
dataGridView2->Rows[2]->DefaultCellStyle->BackColor=System::Drawing::Color::Red;
else if(day_of_week==Days[3])
dataGridView2->Rows[3]->DefaultCellStyle->BackColor=System::Drawing::Color::Red;
else if(day_of_week==Days[4])
dataGridView2->Rows[4]->DefaultCellStyle->BackColor=System::Drawing::Color::Red;
else if(day_of_week==Days[5])
dataGridView2->Rows[5]->DefaultCellStyle->BackColor=System::Drawing::Color::Red;
else if(day_of_week==Days[6])
dataGridView2->Rows[6]->DefaultCellStyle->BackColor=System::Drawing::Color::Red;


 
}
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
timer1->Start();
int i;
dataGridView1->ColumnCount=1;
dataGridView1->RowCount=12;
                 array<String^>^ Months=gcnew array<String^>(12);
Months[0]=gcnew String("January");
Months[1]=gcnew String("February");
Months[2]=gcnew String("March");
Months[3]=gcnew String("April");
Months[4]=gcnew String("May");
Months[5]=gcnew String("June");
Months[6]=gcnew String("July");
Months[7]=gcnew String("August");
Months[8]=gcnew String("September");
Months[9]=gcnew String("Oktober");
Months[10]=gcnew String("November");
Months[11]=gcnew String("December");
for(i=0;i<12;i++)
dataGridView1->Rows[i]->Cells[0]->Value=Months[i];
dataGridView2->ColumnCount=1;
dataGridView2->RowCount=7;
Days=gcnew array<String^>(7);
Days[0]=gcnew String("Monday");
Days[1]=gcnew String("Tuesday");
Days[2]=gcnew String("Wednesday");
Days[3]=gcnew String("Thursday");
Days[4]=gcnew String("Friday");
Days[5]=gcnew String("Saturday");
Days[6]=gcnew String("Sunday");
for(i=0;i<7;i++)
dataGridView2->Rows[i]->Cells[0]->Value=Days[i];

}
private: System::Void Form1_FormClosing(System::Object^  sender, System::Windows::Forms::FormClosingEventArgs^  e) {
timer1->Stop();
}
private: System::Void panel1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
}
};

niedziela, 3 stycznia 2016

Firtst numbers and difference

#include <iostream>
using namespace std;

bool my_first(int number)
{
int sum,i;
sum=0;
for(i=1;i<number+1;i++)
if(number%i==0)
 ++sum;
if(sum==2)
 return true;
else
 return false;
}

int main(int argc, char** argv)
{
int x,difference,r;
x=1;
r=0;
for(;;)
{
if(my_first(x))
{
   
   difference=r+1;
cout<<"+"<<difference<<"\n";
cout<<x<<" first"<<endl;
r=0;
}
else
{
++r;
   }
   ++x;
 }
return 0;
}