Skip to content

Instantly share code, notes, and snippets.

@Evshved
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save Evshved/75b778f237d1b889bf3b to your computer and use it in GitHub Desktop.

Select an option

Save Evshved/75b778f237d1b889bf3b to your computer and use it in GitHub Desktop.
Lab #2
//---------------------------------------------------------------------------
Application
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "FunctionsForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#include <math.h>
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Memo1->Clear();
Edit1->Clear();
Edit2->Clear();
Edit3->Clear();
RadioGroup1->ItemIndex = 0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
double a,b,x,z,y,func,subexp1,subexp2,subexp3,subexp4,subexp5,res;
int count;
if (TryStrToFloat(Edit1->Text,a) && TryStrToFloat(Edit2->Text,b) && TryStrToFloat(Edit3->Text,z) )
{
if (z>0) {
x=1./(z*z+2*z);
Memo1->Lines->Add("z>0");
}
else {
x=1-pow(z,3);
Memo1->Lines->Add("z<=0");
}
switch(RadioGroup1->ItemIndex){
case 0: func=2*x; Memo1->Lines->Add("2*x"); break;
case 1: func=x*x; Memo1->Lines->Add("x^2"); break;
case 2: func=x/3; Memo1->Lines->Add("x/3"); break;
}
subexp1=2.5*a*exp(-3*x);
subexp2=4*b*x*x;
subexp3=log(x)+func;
y=(subexp1-subexp2)/subexp3;
Memo1->Lines->Add(FloatToStrF(func,ffFixed,8,6));
}
else Memo1->Lines->Add("Error");
}
//---------------------------------------------------------------------------
Console
//---------------------------------------------------------------------------
/---------------------------------------------------------------------------
#include <vcl.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <classes.hpp>
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
double a,b,x,z,y,func,subexp1,subexp2,subexp3,res;
int count,k;
char strx[31] = "",stry[31] = "",strz[31] = "";
do {
printf("Test=1 or Your's variables - any key\n ");
// fflush(stdin);
scanf("%d", &k);
if (k==1) {
x=1;
y=-1;
z=3;
}
else {
do {
puts("Press a, b, z");
scanf("%s %s %s",&strx,&stry,&strz);
} while ( ! (TryStrToFloat(strx,a) && TryStrToFloat(stry,b) && TryStrToFloat(strz,z)) );
// printf("Error");
}
if (z>0) {
x=1./(z*z+2*z);
puts("\nz>0");
}
else {
x=1-pow(z,3);
puts("\nz<=0");
}
do {
puts("\nUse function - 2*x - 0");
puts("Use function - x^2 - 1");
puts("Use function - x/3 - 2\n");
fflush(stdin);
} while ( scanf("%d",&count) != 1 || count <0 || count > 2);
switch(count){
case 0: func=2*x; puts("\nUse function - 2*x"); break;
case 1: func=x*x; puts("\nUse function - x^2"); break;
case 2: func=x/3; puts("\nUse function - x/3"); break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment