#include <iostream>
#include <string.h>
using namespace std;
class Binary
{
private:
char temp_values[10];
int my_byts;
public:
char *result;
char *negation;
Binary()
{
int i,j;
j=1;
for(i=0;i<10;i++)
{
temp_values[i]=j;
j*=2;
}
result=new char[10];
result[0]='0';
negation=new char[10];
negation[0]='1';
}
void read_Binary(char digit)
{
int i;
for(i=9;i>=0;i--)
{
my_byts=(temp_values[i] & digit);
if(my_byts!=0)
{
strcat(result,"1");
strcat(negation,"0");
}
else
{
strcat(result,"0");
strcat(negation,"1");
}
}
}
void write_Binary()
{
cout<<result;
}
void write_Negation()
{
cout<<negation;
}
~Binary()
{
delete negation;
delete result;
}
};
int my_first_digit[10];
char char_first_table[10];
bool is_First(int x)
{
int i,sum;
sum=0;
for(i=1;i<x+1;i++)
if(x%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
void init_my_first_Table()
{
int i,j;
i=0;
j=1;
do
{
if(is_First(j))
{
my_first_digit[i]=j;
++i;
}
++j;
}while(i<10);
for(i=0;i<10;i++)
char_first_table[i]=my_first_digit[i];
}
int main(int argc, char **argv)
{
Binary *binary_First=new class Binary[10];
int i;
init_my_first_Table();
for(i=0;i<10;i++)
{
binary_First[i].read_Binary(char_first_table[i]);
cout<<my_first_digit[i]<<" - ";
binary_First[i].write_Binary();cout<<" - ";
binary_First[i].write_Negation();
cout<<endl;
}
delete binary_First;
return 0;
}
Result for table[10] (first digit) binary and negation:
2 - 00000000010 - 11111111101
3 - 00000000011 - 11111111100
5 - 00000000101 - 11111111010
7 - 00000000111 - 11111111000
11 - 00000001011 - 11111110100
13 - 00000001101 - 11111110010
17 - 00000010001 - 11111101110
19 - 00000010011 - 11111101100
23 - 00000010111 - 11111101000
29 - 00000011101 - 11111100010
poniedziałek, 6 marca 2017
piątek, 3 marca 2017
My class which random and sorting another value in Visual C++
sorting_random.h
#include <stdlib.h>
#include <time.h>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
#pragma once
ref class sorting_random
{
private:
System::Int16 my_size;
System::Int16 h_Many;
array<System::Single>^ table_value;
array<System::Single>^ temp_table;
public:
sorting_random(int size_array, int how_many);
void random_another_Value();
void Sorting();
void Write(ListBox^ LB);
};
sorting_random.cpp
#include "StdAfx.h"
#include "sorting_random.h"
sorting_random::sorting_random(int size_array, int how_many)
{
srand(time(NULL));
my_size=size_array;
h_Many=how_many;
table_value=gcnew array<System::Single>(h_Many);
temp_table=gcnew array<System::Single>(my_size);
}
void sorting_random::random_another_Value()
{
System::Int16 i;
System::Int16 j;
System::Int16 value;
for(i=0;i<my_size;i++)
temp_table[i]=0;
i=0;
do
{
do
{
value=rand()%my_size;
}while(temp_table[value]!=0);
temp_table[value]=1;
table_value[i]=value;
++i;
}while(i<h_Many);
}
void sorting_random::Sorting()
{
System::Int16 i;
System::Int16 j;
System::Int16 temp;
for(i=1;i<h_Many;i++)
for(j=h_Many-1;j>=i;j--)
if(table_value[j]<table_value[j-1])
{
temp=table_value[j-1];
table_value[j-1]=table_value[j];
table_value[j]=temp;
}
}
void sorting_random::Write(ListBox^ LB)
{
System::Int16 i;
for(i=0;i<h_Many;i++)
LB->Items->Add(table_value[i].ToString());
}
#include <stdlib.h>
#include <time.h>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
#pragma once
ref class sorting_random
{
private:
System::Int16 my_size;
System::Int16 h_Many;
array<System::Single>^ table_value;
array<System::Single>^ temp_table;
public:
sorting_random(int size_array, int how_many);
void random_another_Value();
void Sorting();
void Write(ListBox^ LB);
};
sorting_random.cpp
#include "StdAfx.h"
#include "sorting_random.h"
sorting_random::sorting_random(int size_array, int how_many)
{
srand(time(NULL));
my_size=size_array;
h_Many=how_many;
table_value=gcnew array<System::Single>(h_Many);
temp_table=gcnew array<System::Single>(my_size);
}
void sorting_random::random_another_Value()
{
System::Int16 i;
System::Int16 j;
System::Int16 value;
for(i=0;i<my_size;i++)
temp_table[i]=0;
i=0;
do
{
do
{
value=rand()%my_size;
}while(temp_table[value]!=0);
temp_table[value]=1;
table_value[i]=value;
++i;
}while(i<h_Many);
}
void sorting_random::Sorting()
{
System::Int16 i;
System::Int16 j;
System::Int16 temp;
for(i=1;i<h_Many;i++)
for(j=h_Many-1;j>=i;j--)
if(table_value[j]<table_value[j-1])
{
temp=table_value[j-1];
table_value[j-1]=table_value[j];
table_value[j]=temp;
}
}
void sorting_random::Write(ListBox^ LB)
{
System::Int16 i;
for(i=0;i<h_Many;i++)
LB->Items->Add(table_value[i].ToString());
}
And example:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
sorting_random table_random(30,10);
table_random.random_another_Value();
table_random.Sorting();
table_random.Write(listBox1);
sorting_random smile_table(6,3);
smile_table.random_another_Value();
smile_table.Sorting();
smile_table.Write(listBox2);
sorting_random next_table(100,85);
next_table.random_another_Value();
next_table.Sorting();
next_table.Write(listBox3);
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
Close();
}
};
czwartek, 2 marca 2017
My time_class in Visual C++
time_class.h
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
ref class time_class
{
private:
DateTime begin_time;
String^ time_Minutes;
String^ time_Seconds;
TimeSpan^ time_work;
public:
time_class(void);
void Read();
void Write();
};
time_class.cpp
#include "StdAfx.h"
#include "time_class.h"
time_class::time_class(void)
{
begin_time=DateTime::Now;
}
void time_class::Read()
{
time_work=gcnew TimeSpan();
DateTime temp_time;
temp_time=DateTime::Now;
time_work=temp_time-begin_time;
time_Minutes=time_work->Minutes.ToString()+ " minutes ";
time_Seconds=time_work->Seconds.ToString()+ " seconds ";
}
void time_class::Write()
{
MessageBox::Show("Time work is: "+time_Minutes+":"+time_Seconds,"TIME",MessageBoxButtons::OK,MessageBoxIcon::Information);
}
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
ref class time_class
{
private:
DateTime begin_time;
String^ time_Minutes;
String^ time_Seconds;
TimeSpan^ time_work;
public:
time_class(void);
void Read();
void Write();
};
time_class.cpp
#include "StdAfx.h"
#include "time_class.h"
time_class::time_class(void)
{
begin_time=DateTime::Now;
}
void time_class::Read()
{
time_work=gcnew TimeSpan();
DateTime temp_time;
temp_time=DateTime::Now;
time_work=temp_time-begin_time;
time_Minutes=time_work->Minutes.ToString()+ " minutes ";
time_Seconds=time_work->Seconds.ToString()+ " seconds ";
}
void time_class::Write()
{
MessageBox::Show("Time work is: "+time_Minutes+":"+time_Seconds,"TIME",MessageBoxButtons::OK,MessageBoxIcon::Information);
}
środa, 22 lutego 2017
transition graph
#include <iostream>
using namespace std;
int value_letter[15];
char *letter_Value[15]={"BCF","AFHKL","CEF","CDEJI","ADEF","MNO","CDE",
"ADH","EFGH","CEKL","ABE","ABC","CFJ","EFGH","ABM"};
char give_Letter(char a)
{
return ((a)-'A');
}
void Read(char letter)
{
char *temp_text;
value_letter[give_Letter(letter)]=1;
cout<<letter<<endl;
for(temp_text=letter_Value[give_Letter(letter)];*temp_text;temp_text++)
if(!(value_letter[give_Letter(*temp_text)]))
Read(*temp_text);
}
int main(int argc, char **argv)
{
char my_letter;
for(my_letter='A';my_letter<'P';my_letter++)
if(!(value_letter[give_Letter(my_letter)]))
Read(my_letter);
return 0;
}
using namespace std;
int value_letter[15];
char *letter_Value[15]={"BCF","AFHKL","CEF","CDEJI","ADEF","MNO","CDE",
"ADH","EFGH","CEKL","ABE","ABC","CFJ","EFGH","ABM"};
char give_Letter(char a)
{
return ((a)-'A');
}
void Read(char letter)
{
char *temp_text;
value_letter[give_Letter(letter)]=1;
cout<<letter<<endl;
for(temp_text=letter_Value[give_Letter(letter)];*temp_text;temp_text++)
if(!(value_letter[give_Letter(*temp_text)]))
Read(*temp_text);
}
int main(int argc, char **argv)
{
char my_letter;
for(my_letter='A';my_letter<'P';my_letter++)
if(!(value_letter[give_Letter(my_letter)]))
Read(my_letter);
return 0;
}
niedziela, 19 lutego 2017
Class my_CPU_value (g++)
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
class my_CPU_value
{
private:
char *text_speed_Mhz;
char *text_cache_size;
char *text_name;
float value_Mhz;
int cache_size;
char model_name[96];
char my_buffer[4096];
FILE *init_file;
size_t value_read;
public:
my_CPU_value()
{
init_file=fopen("/proc/cpuinfo","r");
value_read=fread(my_buffer,1,sizeof(my_buffer),init_file);
fclose(init_file);
my_buffer[value_read]='\0';
text_speed_Mhz=strstr(my_buffer,"cpu MHz");
sscanf(text_speed_Mhz,"cpu MHz : %f",&value_Mhz);
text_cache_size=strstr(my_buffer, "cache size");
sscanf(text_cache_size,"cache size : %d",&cache_size);
text_name=strstr(my_buffer, "model name");
sscanf(text_name,"model name : %s",model_name);
}
void Write()
{
cout<<"Speed CPU = "<<value_Mhz<<" MHz"<<endl;
cout<<"Cache size = "<<cache_size<<endl;
cout<<"Model = "<<model_name<<endl;
}
};
int main(int argc, char **argv)
{
my_CPU_value C1;
C1.Write();
return 0;
}
#include <string.h>
#include <stdio.h>
using namespace std;
class my_CPU_value
{
private:
char *text_speed_Mhz;
char *text_cache_size;
char *text_name;
float value_Mhz;
int cache_size;
char model_name[96];
char my_buffer[4096];
FILE *init_file;
size_t value_read;
public:
my_CPU_value()
{
init_file=fopen("/proc/cpuinfo","r");
value_read=fread(my_buffer,1,sizeof(my_buffer),init_file);
fclose(init_file);
my_buffer[value_read]='\0';
text_speed_Mhz=strstr(my_buffer,"cpu MHz");
sscanf(text_speed_Mhz,"cpu MHz : %f",&value_Mhz);
text_cache_size=strstr(my_buffer, "cache size");
sscanf(text_cache_size,"cache size : %d",&cache_size);
text_name=strstr(my_buffer, "model name");
sscanf(text_name,"model name : %s",model_name);
}
void Write()
{
cout<<"Speed CPU = "<<value_Mhz<<" MHz"<<endl;
cout<<"Cache size = "<<cache_size<<endl;
cout<<"Model = "<<model_name<<endl;
}
};
int main(int argc, char **argv)
{
my_CPU_value C1;
C1.Write();
return 0;
}
sobota, 18 lutego 2017
First - next (C++)
bool __fastcall TForm1::is_First(int x)
{
int i,sum;
sum=0;
for(i=1;i<x+1;i++)
if(x%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
int __fastcall TForm1::Factorial(int x)
{
int i,value;
value=1;
for(i=1;i<x+1;i++)
value*=i;
return value;
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
StringGrid1->Cells[0][0]="First digits";
StringGrid2->Cells[0][0]="Not first";
StringGrid1->Cells[1][0]="Factorial";
StringGrid2->Cells[1][0]="Factorial";
StringGrid1->Cells[2][0]="First d. in F.";
StringGrid2->Cells[2][0]="First d. in F.";
StringGrid1->Cells[3][0]="Not f. in Fa.";
StringGrid2->Cells[3][0]="Not f. in Fa.";
StringGrid1->Cells[4][0]="First/not_first";
StringGrid2->Cells[4][0]="First/not_first";
StringGrid1->Cells[5][0]="Value:";
StringGrid2->Cells[5][0]="Value:";
int first[4],not_first[4],factorial_first[4],factorial_not_first[4];
int first_el[4],first_el2[4],not_first_el[4],not_first_el2[4];
float div_first[4],div_first2[4];
float new_value[4],new_value2[4];
int i,j;
i=0;j=2;
do
{
if(is_First(j))
{
first[i]=j;
++i;
}
++j;
}while(i<4);
i=0;j=1;
do
{
if(!is_First(j))
{
not_first[i]=j;
++i;
}
++j;
}while(i<4);
for(i=0;i<4;i++)
{
factorial_first[i]=Factorial(first[i]);
factorial_not_first[i]=Factorial(not_first[i]);
first_el[i]=0;
first_el2[i]=0;
not_first_el[i]=0;
not_first_el2[i]=0;
}
unsigned k;
i=0;
do
{
for(k=1;k<factorial_first[i]+1;k++)
{
if(is_First(k))
first_el[i]++;
else
not_first_el[i]++;
}
++i;
}while(i<4);
i=0;
do
{
for(k=1;k<factorial_not_first[i]+1;k++)
{
if(is_First(k))
first_el2[i]++;
else
not_first_el2[i]++;
}
++i;
}while(i<4);
for(i=0;i<4;i++)
{
div_first[i]=(1.*first_el[i])/(1.*not_first_el[i]);
div_first2[i]=(1.*first_el2[i])/(1.*not_first_el2[i]);
new_value[i]=div_first[i]*factorial_first[i];
new_value2[i]=div_first2[i]*factorial_not_first[i];
}
for(i=0;i<4;i++)
{
StringGrid1->Cells[0][i+1]=IntToStr(first[i]);
StringGrid2->Cells[0][i+1]=IntToStr(not_first[i]);
StringGrid1->Cells[1][i+1]=IntToStr(factorial_first[i]);
StringGrid2->Cells[1][i+1]=IntToStr(factorial_not_first[i]);
StringGrid1->Cells[2][i+1]=IntToStr(first_el[i]);
StringGrid2->Cells[2][i+1]=IntToStr(first_el2[i]);
StringGrid1->Cells[3][i+1]=IntToStr(not_first_el[i]);
StringGrid2->Cells[3][i+1]=IntToStr(not_first_el2[i]);
StringGrid1->Cells[4][i+1]=FloatToStr(div_first[i]);
StringGrid2->Cells[4][i+1]=FloatToStr(div_first2[i]);
StringGrid1->Cells[5][i+1]=FloatToStr(new_value[i]);
StringGrid2->Cells[5][i+1]=FloatToStr(new_value2[i]);
}
}
Prime numbers transformation (C++ Builder)
private: // User declarations
bool __fastcall is_First(int x);
void __fastcall init_Random();
void __fastcall init_Table();
void __fastcall delete_Table();
int sum_first;
float *first_per_sum,sum_first_per_sum;
float *first_per_next_sum,sum_first_per_next_sum;
float *table_double_sum,sum_double_sum;
float *pow_first_per_next_sum,sum_pow_first;
int *sum_minus_first,sum_minus;
float *next_digit,sum_digit;
float *new_value,sum_new_value;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
int *my_first;
bool __fastcall TForm1::is_First(int x)
{
int i,sum;
sum=0;
for(i=1;i<x+1;i++)
if(x%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
void __fastcall TForm1::init_Random()
{
srand(time(NULL));
}
void __fastcall TForm1::init_Table()
{
my_first=new int[36];
first_per_sum=new float[36];
first_per_next_sum=new float[36];
table_double_sum=new float[36];
pow_first_per_next_sum=new float[36];
sum_minus_first=new int[36];
next_digit=new float[36];
new_value=new float[36];
sum_first=0;
int i,j;
i=0;j=2;
do
{
if(is_First(j))
{
my_first[i]=j;
sum_first+=j;
++i;
}
++j;
}while(i<36);
sum_first_per_sum=0.;
sum_minus=0;
for(i=0;i<36;i++)
{
first_per_sum[i]=(1.*my_first[i])/(sum_first*1.);
sum_first_per_sum+=first_per_sum[i];
sum_minus_first[i]=sum_first-my_first[i];
sum_minus+=sum_minus_first[i];
}
next_digit[0]=0.;
sum_digit=0.0;
for(i=1;i<36;i++)
{
next_digit[i]=(1.*sum_minus_first[i])/(1.*sum_minus_first[i-1]);
sum_digit+=next_digit[i];
}
first_per_next_sum[0]=0.;
sum_first_per_next_sum=0.;
sum_pow_first=0.;
sum_double_sum=0.;
for(i=1;i<36;i++)
{
first_per_next_sum[i]=(1.*my_first[i])/(1.*my_first[i-1]);
sum_first_per_next_sum+=first_per_next_sum[i];
}
for(i=0;i<36;i++)
{
table_double_sum[i]=first_per_sum[i]+first_per_next_sum[i];
sum_double_sum+=table_double_sum[i];
pow_first_per_next_sum[i]=first_per_next_sum[i]*first_per_next_sum[i];
sum_pow_first+=pow_first_per_next_sum[i];
}
sum_new_value=0.0;
for(i=0;i<36;i++)
{
new_value[i]=((sum_minus-(my_first[i]*first_per_next_sum[i]*first_per_next_sum[i]))/sum_first);;
sum_new_value+=new_value[i];
}
}
void __fastcall TForm1::delete_Table()
{
delete my_first;
delete first_per_next_sum;
delete table_double_sum;
delete sum_minus_first;
delete next_digit;
delete pow_first_per_next_sum;
delete first_per_sum;
delete new_value;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
init_Random();
init_Table();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
delete_Table();
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i;
for(i=0;i<36;i++)
{
ListBox1->Items->Add(IntToStr(my_first[i]));
ListBox2->Items->Add(FloatToStr(first_per_sum[i]));
ListBox3->Items->Add(FloatToStr(first_per_next_sum[i]));
ListBox4->Items->Add(FloatToStr(table_double_sum[i]));
ListBox5->Items->Add(FloatToStr(pow_first_per_next_sum[i]));
ListBox6->Items->Add(IntToStr(sum_minus_first[i]));
ListBox7->Items->Add(FloatToStr(next_digit[i]));
ListBox8->Items->Add(FloatToStr(new_value[i]));
}
Edit1->Text=IntToStr(sum_first);
Edit2->Text=FloatToStr(sum_first_per_sum);
Edit3->Text=FloatToStr(sum_first_per_next_sum);
Edit4->Text=FloatToStr(sum_double_sum);
Edit5->Text=FloatToStr(sum_pow_first);
Edit6->Text=IntToStr(sum_minus);
Edit7->Text=FloatToStr(sum_digit);
Edit8->Text=FloatToStr(sum_new_value);
}
Subskrybuj:
Posty (Atom)


