wtorek, 31 października 2017

Dependencies of prime numbers display and save to file (Visual C++)


In the File:



using namespace System::IO;
#pragma endregion
private:
int *table_first,*sum_t,*sum_max;
float *ms_sum,*ms_first;
private:
System::Boolean is_First(System::Int16 Value)
{
System::Int16 i;
System::Int16 sum;
for(i=1;i<Value+1;i++)
if(Value%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
private:
System::Void init_Table()
{
System::Int16 i;
System::Int16 j;
System::Int16 k;
System::Int16 sum;
i=0;
j=2;
do
{
              
 if(is_First(j))
 {
 sum=0;
 table_first[i]=j;
 sum_t[i]=sum_Table(table_first,i+1);
 for(k=1;k<j+1;k++)
 sum+=k;
 sum_max[i]=sum;
 ms_sum[i]=(1.0*sum_max[i])/(sum_t[i]*1.0);
 ms_first[i]=(1.0*sum_t[i])/(1.0*table_first[i]);

 ++i;
 }
 ++j;
}while(i<50);
}
private:
System::Int16 sum_Table(int *table, System::Int16 size)
{
System::Int16 i;
System::Int16 sum;
sum=0;
for(i=0;i<size;i++)
sum+=table[i];
return sum;
}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
delete ms_sum;
delete ms_first;
delete table_first;
delete sum_max;
delete sum_t;

 
 Close();
}
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
table_first=new int[50];
sum_max=new int[50];
sum_t=new int[50];
ms_sum=new float[50];
ms_first=new float[50];
init_Table();
}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
System::Int16 i;
System::Int16 sum;
listBox1->Items->Clear();
listBox2->Items->Clear();
listBox3->Items->Clear();
listBox4->Items->Clear();
listBox5->Items->Clear();
for(i=0;i<50;i++)
{
listBox1->Items->Add(table_first[i].ToString());
listBox2->Items->Add(sum_t[i].ToString());
listBox3->Items->Add(sum_max[i].ToString());
listBox4->Items->Add(ms_sum[i].ToString());
listBox5->Items->Add(ms_first[i].ToString());
 
}
StreamWriter^ mFile=gcnew StreamWriter("mFile.txt",0,System::Text::Encoding::Default);
for(i=0;i<50;i++)
{
mFile->WriteLine(table_first[i].ToString());
mFile->WriteLine(sum_t[i].ToString());
mFile->WriteLine(sum_max[i].ToString());
mFile->WriteLine(ms_sum[i].ToString());
mFile->WriteLine(ms_first[i].ToString());
}
mFile->Close();
 
}
};
}



sobota, 28 października 2017

File attributes (C++ Builder)



private:    // User declarations
    HANDLE idFile;
    TSearchRec tempSR;
    UnicodeString f,t;
    DWORD sizeB;
    wchar_t buffer_Memo[8192],s;
    void __fastcall connect_Components();


TForm1 *Form1;
SECURITY_ATTRIBUTES app_Attr={sizeof(SECURITY_ATTRIBUTES),NULL,TRUE};
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::connect_Components()
{
    f="FALSE";
    t="TRUE";
    s='.';
    DirectoryListBox1->FileList=FileListBox1;
    DriveComboBox1->DirList=DirectoryListBox1;
    FileListBox1->FileEdit=Edit1;
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
 connect_Components();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
 Close();
}
//---------------------------------------------------------------------------


void __fastcall TForm1::FileListBox1Change(TObject *Sender)
{
 int i;
 tempSR.Name=Edit1->Text;
 tempSR.Attr=FileGetAttr(tempSR.Name);
 if((tempSR.Attr && faArchive)==faArchive)
  Edit2->Text=t;
 else
  Edit2->Text=f;
 if((tempSR.Attr & faSysFile)==faSysFile)
  Edit3->Text=t;
 else
  Edit3->Text=f;
 if((tempSR.Attr & faReadOnly)==faReadOnly)
  Edit4->Text=t;
 else
  Edit4->Text=f;
 if((tempSR.Attr & faHidden)==faHidden)
  Edit5->Text=t;
 else
  Edit5->Text=f;
  memset(buffer_Memo,0,sizeof(buffer_Memo)-1);
  idFile=CreateFile(FileListBox1->FileName.c_str(),GENERIC_READ,FILE_SHARE_READ,
  &app_Attr,OPEN_EXISTING,0,NULL);
  if(idFile!=INVALID_HANDLE_VALUE)
   ReadFile(idFile,&buffer_Memo,sizeof(buffer_Memo),&sizeB,NULL);
  for(i=0;i<sizeof(buffer_Memo)-1;i++)
   if(buffer_Memo[i]==NULL)
    buffer_Memo[i]=s;
  Memo1->Text=buffer_Memo;
  CloseHandle(idFile);
}

piątek, 6 października 2017

Use a queue to generate web addresses with a component dataGridView (Visual C++)




Code class in a separate file:

template <class mainType> class MY
{
private:
System::Int64 start,end,max;
mainType *mT;
public:
MY(System::Int64 value)
{
mT=new mainType[max+1];
start=0;
end=0;
max=value;

}
System::Boolean is_Empty()
{
if(start==end)
return true;
else
return false;
}
System::Int64 order(mainType &value)
{
if(start==end)
return -1;
value=mT[start++];
if(start>max)
start=0;
return 1;

}
System::Void insert(mainType value)
{
mT[end++]=value;
if(end>max)
end=0;
}
};

Main program:

#pragma endregion
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
char **tables,*WWW;
tables=new char*[10];
System::Int64 i;
System::Int64 temp_Bool;
for(i=0;i<10;i++)
tables[i]=new char[20];
tables[0]="www.hpe.com";
tables[1]="www.ibm.com";
tables[2]="www.google.com";
tables[3]="www.cnn.com";
tables[4]="www.yahoo.com";
tables[5]="www.nasa.org";
tables[6]="www.microsoft.com";
tables[7]="www.linux.com";
tables[8]="www.embarcadero.com";
tables[9]="www.java.com";
array<System::String^>^ string_Tables=gcnew array<System::String^>(10);
 
MY<char*> FIFO_values(11);
dataGridView1->ColumnCount=1;
dataGridView1->RowCount=10;
 
for(i=0;i<10;i++)
{
FIFO_values.insert(tables[i]);
System::String^ temp=gcnew System::String(tables[i]);
dataGridView1->Rows[i]->Cells[0]->Value=temp;
 

}
for(i=0;i<11;i++)
{
temp_Bool=FIFO_values.order(WWW);
if(temp_Bool==true)
{
System::String^ temp=gcnew System::String(WWW);
listBox1->Items->Add("You can use - "+temp);
}

}

for(i=0;i<10;i++)
delete [] tables[i];
delete [] *tables;


}
private: System::Void dataGridView1_CellContentClick(System::Object^  sender, System::Windows::Forms::DataGridViewCellEventArgs^  e) {
System::String^ myWWW;
myWWW="http:/";
myWWW=safe_cast<DataGridView^>(sender)->CurrentCell->Value->ToString();
System::Diagnostics::Process::Start(myWWW);
}
};
}

I tried to use the structure - array<System::String^>^ tables=gcnew array<System::String^>(10),but for costructor class (new[max+1]) type String^ and array showed errors. So i used - char*.