Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Ivanyuk_Zvit.docx
Скачиваний:
9
Добавлен:
12.05.2015
Размер:
1.59 Mб
Скачать

Практична робота 4 Програма для роботи з візуальними компонентами керування

Завдання 4.1

За допомогою 2-х контейнерів Panel поділіть простір форми на дві частини (головна та нижня) з прив’язкою до її границь. На головній частині розмістіть кнопку Button. На нижній частині розмістіть компонент TrackBar. При зміні позиції «повзунка» TrackBar реалізуйте можливість зміни прозорості форми. При наведенні миші на кнопку Button реалізуйте можливість зміни її положення відносно форми з неможливістю виходу за межі форми.

//---------------------------------------------------------------------------

#include <vcl.h>

#pragma hdrstop

#include "Unit1.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

#pragma resource "*.dfm"

TForm1 *Form1;

//---------------------------------------------------------------------------

__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

}

//---------------------------------------------------------------------------

void __fastcall TForm1::TrackBar1Change(TObject *Sender)

{

Form1 -> AlphaBlendValue = TrackBar1 -> Position;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button1MouseMove(TObject *Sender,

TShiftState Shift, int X, int Y)

{

int x,y;

x= Panel1 ->Height -Button1 -> Height;

y= Panel1 ->Width -Button1 ->Width;

Button1 -> Top = rand()%x;

Button1 -> Left = rand()%y;

}

//---------------------------------------------------------------------------

Практична робота 5 Програми циклічної структури

Завдання 5.1

Побудувати таблицю відповідностей між мірами. Початкове значення міри, крок зміни цього значення та кількість рядків у таблиці задати з клавіатури. 1 фут = 0,3048 м = 12 дюймів.

#include "stdafx.h"

#include <iostream>

#include <math.h>

#include <conio.h>

#include <stdlib.h>

using namespace std;

void _tmain(int argc, _TCHAR* argv[])

{

float shag;

int n;

float fut, metr, duym;

cout << "Nachalnoe znachenie =";

cin >> fut;

cout << "Shag=";

cin >> shag;

cout << "kol-vo=";

cin >> n;

system("cls");

cout.setf(ios::left);

cout.width(40);

cout << "Fut M Duym" << endl;

cout << "__________________________" << endl;

for (int i = 0; i < n; i++)

{

metr = fut * 0.3048;

duym = fut * 12;

cout << fut << " " << metr << " " << duym << endl;

fut = fut + shag;

}

cout << "___________________________" << endl;

system("PAUSE");

}

Завдання 5.2

Дано два цілі числа А і В(А < B). Знайти суму квадратів чисел від А до В включно.

#include "stdafx.h"

#include "stdafx.h"

#include <iostream>

#include <math.h>

#include <conio.h>

#include <stdlib.h>

using namespace std;

void _tmain(int argc, _TCHAR* argv[])

{

int a, b, S;

S = 0;

cout << "A(A<B)=";

cin >> a;

cout << "B(B>A)=";

cin >> b;

if (a < b)

{

for (int i = b; a <= b; a++)

{

S = S + pow(a, 2);

}

cout << "S=" << S << endl;

}

else

cout << "ERROR" << endl;

system("PAUSE");

}

Завдання 5.3

Дано ціле число N>0. Знайти найбільше число K,квадрат якого не перевищує N.

#include "stdafx.h"

#include "stdafx.h"

#include <iostream>

#include <math.h>

#include <conio.h>

#include <stdlib.h>

using namespace std;

void _tmain(int argc, _TCHAR* argv[])

{

int N;

int K;

int K1;

cout << "N=";

cin >> N;

K = 1;

K1 = 1;

for (int i = 1; i < N; i++)

{

K1 = i*i;

if (K1 >= N) { K = i - 1; break; }

}

cout << "K=" << K << endl;

system("PAUSE");

}

Завдання 5.4

Написати програму, яка виводить на екран таблицю Піфагора.

#include "stdafx.h"

#include "stdafx.h"

#include <iostream>

#include <math.h>

#include <conio.h>

#include <stdlib.h>

#include <iomanip>

using namespace std;

void _tmain(int argc, _TCHAR* argv[])

{

cout.width(1);

setfill(" ");

for (int i = 1; i <= 10; i++)

{

for (int j = 1; j <= 10; j++)

{

cout << setprecision(2)<< setw(2)<< i*j<<" ";

}

cout << endl;

}

system("PAUSE");

}

Завдання 5.5

Дано ціле число N>0. Використовуючи операції ділення націло та взяття залишку від ділення, знайти число, отримане при читанні числа N справо на ліво.

#include "stdafx.h"

#include "stdafx.h"

#include <iostream>

#include <math.h>

#include <conio.h>

#include <stdlib.h>

#include <iomanip>

using namespace std;

void _tmain(int argc, _TCHAR* argv[])

{

float x, x1;

cout << "x=";

cin >> x;

x1 = 0;

do

{

x1 = x1 + (fmod(x, 10))/10;

x1 = x1 * 10;

x = floor(x/10);

}

while (x > 0);

cout << "x1=" << x1 << endl;

system("PAUSE");

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]