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

Практична робота 2 Програми розгалуженої структури

Завдання 2.1

Дано три змінні дійсного типу. Якщо їх значення впорядковані за зростанням чи спаданням, то подвоїти їх; інакше – замінити значення кожної змінної на протилежне. Вивести значення змінних.

#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[])

{

float x1, x2, x3, z1, z2, z3;

cout << "x1=";

cin >> x1;

cout << "x2=";

cin >> x2;

cout << "x3=";

cin >> x3;

if (((x1 > x2) && (x1 > x3)) && ((x3 < x2) && (x3 < x1)) || ((x1 < x2) && (x1 < x3)) && ((x3 > x2) && (x3 > x1)))

{

x1 = x1 * 2;

x2 = x2 * 2;

x3 = x3 * 2;

}

else

{

x1 = x1 * -1;

x2 = x2 * -1;

x3 = x3 * -1;

}

cout << x1 << endl;

cout << x2 << endl;

cout << x3 << endl;

system("PAUSE");

}

Завдання 2.2

Дано ціле число K. Вивести рядок-опис оцінки, яка відповідає числу(2 – «незадовільно», 3 – «задовільно», 4 – «добре», 5 – «відмінно»). Якщо K не належить діапазону [1;5], то вивести повідомлення про помилку.

#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 K;

cout << "K=";

cin >> K;

if (K >= 1 && K <= 5)

{

switch (K)

{

case 2:{ cout << "tak se" <<endl; break; }

case 3: {cout << "good" << endl; break; }

case 4:{ cout << "ne ok" <<endl; break; }

case 5:{ cout << "vidminno"<< endl; break; }

default:{ cout << "dnarb" << endl ; break; }

}

}

system("PAUSE");

}

Практична робота 3 Програмна реалізація функцій для роботи з датою та часом

Завдання 3.1

Використовуючи клас ТDateTime (оголошений в модулі sysdate.h) розробіть застосування для робот з датою і часом, яке демонструватиме всі можливі операції над ними.

#include <vcl.h>

#pragma hdrstop

#include "Unit1.h"

#include <systdate.h>

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

#pragma package(smart_init)

#pragma resource "*.dfm"

TForm1 *Form1;

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

__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

AnsiString TimeFormat;

AnsiString DateFormat;

DateFormat = "dd.mm.yy";

TimeFormat = "hh:nn";

}

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

void __fastcall TForm1::Button1Click(TObject *Sender)

{

AnsiString TimeFormat;

AnsiString DateFormat;

if (CheckBox2->Checked) TimeFormat = "hh:nn:ss"; else TimeFormat="hh:nn am/pm";

if (CheckBox1->Checked) DateFormat = "dddddd"; else DateFormat="dd.mmmm.yy";

TDateTime DateTime = TDateTime::CurrentDateTime();

Label2->Caption = DateTime.DateTimeString();

Label3->Caption = DateTime.DateString();

Label4->Caption = DateTime.TimeString();

Label6->Caption = DateTime.CurrentDateTime().FormatString(DateFormat + " " + TimeFormat);

int dayOFweek = DateTime.DayOfWeek();

switch (dayOFweek)

{

case 1: {Label1->Caption = "сейчас воскресенье, " + AnsiString(DateTime);break;}

case 2: {Label1->Caption = "сейчас понедельник, " + AnsiString(DateTime);break;}

case 3: {Label1->Caption = "сейчас вторник, " + AnsiString(DateTime);break;}

case 4: {Label1->Caption = "сейчас среда, " + AnsiString(DateTime);break;}

case 5: {Label1->Caption = "сейчас четверг, " + AnsiString(DateTime);break;}

case 6: {Label1->Caption = "сейчас пятница, " + AnsiString(DateTime);break;}

case 7: {Label1->Caption = "сейчас суббота, " + AnsiString(DateTime);break;}

}

DateTime = TDateTime::FileDateToDateTime(FileAge(Application->ExeName));

Label5->Caption = "дата и время файла: " + DateTime.DateTimeString();

}

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

void __fastcall TForm1::Button2Click(TObject *Sender)

{

Application->Terminate();

}

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

void __fastcall TForm1::Button4Click(TObject *Sender)

{

static TDateTime DateTime=TDateTime::CurrentDateTime();

Label8->Caption=(DateTime++).DateTimeString();

}

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

void __fastcall TForm1::Button3Click(TObject *Sender)

{

static TDateTime StartDateTime=TDateTime::CurrentDateTime();

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

{

TDateTime(TDateTime::CurrentDateTime().DateTimeString());

TDateTime EndDateTime=TDateTime::CurrentDateTime();

Label7->Caption=(EndDateTime - StartDateTime).TimeString();

}

}

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

void __fastcall TForm1::Button5Click(TObject *Sender)

{

static TDateTime DateTime = TDateTime::CurrentDateTime();

Label9->Caption =(DateTime += 1.125).DateTimeString();

}

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