#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;
}
środa, 22 lutego 2017
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);
}
piątek, 17 lutego 2017
Prime numbers (C++ Builder)
private: // User declarations
bool __fastcall is_First(int x);
void __fastcall init_Table();
public: // User declarations
int *my_first;
int *difference;
int *how_many;
int *how_many2;
int *not_first_minus;
int *not_first_minus2;
AnsiString text[50];
AnsiString text2[50];
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
my_first=new int[50];
difference=new int[50];
how_many=new int[50];
not_first_minus=new int[50];
how_many2=new int[50];
not_first_minus2=new int[50];
}
//---------------------------------------------------------------------------
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_Table()
{
int i,j;
i=0;
j=2;
do
{
if(is_First(j))
{
my_first[i]=j;
++i;
}
++j;
}while(i<50);
difference[0]=0;
for(i=1;i<50;i++)
{
difference[i]=my_first[i]-my_first[i-1];
}
for(i=0;i<50;i++)
{
how_many[i]=0;
how_many2[i]=0;
}
i=0;
do
{
for(j=1;j<my_first[i]+1;j++)
if(is_First(j))
++how_many[i];
else
++how_many2[i];
not_first_minus[i]=how_many2[i]-how_many[i];
if(is_First(not_first_minus[i]))
text[i]="yes";
else
text[i]="no";
not_first_minus2[i]=(how_many[i]-(how_many2[i]+difference[i]))*-1;
if(is_First(not_first_minus2[i]))
text2[i]="yes";
else
text2[i]="no";
++i;
}while(i<50);
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
delete my_first;
delete how_many;
delete not_first_minus;
delete not_first_minus2;
delete how_many2;
delete difference;
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
init_Table();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i;
for(i=0;i<50;i++)
{
ListBox1->Items->Add(IntToStr(my_first[i]));
ListBox2->Items->Add(IntToStr(difference[i]));
ListBox3->Items->Add(IntToStr(how_many[i])+" - " +IntToStr(how_many2[i]));
ListBox4->Items->Add(IntToStr(not_first_minus[i]));
ListBox5->Items->Add(text[i]);
ListBox6->Items->Add(IntToStr(not_first_minus2[i]));
ListBox7->Items->Add(text2[i]);
if((is_First(not_first_minus[i])) && is_First(not_first_minus2[i]))
ListBox8->Items->Add(IntToStr(my_first[i]));
if((!is_First(not_first_minus[i])) && !is_First(not_first_minus2[i]))
ListBox9->Items->Add(IntToStr(my_first[i]));
}
}
środa, 8 lutego 2017
Calendar 2017 (gcc)
#include <stdio.h>
#include <string.h>
char days[7][12]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
char months[12][12]={"January","February","March","April","Mai","June","July","August","September","Oktober","November","December"};
char days_in_year[365][12];
char months_in_year[365][12];
int nrday_in_year[365];
int main(int argc, char **argv)
{
int i,j,day;
j=0;
for(i=0;i<365;i++)
{
strcpy(days_in_year[i],days[j]);
j++;
if(j==7)
j=0;
}
day=0; //january
do
{
nrday_in_year[day]=day+1;
strcpy(months_in_year[day],months[0]);
++day;
}while(day<31);
day=31;i=1; //february
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[1]);
++i;++day;
}while(day<59);
day=59;i=1; //march
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[2]);
++i;++day;
}while(day<90);
day=90;i=1; //april
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[3]);
++i;++day;
}while(day<120);
day=120;i=1; //mai
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[4]);
++i;++day;
}while(day<151);
day=151;i=1;//june
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[5]);
++i;++day;
}while(day<181);
day=181;i=1; //july
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[6]);
++i;++day;
}while(day<212);
day=212;i=1; //august
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[7]);
++i;++day;
}while(day<243);
day=243;i=1; //september
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[8]);
++i;++day;
}while(day<273);
day=273;i=1;//oktober
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[9]);
++i;++day;
}while(day<304);
day=304;i=1;//november
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[10]);
++i;++day;
}while(day<334);
day=334;i=1; //december
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[11]);
++i;++day;
}while(day<365);
for(i=0;i<365;i++)
{
printf("%s - %d %s",months_in_year[i],nrday_in_year[i],days_in_year[i]);
printf("\n");
}
return 0;
}
#include <string.h>
char days[7][12]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
char months[12][12]={"January","February","March","April","Mai","June","July","August","September","Oktober","November","December"};
char days_in_year[365][12];
char months_in_year[365][12];
int nrday_in_year[365];
int main(int argc, char **argv)
{
int i,j,day;
j=0;
for(i=0;i<365;i++)
{
strcpy(days_in_year[i],days[j]);
j++;
if(j==7)
j=0;
}
day=0; //january
do
{
nrday_in_year[day]=day+1;
strcpy(months_in_year[day],months[0]);
++day;
}while(day<31);
day=31;i=1; //february
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[1]);
++i;++day;
}while(day<59);
day=59;i=1; //march
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[2]);
++i;++day;
}while(day<90);
day=90;i=1; //april
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[3]);
++i;++day;
}while(day<120);
day=120;i=1; //mai
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[4]);
++i;++day;
}while(day<151);
day=151;i=1;//june
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[5]);
++i;++day;
}while(day<181);
day=181;i=1; //july
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[6]);
++i;++day;
}while(day<212);
day=212;i=1; //august
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[7]);
++i;++day;
}while(day<243);
day=243;i=1; //september
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[8]);
++i;++day;
}while(day<273);
day=273;i=1;//oktober
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[9]);
++i;++day;
}while(day<304);
day=304;i=1;//november
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[10]);
++i;++day;
}while(day<334);
day=334;i=1; //december
do
{
nrday_in_year[day]=i;
strcpy(months_in_year[day],months[11]);
++i;++day;
}while(day<365);
for(i=0;i<365;i++)
{
printf("%s - %d %s",months_in_year[i],nrday_in_year[i],days_in_year[i]);
printf("\n");
}
return 0;
}
niedziela, 5 lutego 2017
File information (C++ Builder)
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
AnsiString text_application=Application->ExeName;
TSearchRec file_info;
ListBox1->Items->Add("Name my application: "+text_application);
ListBox1->Items->Add("Directory name: "+ExtractFileDir(text_application));
ListBox1->Items->Add("Disc label: "+ExtractFileDrive(text_application));
ListBox1->Items->Add("Extract file: "+ExtractFileExt(text_application));
ListBox1->Items->Add("Path: "+ExtractRelativePath(GetCurrentDir(),text_application));
ListBox1->Items->Add("Full name: "+ExtractShortPathName(text_application));
if(FindFirst(text_application,faAnyFile,file_info)!=0)
{
return;
}
FindClose(file_info);
ListBox1->Items->Add("Size: "+IntToStr(file_info.Size) );
ListBox1->Items->Add("Attr: "+IntToStr(file_info.Attr));
ListBox1->Items->Add("Last modification: "+DateTimeToStr(FileDateToDateTime(file_info.Time)));
}
Saving now time on the Web page (gcc)
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
int main(int argc, char **argv)
{
FILE *my_file;
char my_time;
struct timeval time1;
struct tm *time2;
gettimeofday(&time1,NULL);
time2=localtime(&time1.tv_sec);
char my_buffor[64];
char *my_page=
"<html>\n"
"</head>\n"
"<body>\n"
" <p> Now time: %s.</p>\n"
" </body>\n"
"</html>\n";
strftime(my_buffor,sizeof(my_buffor),"%H:%M:%S",time2);
my_file=fopen("my_site.html","w");
fprintf(my_file,my_page,my_buffor);
fflush(my_file);
fclose(my_file);
return 0;
}
#include <sys/time.h>
#include <time.h>
int main(int argc, char **argv)
{
FILE *my_file;
char my_time;
struct timeval time1;
struct tm *time2;
gettimeofday(&time1,NULL);
time2=localtime(&time1.tv_sec);
char my_buffor[64];
char *my_page=
"<html>\n"
"</head>\n"
"<body>\n"
" <p> Now time: %s.</p>\n"
" </body>\n"
"</html>\n";
strftime(my_buffor,sizeof(my_buffor),"%H:%M:%S",time2);
my_file=fopen("my_site.html","w");
fprintf(my_file,my_page,my_buffor);
fflush(my_file);
fclose(my_file);
return 0;
}
Subskrybuj:
Posty (Atom)