#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
bool is_Minus()
{
int value;
value=rand()%2;
if(value==1)
return true;
else
return false;
}
int plus_Minus(int value)
{
if(is_Minus())
{
value=value*-1;
}
return value;
}
int sum_Q1(int a, int b)
{
int sum;
sum=(a*a)+(2*a*b)+(b*b);
return sum;
}
int minus_Q1(int a, int b)
{
int minus;
minus=(a-b)*(a+b);
return minus;
}
int sum_Q2(int a, int b)
{
int sum;
sum=(a*a)-(2*a*b)+(b*b);
return sum;
}
int minus_Q3(int a, int b)
{
int minus;
minus=(a-b)*((a*a)+(a*b)+(b*b));
return minus;
}
int sum_Q3(int a, int b)
{
int sum;
sum=(a+b)*((a*a)-(a*b)+(b*b));
return sum;
}
int sum_Q3_2(int a, int b)
{
int sum;
sum=(a*a*a)+(3*(a*a)*b)+(3*a*(b*b))+(b*b*b);
return sum;
}
int minus_Q3_2(int a, int b)
{
int minus;
minus=(a*a*a)-(3*(a*a)*b)+(3*a*(b*b))-(b*b*b);
return minus;
}
int *results,*a_v,*b_v;
int main(int argc, char **argv)
{
srand(time(NULL));
int i;
results=new int[7];
a_v=new int[7];
b_v=new int[7];
for(i=0;i<7;i++)
{
a_v[i]=plus_Minus(rand()%20+1);
b_v[i]=plus_Minus(rand()%20+1);
}
results[0]=sum_Q1(a_v[0],b_v[0]);
results[1]=minus_Q1(a_v[1],b_v[1]);
results[2]=sum_Q2(a_v[2],b_v[2]);
results[3]=minus_Q3(a_v[3],b_v[3]);
results[4]=sum_Q3(a_v[4],b_v[4]);
results[5]=sum_Q3_2(a_v[5],b_v[5]);
results[6]=minus_Q3_2(a_v[6],b_v[6]);
for(i=0;i<7;i++)
{
cout<<a_v[i]<<" "<<b_v[i]<<" = "<<results[i]<<endl;
}
delete b_v;
delete a_v;
delete results;
return 0;
}
wtorek, 19 listopada 2019
poniedziałek, 11 listopada 2019
Text function and different types (C/C++ Builder)
UnicodeString __fastcall TForm1::first_and_Last(UnicodeString text_Ex)
{
wchar_t* date_Text=text_Ex.w_str();
int size_Text=wcslen(date_Text);
int size_Result=size_Text-2;
int i;
wchar_t* new_Text=new wchar_t[size_Result];
for(i=0;i<size_Result;i++)
new_Text[i]=date_Text[i+1];
return (UnicodeString) new_Text;
}
AnsiString __fastcall TForm1::first_and_Last2(AnsiString text_Ex)
{
char* date_Text=text_Ex.c_str();
int size_Text=strlen(date_Text);
int size_Result=size_Text-2;
int i;
char* new_Text=new char[size_Result];
for(i=0;i<size_Result;i++)
new_Text[i]=date_Text[i+1];
return (AnsiString) new_Text;
}
String __fastcall TForm1::first_and_Last3(String text_Ex)
{
char* date_Text;
sprintf(date_Text,"%s",text_Ex.c_str());
int size_Text=strlen(date_Text);
int size_Result=size_Text-2;
int i;
char* new_Text=new char[size_Result];
for(i=0;i<size_Result;i++)
new_Text[i]=date_Text[i+1];
return (String) new_Text;
}
string first_and_Last4(string text_Ex)
{
const char* date_Text=text_Ex.c_str();
int size_Text=strlen(date_Text);
int size_Result=size_Text-2;
int i;
char* new_Text=new char[size_Result];
for(i=0;i<size_Result;i++)
new_Text[i]=date_Text[i+1];
return (string) new_Text;
}
char* first_and_Last5(char* text_Ex)
{
const char* date_Text=text_Ex;
int size_Text=strlen(date_Text);
int size_Result=size_Text-2;
int i;
char* new_Text=new char[size_Result];
for(i=0;i<size_Result;i++)
new_Text[i]=date_Text[i+1];
return new_Text;
}
{
wchar_t* date_Text=text_Ex.w_str();
int size_Text=wcslen(date_Text);
int size_Result=size_Text-2;
int i;
wchar_t* new_Text=new wchar_t[size_Result];
for(i=0;i<size_Result;i++)
new_Text[i]=date_Text[i+1];
return (UnicodeString) new_Text;
}
AnsiString __fastcall TForm1::first_and_Last2(AnsiString text_Ex)
{
char* date_Text=text_Ex.c_str();
int size_Text=strlen(date_Text);
int size_Result=size_Text-2;
int i;
char* new_Text=new char[size_Result];
for(i=0;i<size_Result;i++)
new_Text[i]=date_Text[i+1];
return (AnsiString) new_Text;
}
String __fastcall TForm1::first_and_Last3(String text_Ex)
{
char* date_Text;
sprintf(date_Text,"%s",text_Ex.c_str());
int size_Text=strlen(date_Text);
int size_Result=size_Text-2;
int i;
char* new_Text=new char[size_Result];
for(i=0;i<size_Result;i++)
new_Text[i]=date_Text[i+1];
return (String) new_Text;
}
string first_and_Last4(string text_Ex)
{
const char* date_Text=text_Ex.c_str();
int size_Text=strlen(date_Text);
int size_Result=size_Text-2;
int i;
char* new_Text=new char[size_Result];
for(i=0;i<size_Result;i++)
new_Text[i]=date_Text[i+1];
return (string) new_Text;
}
char* first_and_Last5(char* text_Ex)
{
const char* date_Text=text_Ex;
int size_Text=strlen(date_Text);
int size_Result=size_Text-2;
int i;
char* new_Text=new char[size_Result];
for(i=0;i<size_Result;i++)
new_Text[i]=date_Text[i+1];
return new_Text;
}
sobota, 9 listopada 2019
Example files and array (g++)
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int *date_Tab;
int *date_Temp;
int *sum_Array;
int double_Tab[50][20];
FILE *tab_Result,*sum_Result;
bool is_First(int value)
{
int i,sum;
sum=0;
for(i=1;i<value+1;i++)
{
if(value%i==0)
++sum;
}
if(sum==2)
return true;
else
return false;
}
int sum_Tab(int *tab, int tab_Size)
{
int i,sum;
sum=0;
for(i=0;i<tab_Size;i++)
sum+=tab_Size;
return sum;
}
void sort_Tab(int *tab, int tab_Size)
{
int i,j,k;
for(i=1;i<tab_Size;i++)
{
j=i;
k=tab[j];
while((j>0) && (tab[j-1]>k))
{
tab[j]=tab[j-1];
j--;
}
tab[j]=k;
}
}
int main(int argc, char **argv)
{
int i,j,k;
date_Tab=new int[1000];
date_Temp=new int[1000];
sum_Array=new int[50];
srand(time(NULL));
i=0;
j=2;
do
{
if(is_First(j))
{
date_Tab[i]=j;
date_Temp[i]=0;
++i;
}
++j;
}while(i<1000);
i=0;
do
{
j=0;
do
{
do
{
k=rand()%1000;
}while(date_Temp[k]!=0);
date_Temp[k]=1;
double_Tab[i][j]=date_Tab[k];
++j;
}while(j<20);
++i;
}while(i<50);
for(i=0;i<50;i++)
{
sort_Tab(double_Tab[i],20);
sum_Array[i]=sum_Tab(double_Tab[i],20);
}
tab_Result=fopen("table_First.txt","wt");
for(i=0;i<50;i++)
{
for(j=0;j<20;j++)
{
fprintf(tab_Result,"%d ",double_Tab[i][j]);
}
fprintf(tab_Result,"\n");
}
fclose(tab_Result);
sum_Result=fopen("table_Sum.txt","wt");
for(i=0;i<50;i++)
{
fprintf(sum_Result,"%d \n",sum_Array[i]);
}
fclose(sum_Result);
delete sum_Array;
delete date_Tab;
delete date_Temp;
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int *date_Tab;
int *date_Temp;
int *sum_Array;
int double_Tab[50][20];
FILE *tab_Result,*sum_Result;
bool is_First(int value)
{
int i,sum;
sum=0;
for(i=1;i<value+1;i++)
{
if(value%i==0)
++sum;
}
if(sum==2)
return true;
else
return false;
}
int sum_Tab(int *tab, int tab_Size)
{
int i,sum;
sum=0;
for(i=0;i<tab_Size;i++)
sum+=tab_Size;
return sum;
}
void sort_Tab(int *tab, int tab_Size)
{
int i,j,k;
for(i=1;i<tab_Size;i++)
{
j=i;
k=tab[j];
while((j>0) && (tab[j-1]>k))
{
tab[j]=tab[j-1];
j--;
}
tab[j]=k;
}
}
int main(int argc, char **argv)
{
int i,j,k;
date_Tab=new int[1000];
date_Temp=new int[1000];
sum_Array=new int[50];
srand(time(NULL));
i=0;
j=2;
do
{
if(is_First(j))
{
date_Tab[i]=j;
date_Temp[i]=0;
++i;
}
++j;
}while(i<1000);
i=0;
do
{
j=0;
do
{
do
{
k=rand()%1000;
}while(date_Temp[k]!=0);
date_Temp[k]=1;
double_Tab[i][j]=date_Tab[k];
++j;
}while(j<20);
++i;
}while(i<50);
for(i=0;i<50;i++)
{
sort_Tab(double_Tab[i],20);
sum_Array[i]=sum_Tab(double_Tab[i],20);
}
tab_Result=fopen("table_First.txt","wt");
for(i=0;i<50;i++)
{
for(j=0;j<20;j++)
{
fprintf(tab_Result,"%d ",double_Tab[i][j]);
}
fprintf(tab_Result,"\n");
}
fclose(tab_Result);
sum_Result=fopen("table_Sum.txt","wt");
for(i=0;i<50;i++)
{
fprintf(sum_Result,"%d \n",sum_Array[i]);
}
fclose(sum_Result);
delete sum_Array;
delete date_Tab;
delete date_Temp;
return 0;
}
Subskrybuj:
Posty (Atom)