Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

И-12б(8) / 12 / Unit1

.cpp
Скачиваний:
0
Добавлен:
02.02.2015
Размер:
2.11 Кб
Скачать
//---------------------------------------------------------------------------

#include <vcl.h>
#include <math.h>
#include <stdio.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
const mlen= 255;
void printa(int* a, int n)
{
for(int i=0;i<n; i++)
Form1->Memo1->Lines->Add(a[i]);
}
int* reada(char* fn, int &n)
{
char buf[mlen];
FILE* f =fopen(fn,"r");
if (f==NULL)
{
ShowMessage("file not open");
return NULL;
}
fgets(buf,mlen,f);
n = atoi(buf);
int *res = new int[n];
for (int i=0; i<n;i++)
{
fgets(buf,mlen,f);
res[i]= atoi(buf);
}
fclose(f);
return res;
}

void wresult(char* fn, int max)
{
FILE* f = fopen(fn,"w+");
char cmax[mlen] = "Result = ";
char cmaxv[mlen];
itoa (max, cmaxv,10);
strcat(cmax,cmaxv);
fputs(cmax,f);
fputs("\n",f);
fclose(f);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
Form1->Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
int max;
int sum=0;
int sum1=0;
int n=0;
int* a= reada("1.txt", n);
if (a==NULL)
return;
printa(a,n);
if( CheckBox1->Checked)
{
max = a[0];
for (int i=0; i<n; i++)
{
if (fabs(a[i])>fabs(max))
max = a[i];
}
wresult("2.txt",max);
Label1->Caption = "max = "+ IntToStr(max);
}
if( CheckBox2->Checked)
{
for (int i=0; i<n; i++)
{
if (a[i]<0)
{
 sum +=a[i];
}
}
wresult("2.txt",sum);
Label1->Caption = " sum = "+ IntToStr(sum);
}
if( CheckBox3->Checked)
{
for (int i=0; i<n; i++)
{
 sum1 +=pow(a[i],2);
}
wresult("2.txt",sum1);
Label1->Caption = " sum sqr = "+ IntToStr(sum1);
}

delete[]a;


}
//---------------------------------------------------------------------------
Соседние файлы в папке 12
  • #
    02.02.20152.55 Кб1Project1.bpr
  • #
    02.02.2015710 б0Project1.cpp
  • #
    02.02.201515.66 Кб0Project1.obj
  • #
    02.02.2015876 б0Project1.res
  • #
    02.02.20151.77 Mб1Project1.tds
  • #
    02.02.20152.11 Кб0Unit1.cpp
  • #
    02.02.20151.32 Кб0Unit1.dfm
  • #
    02.02.20151.06 Кб0Unit1.h
  • #
    02.02.201546.92 Кб1Unit1.obj
  • #
    02.02.20152.11 Кб1Unit1.~cpp
  • #
    02.02.20151.32 Кб0Unit1.~dfm