niedziela, 23 sierpnia 2020

Calculations in structures

 #include <iostream>

#include <conio.h>

#include <stdlib.h>

#include <time.h>


#define max_Size 1000

#define rand_Size 100

using namespace std;


struct int_Point

{

    int x;

    int y;

    int z;

};

struct float_Point

{

    float x;

    float y;

    float z;

};

bool min_Sort(int a, int b, int c)

{

    if((a<b) && (b<c))

        return true;

    else

        return false;

}

int main()

{

    int a,b,c,i;

    float a1,b1,c1;

    float a2,b2,c2;

    int a3,b3,c3;

    srand(time(NULL));

    int_Point *i_P;

    float_Point *f_P;

    float_Point *g_P;

    int_Point *h_P;

    i_P=new struct int_Point[max_Size];

    f_P=new struct float_Point[max_Size];

    g_P=new struct float_Point[max_Size];

    h_P=new struct int_Point[max_Size];

    for(i=0;i<max_Size;i++)

    {

     a=1+rand()%rand_Size; a1=(a*1.00)/100.;a2=1.00-a1;a3=int(a2*100.);

     b=1+rand()%rand_Size; b1=(b*1.00)/100.;b2=1.00-b1;b3=int(b2*100.);

     c=1+rand()%rand_Size; c1=(c*1.00)/100.;c2=1.00-c1;c3=int(c2*100.);

     i_P[i].x=a; f_P[i].x=a1; g_P[i].x=a2; h_P[i].x=a3;

     i_P[i].y=b; f_P[i].y=b1; g_P[i].y=b2; h_P[i].y=b3;

     i_P[i].z=c; f_P[i].z=c1; g_P[i].z=c2; h_P[i].z=c3;

     if(min_Sort(a,b,c))

     {

         float *sum;

         sum=new float[3];

         sum[0]=(1.00*i_P[i].x)+f_P[i].x+g_P[i].x+(1.00*h_P[i].x);

         sum[1]=(1.00*i_P[i].y)+f_P[i].y+g_P[i].y+(1.00*h_P[i].y);

         sum[2]=(1.00*i_P[i].z)+f_P[i].z+g_P[i].z+(1.00*h_P[i].z);

         float all_s=sum[0]+sum[1]+sum[3];

         cout<<i_P[i].x<<"+"<<f_P[i].x<<"+"<<g_P[i].x<<"+"<<h_P[i].x<<"="<<sum[0]<<endl;

         cout<<i_P[i].y<<"+"<<f_P[i].y<<"+"<<g_P[i].y<<"+"<<h_P[i].y<<"="<<sum[1]<<endl;

         cout<<i_P[i].z<<"+"<<f_P[i].z<<"+"<<g_P[i].z<<"+"<<h_P[i].z<<"="<<sum[2]<<endl;

         cout<<"All = "<<all_s<<endl;

         delete [] sum;

     }

    }

    delete [] i_P;

    delete [] f_P;

    delete [] g_P;

    delete [] h_P;

    getch();

    return 0;

}


YOU CAN PAY ME - https://paypal.me/LukaszW77?locale.x=pl_PL


sobota, 22 sierpnia 2020

Copying files /proc

#include <iostream>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/sendfile.h>

using namespace std;

class COPY_SENDF
{
    private:
    int file_begin;
    int file_end;
    string name_begin;
    string name_end;
    struct stat str_stat;
    off_t temp_off;
    public:
   
    void read(string name1, string name2)
    {
        name_begin=name1;
        name_end=name2;
    }
    void s_Copy()
    {
        file_begin=open(name_begin.c_str(),O_RDONLY);
        fstat(file_begin,&str_stat);
        file_end=open(name_end.c_str(),O_WRONLY | O_CREAT,str_stat.st_mode);
        sendfile(file_end,file_begin,&temp_off,str_stat.st_size);
        close(file_begin);
        close(file_end);
    }
};

string write_proc(string name)
{
    string result;
    result="/proc/"+name;
    return result;
}

int main(int argc, char **argv)
{
    string info="/home/PROC_DATES";
    string files_proc[8]={"filesystems","version","meminfo","modules","iomen",
        "partitions","swap","cpuinfo"};
    COPY_SENDF *c_Send=new class COPY_SENDF[8];
    for(int i=0;i<8;i++)
    {
        c_Send[i].read(write_proc(files_proc[i]),info);
        c_Send[i].s_Copy();
    }
    delete [] c_Send;
    return 0;
}


YOU CAN PAY ME - https://paypal.me/LukaszW77?locale.x=pl_PL