Archived
Работы по программированию
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"cstdlib": "c",
|
||||
"math.h": "c",
|
||||
"ostream": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"iterator": "cpp",
|
||||
"xmemory": "cpp",
|
||||
"xutility": "cpp"
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"tasks": [
|
||||
{
|
||||
"type": "cppbuild",
|
||||
"label": "C/C++: gcc.exe build active file",
|
||||
"command": "D:\\mingw\\MinGW\\bin\\gcc.exe",
|
||||
"args": [
|
||||
"-fdiagnostics-color=always",
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"${fileDirname}\\${fileBasenameNoExtension}.exe"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${fileDirname}"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"detail": "Task generated by Debugger."
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
}
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
1.Даны целочисленные переменные А и В. Найти их сумму и вывести на экран.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int getSum(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
int main() {
|
||||
const int A = 3;
|
||||
const int B = 8;
|
||||
|
||||
printf("Sum: %d", getSum(A, B));
|
||||
return 0;
|
||||
}
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
10.Создать целочисленный массив A[5][5]. При помощи цикла и оператора условия задать его значения, как показано ниже:
|
||||
1 2 3 4 5
|
||||
2 3 4 5 4
|
||||
3 4 5 4 3
|
||||
4 5 4 3 2
|
||||
5 4 3 2 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define N 5
|
||||
|
||||
|
||||
void setArray(int (*array)[N]) {
|
||||
for (int i = 0; i < N; i++) {
|
||||
for (int j = 0; j < N; j++) {
|
||||
array[i][j] = (i + j) < (N-1) ? i + j + 1 : (N*2 - 1) - (i+j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void printArray(int (*array)[N] ) {
|
||||
for (int i = 0; i < N; i++) {
|
||||
for (int j = 0; j < N; j++) {
|
||||
printf("%d ", array[i][j]);
|
||||
}
|
||||
puts("");
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int A[N][N];
|
||||
|
||||
setArray(A);
|
||||
printArray(A);
|
||||
return 0;
|
||||
}
|
||||
Executable
+69
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
11.На поле 10х10 клеток установить 10 однопалубных кораблей. Корабли не соприкасаются.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#define N 10
|
||||
#define AMOUNT 10
|
||||
|
||||
const char SHIP = '#';
|
||||
const char VOID = '.';
|
||||
|
||||
char matrix[N][N];
|
||||
|
||||
void fillMatrix() {
|
||||
for (int i=0;i<N;i++) {
|
||||
for (int j=0;j<N;j++) {
|
||||
matrix[i][j] = VOID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void printMatrix() {
|
||||
for (int i=0;i<N;i++) {
|
||||
for (int j=0;j<N;j++) {
|
||||
printf("%2c", matrix[i][j]);
|
||||
}
|
||||
puts("");
|
||||
}
|
||||
}
|
||||
|
||||
bool isCanPlace(int x, int y) {
|
||||
for (int i = -1; i <= 1; i++) {
|
||||
for (int j = -1; j <= 1;j++) {
|
||||
if (matrix[abs(x-i)][abs(y-j)] == SHIP)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void setShips() {
|
||||
for (int i = 0; i < AMOUNT; i++) {
|
||||
int x = rand() % N;
|
||||
int y = rand() % N;
|
||||
|
||||
if (isCanPlace(x, y)) {
|
||||
matrix[x][y] = SHIP;
|
||||
} else {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
srand(time(0));
|
||||
|
||||
fillMatrix();
|
||||
setShips();
|
||||
|
||||
printMatrix();
|
||||
return 0;
|
||||
}
|
||||
Executable
+74
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
12.На поле 10х10 клеток установить 5 двухпалубных кораблей. Корабли не соприкасаются.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#define N 10
|
||||
#define AMOUNT 5
|
||||
|
||||
const char SHIP = '#';
|
||||
const char VOID = '.';
|
||||
|
||||
char matrix[N][N];
|
||||
|
||||
void fillMatrix() {
|
||||
for (int i=0;i<N;i++) {
|
||||
for (int j=0;j<N;j++) {
|
||||
matrix[i][j] = VOID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void printMatrix() {
|
||||
for (int i=0;i<N;i++) {
|
||||
for (int j=0;j<N;j++) {
|
||||
printf("%2c", matrix[i][j]);
|
||||
}
|
||||
puts("");
|
||||
}
|
||||
}
|
||||
|
||||
bool isCanPlace(int x, int y) {
|
||||
for (int i = -2; i <= 2; i++) {
|
||||
for (int j = -2; j <= 2;j++) {
|
||||
if (matrix[abs(x-i)][abs(y-j)] == SHIP)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void setShips() {
|
||||
for (int i = 0; i < AMOUNT; i++) {
|
||||
int x = rand() % (N - 1);
|
||||
int y = rand() % (N - 1);
|
||||
|
||||
if (isCanPlace(x, y)) {
|
||||
matrix[x][y] = SHIP;
|
||||
if (rand() % 2 == 0) {
|
||||
matrix[x+1][y] = SHIP;
|
||||
} else {
|
||||
matrix[x][y+1] = SHIP;
|
||||
}
|
||||
} else {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
srand(time(0));
|
||||
|
||||
fillMatrix();
|
||||
setShips();
|
||||
|
||||
printMatrix();
|
||||
return 0;
|
||||
}
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
13.Написать программу, которая шифрует и дешифрует сообщение Шифром Цезаря.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define OFFSET 13
|
||||
|
||||
|
||||
char* encrypt(char* string) {
|
||||
char *result = string;
|
||||
|
||||
for (int i =0; i < strlen(string);i++) {
|
||||
char c = string[i];
|
||||
if (c >= 'A' && c <= 'Z') {
|
||||
c = c + (OFFSET % 26);
|
||||
if (c > 'Z') c = 'A' + (c - 'Z') - 1;
|
||||
}
|
||||
if (c >= 'a' && c <= 'z') {
|
||||
c = c + (OFFSET % 26);
|
||||
if (c > 'z') c= 'a' + (c - 'z') - 1;
|
||||
}
|
||||
result[i] = c;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
char* decrypt(char* string) {
|
||||
char *result = string;
|
||||
|
||||
for (int i =0; i < strlen(string);i++) {
|
||||
char c = string[i];
|
||||
if (c >= 'A' && c <= 'Z') {
|
||||
c = c - (OFFSET % 26);
|
||||
if (c < 'A') c = 'Z' - ('A' - c) + 1;
|
||||
}
|
||||
if (c >= 'a' && c <= 'z') {
|
||||
c = c - (OFFSET % 26);
|
||||
if (c < 'a') c= 'z' - ('a' - c) + 1;
|
||||
}
|
||||
result[i] = c;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char string[32];
|
||||
scanf("%s", string);
|
||||
|
||||
char *enc = encrypt(string);
|
||||
printf("%s\n", enc);
|
||||
|
||||
printf("%s", decrypt(enc));
|
||||
return 0;
|
||||
}
|
||||
Executable
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
15.Вычислить сумму двух обыкновенных дробей. Ответ дать в виде обыкновенной и в виде десятичной дробей. Числители и знаменатели относятся к целому типу данных.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
typedef struct Fraction {
|
||||
int up;
|
||||
int down;
|
||||
} fraction;
|
||||
|
||||
int GCD(int a, int b) {
|
||||
int result = (a < b) ? a : b;
|
||||
while (result > 0)
|
||||
{
|
||||
if (a % result == 0 && b % result == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
result--;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int LCM(int a, int b) {
|
||||
return a / GCD(a, b) * b;
|
||||
}
|
||||
|
||||
void printSumFraction(fraction fraction_1, fraction fraction_2) {
|
||||
int a = fraction_1.up;
|
||||
int b = fraction_1.down;
|
||||
|
||||
int c = fraction_2.up;
|
||||
int d = fraction_2.down;
|
||||
|
||||
/*
|
||||
a c
|
||||
- + -
|
||||
b d
|
||||
*/
|
||||
|
||||
int lcm = LCM(b, d);
|
||||
|
||||
int answer_up = a * (lcm / b) + c * (lcm / d);
|
||||
printf("%2d %2d %2d * %2d + %2d %2d\n", a, c, a, lcm / b, c*lcm / d, a * (lcm / b) + c * (lcm / d));
|
||||
printf("-- + -- = ------------ = -- = %.3lf\n", (double)answer_up/lcm);
|
||||
printf("%2d %2d %2d %2d\n", b, d, lcm, lcm);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
fraction first;
|
||||
fraction second;
|
||||
printf("Enter a b c and d: ");
|
||||
|
||||
scanf("%d %d %d %d", &first.up, &first.down, &second.up, &second.down);
|
||||
printSumFraction(first, second);
|
||||
return 0;
|
||||
}
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
16.Вычислить разность двух обыкновенных дробей. Ответ дать в виде обыкновенной и в виде десятичной дробей. Числители и знаменатели относятся к целому типу данных.*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
typedef struct Fraction
|
||||
{
|
||||
int up;
|
||||
int down;
|
||||
} fraction;
|
||||
|
||||
int GCD(int a, int b)
|
||||
{
|
||||
int result = (a < b) ? a : b;
|
||||
while (result > 0)
|
||||
{
|
||||
if (a % result == 0 && b % result == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
result--;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int LCM(int a, int b)
|
||||
{
|
||||
return a / GCD(a, b) * b;
|
||||
}
|
||||
|
||||
void printSumFraction(fraction fraction_1, fraction fraction_2)
|
||||
{
|
||||
int a = fraction_1.up;
|
||||
int b = fraction_1.down;
|
||||
|
||||
int c = fraction_2.up;
|
||||
int d = fraction_2.down;
|
||||
|
||||
/*
|
||||
a c
|
||||
- - -
|
||||
b d
|
||||
*/
|
||||
|
||||
int lcm = LCM(b, d);
|
||||
|
||||
int answer_up = a * (lcm / b) - c * (lcm / d);
|
||||
printf("%2d %2d %2d * %2d - %2d %2d\n", a, c, a, lcm / b, c * lcm / d, a * (lcm / b) - c * (lcm / d));
|
||||
printf("-- - -- = ------------ = -- = %.3lf\n", (double)answer_up / lcm);
|
||||
printf("%2d %2d %2d %2d\n", b, d, lcm, lcm);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
fraction first;
|
||||
fraction second;
|
||||
printf("Enter a b c and d: ");
|
||||
|
||||
scanf("%d %d %d %d", &first.up, &first.down, &second.up, &second.down);
|
||||
printSumFraction(first, second);
|
||||
return 0;
|
||||
}
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
17.Вычислить произведение двух обыкновенных дробей. Ответ дать в виде обыкновенной и в виде десятичной дробей. Числители и знаменатели относятся к целому типу данных.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
typedef struct Fraction
|
||||
{
|
||||
int up;
|
||||
int down;
|
||||
} fraction;
|
||||
|
||||
void printSumFraction(fraction fraction_1, fraction fraction_2)
|
||||
{
|
||||
int a = fraction_1.up;
|
||||
int b = fraction_1.down;
|
||||
|
||||
int c = fraction_2.up;
|
||||
int d = fraction_2.down;
|
||||
|
||||
/*
|
||||
a c
|
||||
- * -
|
||||
b d
|
||||
*/
|
||||
|
||||
printf("%2d %2d %2d * %2d %2d\n", a, c, a, c, a*c);
|
||||
printf("-- * -- = ------------ = -- = %.3lf\n", (double)(a*c)/(b*d));
|
||||
printf("%2d %2d %2d * %2d %2d\n", b, d, b,d, b*d);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
fraction first;
|
||||
fraction second;
|
||||
printf("Enter a b c and d: ");
|
||||
|
||||
scanf("%d %d %d %d", &first.up, &first.down, &second.up, &second.down);
|
||||
printSumFraction(first, second);
|
||||
return 0;
|
||||
}
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
18.Вычислить частное двух обыкновенных дробей. Ответ дать в виде обыкновенной и в виде десятичной дробей. Числители и знаменатели относятся к целому типу данных.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
typedef struct Fraction {
|
||||
int up;
|
||||
int down;
|
||||
} fraction;
|
||||
|
||||
|
||||
void printSumFraction(fraction fraction_1, fraction fraction_2) {
|
||||
int a = fraction_1.up;
|
||||
int b = fraction_1.down;
|
||||
|
||||
int c = fraction_2.up;
|
||||
int d = fraction_2.down;
|
||||
|
||||
/*
|
||||
a c
|
||||
- : -
|
||||
b d
|
||||
*/
|
||||
|
||||
printf("%2d %2d %2d * %2d %2d * %2d %2d\n", a, c, a, d, a, d, a * d);
|
||||
printf("-- : -- = --- --- = ------- = -- = %.3lf\n", (double)(a * d) / (b * c));
|
||||
printf("%2d %2d %2d * %2d %2d * %2d %2d\n", b, d, b, c, b, c, b * c);
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
fraction first;
|
||||
fraction second;
|
||||
printf("Enter a b c and d: ");
|
||||
|
||||
scanf("%d %d %d %d", &first.up, &first.down, &second.up, &second.down);
|
||||
printSumFraction(first, second);
|
||||
return 0;
|
||||
}
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
19.Вычислить определитель матрицы 3x3.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define N 3
|
||||
|
||||
int getDet(int (*matrix)[N]) {
|
||||
return matrix[0][0]*matrix[1][1]*matrix[2][2] + matrix[0][1]*matrix[1][2]*matrix[2][0] + matrix[0][2]*matrix[1][0]*matrix[2][1] - matrix[0][2]*matrix[1][1]*matrix[2][0] - matrix[0][1]*matrix[1][0]*matrix[2][2] - matrix[0][0]*matrix[1][2]*matrix[2][1];
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
int matrix[N][N] = {{6, 3, 0},
|
||||
{4, 1, -3},
|
||||
{-2, -3, 2}
|
||||
};
|
||||
|
||||
printf("Det: %d", getDet(matrix));
|
||||
return 0;
|
||||
}
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
2.Даны целочисленные переменные А и В. Найти их частное, вывести на экран с точностью до двух знаков после запятой.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
double getDivision(double a, double b) {
|
||||
return a/b;
|
||||
}
|
||||
|
||||
int main() {
|
||||
const int A = 10;
|
||||
const int B = 4;
|
||||
|
||||
printf("%.2lf", getDivision(A, B));
|
||||
return 0;
|
||||
}
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
20.Вычислить корни СЛАУ через определители
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define N 3
|
||||
#define M 4
|
||||
|
||||
int getDet(int (*matrix)[N])
|
||||
{
|
||||
return matrix[0][0] * matrix[1][1] * matrix[2][2] + matrix[0][1] * matrix[1][2] * matrix[2][0] + matrix[0][2] * matrix[1][0] * matrix[2][1] - matrix[0][2] * matrix[1][1] * matrix[2][0] - matrix[0][1] * matrix[1][0] * matrix[2][2] - matrix[0][0] * matrix[1][2] * matrix[2][1];
|
||||
}
|
||||
|
||||
void setMatrixNew(int (*matrix_new)[N], int (*matrix)[M])
|
||||
{
|
||||
for (int x = 0; x < N; x++)
|
||||
{
|
||||
for (int y = 0; y < N; y++)
|
||||
{
|
||||
matrix_new[x][y] = matrix[x][y];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int getSolve(int (*matrix)[M])
|
||||
{
|
||||
int matrix_new[N][N];
|
||||
|
||||
setMatrixNew(matrix_new, matrix);
|
||||
|
||||
int X = getDet(matrix_new);
|
||||
if (X == 0) {
|
||||
puts("KOD KRASBYI!!");
|
||||
return;
|
||||
}
|
||||
|
||||
int x_array[N];
|
||||
for (int i = N - 1; i >= 0; i--)
|
||||
{
|
||||
setMatrixNew(matrix_new, matrix);
|
||||
|
||||
matrix_new[0][i] = matrix[0][M - 1];
|
||||
matrix_new[1][i] = matrix[1][M - 1];
|
||||
matrix_new[2][i] = matrix[2][M - 1];
|
||||
|
||||
x_array[i] = getDet(matrix_new);
|
||||
printf("%d\n", getDet(matrix_new));
|
||||
}
|
||||
|
||||
char current = 'x';
|
||||
for (int i = 0; i < N;i++) {
|
||||
printf("%c = %.2lf\n", current++, (double)x_array[i]/X);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int matrix[N][M] = {{1, 2, 3, 3},
|
||||
{3, 2, 2, 3},
|
||||
{3, 3, 3, 3}};
|
||||
getSolve(matrix);
|
||||
return 0;
|
||||
}
|
||||
Executable
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
21.Выполнить сортировку одномерного массива A[25] методом пузырька.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define N 25
|
||||
|
||||
void initArray(int *array, const int MAX)
|
||||
{
|
||||
srand(time(0));
|
||||
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
array[i] = rand() % MAX + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void _swap(int *x, int *y)
|
||||
{
|
||||
int temp = *x;
|
||||
*x = *y;
|
||||
*y = temp;
|
||||
}
|
||||
|
||||
void sortArrayBubble(int *array)
|
||||
{
|
||||
int i, j;
|
||||
bool is_swap;
|
||||
for (i = 0; i < N - 1; i++)
|
||||
{
|
||||
is_swap = false;
|
||||
for (j = 0; j < N - i - 1; j++)
|
||||
{
|
||||
if (array[j] > array[j + 1])
|
||||
{
|
||||
_swap(&array[j], &array[j + 1]);
|
||||
is_swap = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_swap == false)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void printArray(int *array)
|
||||
{
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
printf("%d ", array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int A[N];
|
||||
|
||||
initArray(A, 10);
|
||||
sortArrayBubble(A);
|
||||
printArray(A);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
22.Выполнить сортировку одномерного массива A[25] методом быстрой сортировки.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define N 25
|
||||
|
||||
void initArray(int *array, const int MAX)
|
||||
{
|
||||
srand(time(0));
|
||||
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
array[i] = rand() % MAX + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void sortArrayQuick(int *array, int size)
|
||||
{
|
||||
int i = 0;
|
||||
int j = size - 1;
|
||||
|
||||
int middle = array[size / 2];
|
||||
|
||||
do
|
||||
{
|
||||
while (array[i] < middle)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
while (array[j] > middle)
|
||||
{
|
||||
j--;
|
||||
}
|
||||
|
||||
if (i <= j)
|
||||
{
|
||||
int tmp = array[i];
|
||||
array[i] = array[j];
|
||||
array[j] = tmp;
|
||||
|
||||
i++;
|
||||
j--;
|
||||
}
|
||||
} while (i <= j);
|
||||
|
||||
if (j > 0)
|
||||
{
|
||||
sortArrayQuick(array, j + 1);
|
||||
}
|
||||
if (i < size)
|
||||
{
|
||||
sortArrayQuick(&array[i], size - i);
|
||||
}
|
||||
}
|
||||
|
||||
void printArray(int *array)
|
||||
{
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
printf("%d ", array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int A[N];
|
||||
|
||||
initArray(A, 10);
|
||||
sortArrayQuick(A, N);
|
||||
printArray(A);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
23.Выполнить сортировку одномерного массива A[25] методом сортировки вставкой.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define N 25
|
||||
|
||||
void initArray(int *array, const int MAX)
|
||||
{
|
||||
srand(time(0));
|
||||
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
array[i] = rand() % MAX + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void _swap(int *x, int *y)
|
||||
{
|
||||
int temp = *x;
|
||||
*x = *y;
|
||||
*y = temp;
|
||||
}
|
||||
|
||||
void sortArrayInsertion(int *array)
|
||||
{
|
||||
int i, key, j;
|
||||
for (i = 1; i < N; i++)
|
||||
{
|
||||
key = array[i];
|
||||
j = i - 1;
|
||||
|
||||
while (j >= 0 && array[j] > key)
|
||||
{
|
||||
array[j + 1] = array[j];
|
||||
j = j - 1;
|
||||
}
|
||||
array[j + 1] = key;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printArray(int *array)
|
||||
{
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
printf("%d ", array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int A[N];
|
||||
|
||||
initArray(A, 10);
|
||||
sortArrayInsertion(A);
|
||||
printArray(A);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+85
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
24.В функции main есть два массива: A[5] и B[10].
|
||||
Написать две функции – одна сортирует массивы по возрастанию (один массив за один вызов функции),
|
||||
а другая – выводит значения элементов массива (один массив за один вызов функции).
|
||||
Массивы в функции main находятся в одной области памяти, отсортированные – в другой.
|
||||
После вызова функции вывести результат сортировки и исходные массивы.
|
||||
Сами исходные массивы в функции main остаются без изменений.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define SIZE_A 5
|
||||
#define SIZE_B 10
|
||||
|
||||
void initArray(int *array, int size, const int MAX)
|
||||
{
|
||||
srand(time(0));
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
array[i] = rand() % MAX + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void sortArrayInsertion(int *array, int size)
|
||||
{
|
||||
int i, key, j;
|
||||
for (i = 1; i < size; i++)
|
||||
{
|
||||
key = array[i];
|
||||
j = i - 1;
|
||||
|
||||
while (j >= 0 && array[j] > key)
|
||||
{
|
||||
array[j + 1] = array[j];
|
||||
j = j - 1;
|
||||
}
|
||||
array[j + 1] = key;
|
||||
}
|
||||
}
|
||||
|
||||
void printArray(int *array, int size)
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
printf("%d ", array[i]);
|
||||
}
|
||||
puts("");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int A[SIZE_A];
|
||||
int B[SIZE_B];
|
||||
|
||||
initArray(A, SIZE_A, 10);
|
||||
initArray(B, SIZE_B, 15);
|
||||
|
||||
int A_sort[SIZE_A];
|
||||
int B_sort[SIZE_B];
|
||||
|
||||
memcpy(A_sort, A, sizeof(A));
|
||||
memcpy(B_sort, B, sizeof(B));
|
||||
|
||||
sortArrayInsertion(A_sort, SIZE_A);
|
||||
sortArrayInsertion(B_sort, SIZE_B);
|
||||
|
||||
printf("A[%d] = ", SIZE_A);
|
||||
printArray(A, SIZE_A);
|
||||
|
||||
printf("Sorted A[%d] = ", SIZE_A);
|
||||
printArray(A_sort, SIZE_A);
|
||||
|
||||
printf("B[%d] = ", SIZE_A);
|
||||
printArray(B, SIZE_B);
|
||||
|
||||
printf("Sorted B[%d] = ", SIZE_A);
|
||||
printArray(B_sort, SIZE_B);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
25. Выполнить подготовку для рисования графика функции y=sin(x), x [-2pi;2pi].
|
||||
С шагом pi/180. Значения (x,y) записать в файл «sinraw.txt», как есть
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
|
||||
|
||||
|
||||
void writeXY()
|
||||
{
|
||||
FILE *file = fopen("sinraw.txt", "w");
|
||||
if (file == NULL)
|
||||
{
|
||||
printf("Error open\n");
|
||||
return;
|
||||
}
|
||||
|
||||
double a = 0;
|
||||
double b = 2 * M_PI;
|
||||
double h = 0.1;
|
||||
|
||||
for (double x = a; x <= b; x += h)
|
||||
{
|
||||
double y = sin(x);
|
||||
fprintf(file, "%f %f\n", x, y);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
writeXY();
|
||||
return 0;
|
||||
}
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
26.Аналогично заданию 25, но в файл «singood.txt» записать экранные координаты (x,y).
|
||||
Для этого следует учесть:
|
||||
* масштабирование по оси ОХ = 50, по оси ОУ = 40
|
||||
* начало экранных координат установлено в точке (320, 240)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
void writeXY()
|
||||
{
|
||||
FILE *file = fopen("singood.txt", "w");
|
||||
if (file == NULL)
|
||||
{
|
||||
printf("Error open\n");
|
||||
return;
|
||||
}
|
||||
|
||||
double a = 0;
|
||||
double b = 2 * M_PI;
|
||||
double h = 0.1;
|
||||
|
||||
double scale_x = 50;
|
||||
double scale_y = 40;
|
||||
double offset_x = 320;
|
||||
double offset_y = 240;
|
||||
|
||||
for (double x = a; x <= b; x += h)
|
||||
{
|
||||
double y = sin(x);
|
||||
fprintf(file, "%f %f\n", x, y);
|
||||
|
||||
double x_screen = x * scale_x + offset_x;
|
||||
double y_screen = -y * scale_y + offset_y;
|
||||
fprintf(file, "%f %f\n", x_screen, y_screen);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
writeXY();
|
||||
return 0;
|
||||
}
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
29.Загадать случайным образом 100 чисел в диапазоне [-50;75].
|
||||
Записать их в файл «binint.dat» - каждое число записывается в файл в 4-х байтном представлении.
|
||||
Прочитать данные из файла «binint.dat», найти сумму чисел в нём.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
|
||||
const int MIN = -50;
|
||||
const int MAX = 75;
|
||||
const int AMOUNT = 100;
|
||||
|
||||
int* getRandomArray() {
|
||||
srand(time(0));
|
||||
|
||||
int *array = malloc(sizeof(int)*AMOUNT);
|
||||
for (int i = 0; i < AMOUNT;i++) {
|
||||
array[i] = rand() % (abs(MIN) + abs(MAX) + 1) - abs(MIN);
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
void writeData(char* filename) {
|
||||
FILE *file = fopen(filename, "wb");
|
||||
|
||||
int *array = getRandomArray();
|
||||
for (int i = 0; i < AMOUNT; i++) {
|
||||
fwrite(&array[i], sizeof(int), 1, file);
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
int getSummaryNumbers(char* filename) {
|
||||
FILE *file = fopen(filename, "rb");
|
||||
int number, summary = 0;
|
||||
|
||||
while(fread(&number, sizeof(int), 1, file) == 1) {
|
||||
summary += number;
|
||||
}
|
||||
fclose(file);
|
||||
return summary;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char *filename = "binint.dat";
|
||||
writeData(filename);
|
||||
printf("Summary: %d", getSummaryNumbers(filename));
|
||||
return 0;
|
||||
}
|
||||
Executable
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
3.Даны целочисленные переменные А, В и С. Задать их вводом с клавиатуры. Вывести в порядке возрастания. (только оператор условия)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int* getNumbers(int a, int b, int c) {
|
||||
|
||||
if (a > b) {
|
||||
int tmp = a;
|
||||
a = b;
|
||||
b = tmp;
|
||||
}
|
||||
if (b > c) {
|
||||
int tmp = b;
|
||||
b = c;
|
||||
c = tmp;
|
||||
}
|
||||
if (a > b) {
|
||||
int tmp = a;
|
||||
a = b;
|
||||
b = tmp;
|
||||
}
|
||||
|
||||
int *answer = malloc(sizeof(int) * 3);
|
||||
answer[0] = a;
|
||||
answer[1] = b;
|
||||
answer[2] = c;
|
||||
return answer;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int a, b, c;
|
||||
printf("Enter 3 numbers: ");
|
||||
|
||||
scanf("%d %d %d", &a, &b, &c);
|
||||
|
||||
int *result = getNumbers(a, b ,c);
|
||||
printf("Sorted: %d %d %d", result[0], result[1], result[2]);
|
||||
free(result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
30.Загадать случайным образом 50 действительных чисел в диапазоне [-5.5;5.5].
|
||||
Записать их в файл «binfloat.dat» - каждое число записывается в 4-х байтном представлении.
|
||||
Прочитать данные из файла «binfloat.dat», найти максимальное значение.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
|
||||
const int MIN = -55;
|
||||
const int MAX = 55;
|
||||
const int AMOUNT = 50;
|
||||
|
||||
float* getRandomFloatArray() {
|
||||
srand(time(0));
|
||||
|
||||
float *array = malloc(sizeof(float)*AMOUNT);
|
||||
for (int i = 0; i < AMOUNT;i++) {
|
||||
array[i] = (rand() % (abs(MIN) + abs(MAX) + 1) - abs(MIN))/10.0f;
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
void writeData(char* filename) {
|
||||
FILE *file = fopen(filename, "wb");
|
||||
|
||||
float *array = getRandomFloatArray();
|
||||
for (int i = 0; i < AMOUNT; i++) {
|
||||
fwrite(&array[i], sizeof(float), 1, file);
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
float getMaximumNumber(char* filename) {
|
||||
FILE *file = fopen(filename, "rb");
|
||||
float number, maximum = 0;
|
||||
|
||||
while(fread(&number, sizeof(float), 1, file) == 1) {
|
||||
maximum = maximum < number ? number : maximum;
|
||||
}
|
||||
fclose(file);
|
||||
return maximum;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char *filename = "binfloat.dat";
|
||||
writeData(filename);
|
||||
printf("Maximum: %.1f", getMaximumNumber(filename));
|
||||
return 0;
|
||||
}
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
4.Даны целочисленные переменные А и В. Задать их значения с клавиатуры. Поменять значения в переменных А и В без дополнительных переменных.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void swap(int *a, int *b) {
|
||||
*a += *b;
|
||||
*b = *a - *b;
|
||||
*a -= *b;
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
int a, b;
|
||||
|
||||
printf("Enter 2 digits: ");
|
||||
scanf("%d %d", &a, &b);
|
||||
|
||||
swap(&a, &b);
|
||||
|
||||
printf("%d %d", a ,b);
|
||||
return 0;
|
||||
}
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
5.Дана переменная А. Задать ее значение с клавиатуры (от 1 до 7). Используя оператор SWITCH…CASE вывести на экран соответствующий день недели.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
char* getDay(int number) {
|
||||
switch (number) {
|
||||
case 1:
|
||||
return "Monday";
|
||||
case 2:
|
||||
return "Tuesday";
|
||||
case 3:
|
||||
return "Wednesday";
|
||||
case 4:
|
||||
return "Thursday";
|
||||
case 5:
|
||||
return "Friday";
|
||||
case 6:
|
||||
return "Saturday";
|
||||
case 7:
|
||||
return "Sunday";
|
||||
default:
|
||||
return "number not between 1..7";
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int number;
|
||||
printf("Enter number day: ");
|
||||
scanf("%d", &number);
|
||||
|
||||
printf("Answer: %s", getDay(number));
|
||||
return 0;
|
||||
}
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
6.Создать структуру, содержащую два поля – NAME и AGE. Задать две переменные типа этой структуры. Ввести их значения с клавиатуры и вывести на экран.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
struct person {
|
||||
char NAME[32];
|
||||
int AGE;
|
||||
};
|
||||
|
||||
int main() {
|
||||
struct person p1, p2;
|
||||
|
||||
printf("Enter name and age first person: ");
|
||||
scanf("%s %d", p1.NAME, &p1.AGE);
|
||||
printf("Enter name and age second person: ");
|
||||
scanf("%s %d", p2.NAME, &p2.AGE);
|
||||
|
||||
printf("First person: %s, %2d age\n", p1.NAME, p1.AGE);
|
||||
printf("Second person: %s, %2d age\n", p2.NAME, p2.AGE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
7.Создать целочисленный массив A[5][5]. При помощи цикла и оператора условия задать его значения, как показано ниже:
|
||||
1 1 1 1 1
|
||||
2 2 2 2 2
|
||||
3 3 3 3 3
|
||||
4 4 4 4 4
|
||||
5 5 5 5 5
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define N 5
|
||||
|
||||
|
||||
void setArray(int (*array)[N]) {
|
||||
for (int i = 0; i < N; i++) {
|
||||
for (int j = 0; j < N; j++) {
|
||||
array[i][j] = i+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void printArray(int (*array)[N] ) {
|
||||
for (int i = 0; i < N; i++) {
|
||||
for (int j = 0; j < N; j++) {
|
||||
printf("%2d", array[i][j]);
|
||||
}
|
||||
puts("");
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int A[N][N];
|
||||
|
||||
setArray(A);
|
||||
printArray(A);
|
||||
return 0;
|
||||
}
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
8.Создать целочисленный массив A[5][5]. При помощи цикла и оператора условия задать его значения, как показано ниже:
|
||||
5 5 5 5 5
|
||||
4 4 4 4 4
|
||||
3 3 3 3 3
|
||||
2 2 2 2 2
|
||||
1 1 1 1 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define N 5
|
||||
|
||||
|
||||
void setArray(int (*array)[N]) {
|
||||
for (int i = 0; i < N; i++) {
|
||||
for (int j = 0; j < N; j++) {
|
||||
array[i][j] = N - i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void printArray(int (*array)[N] ) {
|
||||
for (int i = 0; i < N; i++) {
|
||||
for (int j = 0; j < N; j++) {
|
||||
printf("%2d", array[i][j]);
|
||||
}
|
||||
puts("");
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int A[N][N];
|
||||
|
||||
setArray(A);
|
||||
printArray(A);
|
||||
return 0;
|
||||
}
|
||||
Executable
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
9.Создать целочисленный массив A[5][5]. При помощи цикла и оператора условия задать его значения, как показано ниже:
|
||||
5 4 3 2 1
|
||||
4 3 2 1 2
|
||||
3 2 1 2 3
|
||||
2 1 2 3 4
|
||||
1 2 3 4 5
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define N 5
|
||||
|
||||
|
||||
void setArray(int (*array)[N]) {
|
||||
for (int i = 0; i < N; i++) {
|
||||
for (int j = 0; j < N; j++) {
|
||||
int result;
|
||||
if ( i+j < N) {
|
||||
result = N - (i+j);
|
||||
} else {
|
||||
result = (i+j) - (N - 2);
|
||||
}
|
||||
array[i][j] = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void printArray(int (*array)[N] ) {
|
||||
for (int i = 0; i < N; i++) {
|
||||
for (int j = 0; j < N; j++) {
|
||||
printf("%d ", array[i][j]);
|
||||
}
|
||||
puts("");
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int A[N][N];
|
||||
|
||||
setArray(A);
|
||||
printArray(A);
|
||||
return 0;
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
+362
@@ -0,0 +1,362 @@
|
||||
// The winbgim library, Version 6.0, August 9, 2004
|
||||
// Written by:
|
||||
// Grant Macklem (Grant.Macklem@colorado.edu)
|
||||
// Gregory Schmelter (Gregory.Schmelter@colorado.edu)
|
||||
// Alan Schmidt (Alan.Schmidt@colorado.edu)
|
||||
// Ivan Stashak (Ivan.Stashak@colorado.edu)
|
||||
// Michael Main (Michael.Main@colorado.edu)
|
||||
// CSCI 4830/7818: API Programming
|
||||
// University of Colorado at Boulder, Spring 2003
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Notes
|
||||
// ---------------------------------------------------------------------------
|
||||
// * This library is still under development.
|
||||
// * Please see http://www.cs.colorado.edu/~main/bgi for information on
|
||||
// * using this library with the mingw32 g++ compiler.
|
||||
// * This library only works with Windows API level 4.0 and higher (Windows 95, NT 4.0 and newer)
|
||||
// * This library may not be compatible with 64-bit versions of Windows
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Macro Guard and Include Directives
|
||||
// ---------------------------------------------------------------------------
|
||||
#ifndef WINBGI_H
|
||||
#define WINBGI_H
|
||||
#include <windows.h> // Provides the mouse message types
|
||||
#include <limits.h> // Provides INT_MAX
|
||||
#include <sstream> // Provides std::ostringstream
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Definitions
|
||||
// ---------------------------------------------------------------------------
|
||||
// Definitions for the key pad extended keys are added here. When one
|
||||
// of these keys are pressed, getch will return a zero followed by one
|
||||
// of these values. This is the same way that it works in conio for
|
||||
// dos applications.
|
||||
#define KEY_HOME 71
|
||||
#define KEY_UP 72
|
||||
#define KEY_PGUP 73
|
||||
#define KEY_LEFT 75
|
||||
#define KEY_CENTER 76
|
||||
#define KEY_RIGHT 77
|
||||
#define KEY_END 79
|
||||
#define KEY_DOWN 80
|
||||
#define KEY_PGDN 81
|
||||
#define KEY_INSERT 82
|
||||
#define KEY_DELETE 83
|
||||
#define KEY_F1 59
|
||||
#define KEY_F2 60
|
||||
#define KEY_F3 61
|
||||
#define KEY_F4 62
|
||||
#define KEY_F5 63
|
||||
#define KEY_F6 64
|
||||
#define KEY_F7 65
|
||||
#define KEY_F8 66
|
||||
#define KEY_F9 67
|
||||
|
||||
// Line thickness settings
|
||||
#define NORM_WIDTH 1
|
||||
#define THICK_WIDTH 3
|
||||
|
||||
// Character Size and Direction
|
||||
#define USER_CHAR_SIZE 0
|
||||
#define HORIZ_DIR 0
|
||||
#define VERT_DIR 1
|
||||
|
||||
|
||||
// Constants for closegraph
|
||||
#define CURRENT_WINDOW -1
|
||||
#define ALL_WINDOWS -2
|
||||
#define NO_CURRENT_WINDOW -3
|
||||
|
||||
// The standard Borland 16 colors
|
||||
#define MAXCOLORS 15
|
||||
enum colors { BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY, DARKGRAY,
|
||||
LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE };
|
||||
|
||||
// The standard line styles
|
||||
enum line_styles { SOLID_LINE, DOTTED_LINE, CENTER_LINE, DASHED_LINE, USERBIT_LINE };
|
||||
|
||||
// The standard fill styles
|
||||
enum fill_styles { EMPTY_FILL, SOLID_FILL, LINE_FILL, LTSLASH_FILL, SLASH_FILL,
|
||||
BKSLASH_FILL, LTBKSLASH_FILL, HATCH_FILL, XHATCH_FILL, INTERLEAVE_FILL,
|
||||
WIDE_DOT_FILL, CLOSE_DOT_FILL, USER_FILL };
|
||||
|
||||
// The various graphics drivers
|
||||
enum graphics_drivers { DETECT, CGA, MCGA, EGA, EGA64, EGAMONO, IBM8514, HERCMONO,
|
||||
ATT400, VGA, PC3270 };
|
||||
|
||||
// Various modes for each graphics driver
|
||||
enum graphics_modes { CGAC0, CGAC1, CGAC2, CGAC3, CGAHI,
|
||||
MCGAC0 = 0, MCGAC1, MCGAC2, MCGAC3, MCGAMED, MCGAHI,
|
||||
EGALO = 0, EGAHI,
|
||||
EGA64LO = 0, EGA64HI,
|
||||
EGAMONOHI = 3,
|
||||
HERCMONOHI = 0,
|
||||
ATT400C0 = 0, ATT400C1, ATT400C2, ATT400C3, ATT400MED, ATT400HI,
|
||||
VGALO = 0, VGAMED, VGAHI,
|
||||
PC3270HI = 0,
|
||||
IBM8514LO = 0, IBM8514HI };
|
||||
|
||||
// Borland error messages for the graphics window.
|
||||
#define NO_CLICK -1 // No mouse event of the current type in getmouseclick
|
||||
enum graph_errors { grInvalidVersion = -18, grInvalidDeviceNum = -15, grInvalidFontNum,
|
||||
grInvalidFont, grIOerror, grError, grInvalidMode, grNoFontMem,
|
||||
grFontNotFound, grNoFloodMem, grNoScanMem, grNoLoadMem,
|
||||
grInvalidDriver, grFileNotFound, grNotDetected, grNoInitGraph,
|
||||
grOk };
|
||||
|
||||
// Write modes
|
||||
enum putimage_ops{ COPY_PUT, XOR_PUT, OR_PUT, AND_PUT, NOT_PUT };
|
||||
|
||||
// Text Modes
|
||||
enum horiz { LEFT_TEXT, CENTER_TEXT, RIGHT_TEXT };
|
||||
enum vertical { BOTTOM_TEXT, VCENTER_TEXT, TOP_TEXT }; // middle not needed other than as seperator
|
||||
enum font_names { DEFAULT_FONT, TRIPLEX_FONT, SMALL_FONT, SANS_SERIF_FONT,
|
||||
GOTHIC_FONT, SCRIPT_FONT, SIMPLEX_FONT, TRIPLEX_SCR_FONT,
|
||||
COMPLEX_FONT, EUROPEAN_FONT, BOLD_FONT };
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Structures
|
||||
// ---------------------------------------------------------------------------
|
||||
// This structure records information about the last call to arc. It is used
|
||||
// by getarccoords to get the location of the endpoints of the arc.
|
||||
struct arccoordstype
|
||||
{
|
||||
int x, y; // Center point of the arc
|
||||
int xstart, ystart; // The starting position of the arc
|
||||
int xend, yend; // The ending position of the arc.
|
||||
};
|
||||
|
||||
|
||||
// This structure defines the fill style for the current window. Pattern is
|
||||
// one of the system patterns such as SOLID_FILL. Color is the color to
|
||||
// fill with
|
||||
struct fillsettingstype
|
||||
{
|
||||
int pattern; // Current fill pattern
|
||||
int color; // Current fill color
|
||||
};
|
||||
|
||||
|
||||
// This structure records information about the current line style.
|
||||
// linestyle is one of the line styles such as SOLID_LINE, upattern is a
|
||||
// 16-bit pattern for user defined lines, and thickness is the width of the
|
||||
// line in pixels.
|
||||
struct linesettingstype
|
||||
{
|
||||
int linestyle; // Current line style
|
||||
unsigned upattern; // 16-bit user line pattern
|
||||
int thickness; // Width of the line in pixels
|
||||
};
|
||||
|
||||
|
||||
// This structure records information about the text settings.
|
||||
struct textsettingstype
|
||||
{
|
||||
int font; // The font in use
|
||||
int direction; // Text direction
|
||||
int charsize; // Character size
|
||||
int horiz; // Horizontal text justification
|
||||
int vert; // Vertical text justification
|
||||
};
|
||||
|
||||
|
||||
// This structure records information about the viewport
|
||||
struct viewporttype
|
||||
{
|
||||
int left, top, // Viewport bounding box
|
||||
right, bottom;
|
||||
int clip; // Whether to clip image to viewport
|
||||
};
|
||||
|
||||
|
||||
// This structure records information about the palette.
|
||||
struct palettetype
|
||||
{
|
||||
unsigned char size;
|
||||
signed char colors[MAXCOLORS + 1];
|
||||
};
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// API Entries
|
||||
// ---------------------------------------------------------------------------
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Drawing Functions
|
||||
void arc( int x, int y, int stangle, int endangle, int radius );
|
||||
void bar( int left, int top, int right, int bottom );
|
||||
void bar3d( int left, int top, int right, int bottom, int depth, int topflag );
|
||||
void circle( int x, int y, int radius );
|
||||
void cleardevice( );
|
||||
void clearviewport( );
|
||||
void drawpoly(int n_points, int* points);
|
||||
void ellipse( int x, int y, int stangle, int endangle, int xradius, int yradius );
|
||||
void fillellipse( int x, int y, int xradius, int yradius );
|
||||
void fillpoly(int n_points, int* points);
|
||||
void floodfill( int x, int y, int border );
|
||||
void line( int x1, int y1, int x2, int y2 );
|
||||
void linerel( int dx, int dy );
|
||||
void lineto( int x, int y );
|
||||
void pieslice( int x, int y, int stangle, int endangle, int radius );
|
||||
void putpixel( int x, int y, int color );
|
||||
void rectangle( int left, int top, int right, int bottom );
|
||||
void sector( int x, int y, int stangle, int endangle, int xradius, int yradius );
|
||||
|
||||
// Miscellaneous Functions
|
||||
int getdisplaycolor( int color );
|
||||
int converttorgb( int color );
|
||||
void delay( int msec );
|
||||
void getarccoords( arccoordstype *arccoords );
|
||||
int getbkcolor( );
|
||||
int getcolor( );
|
||||
void getfillpattern( char *pattern );
|
||||
void getfillsettings( fillsettingstype *fillinfo );
|
||||
void getlinesettings( linesettingstype *lineinfo );
|
||||
int getmaxcolor( );
|
||||
int getmaxheight( );
|
||||
int getmaxwidth( );
|
||||
int getmaxx( );
|
||||
int getmaxy( );
|
||||
bool getrefreshingbgi( );
|
||||
int getwindowheight( );
|
||||
int getwindowwidth( );
|
||||
int getpixel( int x, int y );
|
||||
void getviewsettings( viewporttype *viewport );
|
||||
int getx( );
|
||||
int gety( );
|
||||
void moverel( int dx, int dy );
|
||||
void moveto( int x, int y );
|
||||
void refreshbgi(int left, int top, int right, int bottom);
|
||||
void refreshallbgi( );
|
||||
void setbkcolor( int color );
|
||||
void setcolor( int color );
|
||||
void setfillpattern( char *upattern, int color );
|
||||
void setfillstyle( int pattern, int color );
|
||||
void setlinestyle( int linestyle, unsigned upattern, int thickness );
|
||||
void setrefreshingbgi(bool value);
|
||||
void setviewport( int left, int top, int right, int bottom, int clip );
|
||||
void setwritemode( int mode );
|
||||
|
||||
// Window Creation / Graphics Manipulation
|
||||
void closegraph( int wid=ALL_WINDOWS );
|
||||
void detectgraph( int *graphdriver, int *graphmode );
|
||||
void getaspectratio( int *xasp, int *yasp );
|
||||
char *getdrivername( );
|
||||
int getgraphmode( );
|
||||
int getmaxmode( );
|
||||
char *getmodename( int mode_number );
|
||||
void getmoderange( int graphdriver, int *lomode, int *himode );
|
||||
void graphdefaults( );
|
||||
char *grapherrormsg( int errorcode );
|
||||
int graphresult( );
|
||||
void initgraph( int *graphdriver, int *graphmode, char *pathtodriver );
|
||||
int initwindow
|
||||
( int width, int height, const char* title="Windows BGI", int left=0, int top=0, bool dbflag=false, bool closeflag=true );
|
||||
int installuserdriver( char *name, int *fp ); // Not available in WinBGI
|
||||
int installuserfont( char *name ); // Not available in WinBGI
|
||||
int registerbgidriver( void *driver ); // Not available in WinBGI
|
||||
int registerbgifont( void *font ); // Not available in WinBGI
|
||||
void restorecrtmode( );
|
||||
void setaspectratio( int xasp, int yasp );
|
||||
unsigned setgraphbufsize( unsigned bufsize ); // Not available in WinBGI
|
||||
void setgraphmode( int mode );
|
||||
void showerrorbox( const char *msg = NULL );
|
||||
|
||||
// User Interaction
|
||||
int getch( );
|
||||
int kbhit( );
|
||||
|
||||
// User-Controlled Window Functions (winbgi.cpp)
|
||||
int getcurrentwindow( );
|
||||
void setcurrentwindow( int window );
|
||||
|
||||
// Double buffering support (winbgi.cpp)
|
||||
int getactivepage( );
|
||||
int getvisualpage( );
|
||||
void setactivepage( int page );
|
||||
void setvisualpage( int page );
|
||||
void swapbuffers( );
|
||||
|
||||
// Image Functions (drawing.cpp)
|
||||
unsigned imagesize( int left, int top, int right, int bottom );
|
||||
void getimage( int left, int top, int right, int bottom, void *bitmap );
|
||||
void putimage( int left, int top, void *bitmap, int op );
|
||||
void printimage(
|
||||
const char* title=NULL,
|
||||
double width_inches=7, double border_left_inches=0.75, double border_top_inches=0.75,
|
||||
int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX,
|
||||
bool active=true, HWND hwnd=NULL
|
||||
);
|
||||
void readimagefile(
|
||||
const char* filename=NULL,
|
||||
int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX
|
||||
);
|
||||
void writeimagefile(
|
||||
const char* filename=NULL,
|
||||
int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX,
|
||||
bool active=true, HWND hwnd=NULL
|
||||
);
|
||||
|
||||
// Text Functions (text.cpp)
|
||||
void gettextsettings(struct textsettingstype *texttypeinfo);
|
||||
void outtext(char *textstring);
|
||||
void outtextxy(int x, int y, char *textstring);
|
||||
void settextjustify(int horiz, int vert);
|
||||
void settextstyle(int font, int direction, int charsize);
|
||||
void setusercharsize(int multx, int divx, int multy, int divy);
|
||||
int textheight(char *textstring);
|
||||
int textwidth(char *textstring);
|
||||
extern std::ostringstream bgiout;
|
||||
void outstream(std::ostringstream& out=bgiout);
|
||||
void outstreamxy(int x, int y, std::ostringstream& out=bgiout);
|
||||
|
||||
// Mouse Functions (mouse.cpp)
|
||||
void clearmouseclick( int kind );
|
||||
void clearresizeevent( );
|
||||
void getmouseclick( int kind, int& x, int& y );
|
||||
bool ismouseclick( int kind );
|
||||
bool isresizeevent( );
|
||||
int mousex( );
|
||||
int mousey( );
|
||||
void registermousehandler( int kind, void h( int, int ) );
|
||||
void setmousequeuestatus( int kind, bool status=true );
|
||||
|
||||
// Palette Functions
|
||||
palettetype *getdefaultpalette( );
|
||||
void getpalette( palettetype *palette );
|
||||
int getpalettesize( );
|
||||
void setallpalette( palettetype *palette );
|
||||
void setpalette( int colornum, int color );
|
||||
void setrgbpalette( int colornum, int red, int green, int blue );
|
||||
|
||||
// Color Macros
|
||||
#define IS_BGI_COLOR(v) ( ((v) >= 0) && ((v) < 16) )
|
||||
#define IS_RGB_COLOR(v) ( (v) & 0x03000000 )
|
||||
#define RED_VALUE(v) int(GetRValue( converttorgb(v) ))
|
||||
#define GREEN_VALUE(v) int(GetGValue( converttorgb(v) ))
|
||||
#define BLUE_VALUE(v) int(GetBValue( converttorgb(v) ))
|
||||
#undef COLOR
|
||||
int COLOR(int r, int g, int b); // No longer a macro
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // WINBGI_H
|
||||
|
||||
Executable
+362
@@ -0,0 +1,362 @@
|
||||
// The winbgim library, Version 6.0, August 9, 2004
|
||||
// Written by:
|
||||
// Grant Macklem (Grant.Macklem@colorado.edu)
|
||||
// Gregory Schmelter (Gregory.Schmelter@colorado.edu)
|
||||
// Alan Schmidt (Alan.Schmidt@colorado.edu)
|
||||
// Ivan Stashak (Ivan.Stashak@colorado.edu)
|
||||
// Michael Main (Michael.Main@colorado.edu)
|
||||
// CSCI 4830/7818: API Programming
|
||||
// University of Colorado at Boulder, Spring 2003
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Notes
|
||||
// ---------------------------------------------------------------------------
|
||||
// * This library is still under development.
|
||||
// * Please see http://www.cs.colorado.edu/~main/bgi for information on
|
||||
// * using this library with the mingw32 g++ compiler.
|
||||
// * This library only works with Windows API level 4.0 and higher (Windows 95, NT 4.0 and newer)
|
||||
// * This library may not be compatible with 64-bit versions of Windows
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Macro Guard and Include Directives
|
||||
// ---------------------------------------------------------------------------
|
||||
#ifndef WINBGI_H
|
||||
#define WINBGI_H
|
||||
#include <windows.h> // Provides the mouse message types
|
||||
#include <limits.h> // Provides INT_MAX
|
||||
#include <sstream> // Provides std::ostringstream
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Definitions
|
||||
// ---------------------------------------------------------------------------
|
||||
// Definitions for the key pad extended keys are added here. When one
|
||||
// of these keys are pressed, getch will return a zero followed by one
|
||||
// of these values. This is the same way that it works in conio for
|
||||
// dos applications.
|
||||
#define KEY_HOME 71
|
||||
#define KEY_UP 72
|
||||
#define KEY_PGUP 73
|
||||
#define KEY_LEFT 75
|
||||
#define KEY_CENTER 76
|
||||
#define KEY_RIGHT 77
|
||||
#define KEY_END 79
|
||||
#define KEY_DOWN 80
|
||||
#define KEY_PGDN 81
|
||||
#define KEY_INSERT 82
|
||||
#define KEY_DELETE 83
|
||||
#define KEY_F1 59
|
||||
#define KEY_F2 60
|
||||
#define KEY_F3 61
|
||||
#define KEY_F4 62
|
||||
#define KEY_F5 63
|
||||
#define KEY_F6 64
|
||||
#define KEY_F7 65
|
||||
#define KEY_F8 66
|
||||
#define KEY_F9 67
|
||||
|
||||
// Line thickness settings
|
||||
#define NORM_WIDTH 1
|
||||
#define THICK_WIDTH 3
|
||||
|
||||
// Character Size and Direction
|
||||
#define USER_CHAR_SIZE 0
|
||||
#define HORIZ_DIR 0
|
||||
#define VERT_DIR 1
|
||||
|
||||
|
||||
// Constants for closegraph
|
||||
#define CURRENT_WINDOW -1
|
||||
#define ALL_WINDOWS -2
|
||||
#define NO_CURRENT_WINDOW -3
|
||||
|
||||
// The standard Borland 16 colors
|
||||
#define MAXCOLORS 15
|
||||
enum colors { BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY, DARKGRAY,
|
||||
LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE };
|
||||
|
||||
// The standard line styles
|
||||
enum line_styles { SOLID_LINE, DOTTED_LINE, CENTER_LINE, DASHED_LINE, USERBIT_LINE };
|
||||
|
||||
// The standard fill styles
|
||||
enum fill_styles { EMPTY_FILL, SOLID_FILL, LINE_FILL, LTSLASH_FILL, SLASH_FILL,
|
||||
BKSLASH_FILL, LTBKSLASH_FILL, HATCH_FILL, XHATCH_FILL, INTERLEAVE_FILL,
|
||||
WIDE_DOT_FILL, CLOSE_DOT_FILL, USER_FILL };
|
||||
|
||||
// The various graphics drivers
|
||||
enum graphics_drivers { DETECT, CGA, MCGA, EGA, EGA64, EGAMONO, IBM8514, HERCMONO,
|
||||
ATT400, VGA, PC3270 };
|
||||
|
||||
// Various modes for each graphics driver
|
||||
enum graphics_modes { CGAC0, CGAC1, CGAC2, CGAC3, CGAHI,
|
||||
MCGAC0 = 0, MCGAC1, MCGAC2, MCGAC3, MCGAMED, MCGAHI,
|
||||
EGALO = 0, EGAHI,
|
||||
EGA64LO = 0, EGA64HI,
|
||||
EGAMONOHI = 3,
|
||||
HERCMONOHI = 0,
|
||||
ATT400C0 = 0, ATT400C1, ATT400C2, ATT400C3, ATT400MED, ATT400HI,
|
||||
VGALO = 0, VGAMED, VGAHI,
|
||||
PC3270HI = 0,
|
||||
IBM8514LO = 0, IBM8514HI };
|
||||
|
||||
// Borland error messages for the graphics window.
|
||||
#define NO_CLICK -1 // No mouse event of the current type in getmouseclick
|
||||
enum graph_errors { grInvalidVersion = -18, grInvalidDeviceNum = -15, grInvalidFontNum,
|
||||
grInvalidFont, grIOerror, grError, grInvalidMode, grNoFontMem,
|
||||
grFontNotFound, grNoFloodMem, grNoScanMem, grNoLoadMem,
|
||||
grInvalidDriver, grFileNotFound, grNotDetected, grNoInitGraph,
|
||||
grOk };
|
||||
|
||||
// Write modes
|
||||
enum putimage_ops{ COPY_PUT, XOR_PUT, OR_PUT, AND_PUT, NOT_PUT };
|
||||
|
||||
// Text Modes
|
||||
enum horiz { LEFT_TEXT, CENTER_TEXT, RIGHT_TEXT };
|
||||
enum vertical { BOTTOM_TEXT, VCENTER_TEXT, TOP_TEXT }; // middle not needed other than as seperator
|
||||
enum font_names { DEFAULT_FONT, TRIPLEX_FONT, SMALL_FONT, SANS_SERIF_FONT,
|
||||
GOTHIC_FONT, SCRIPT_FONT, SIMPLEX_FONT, TRIPLEX_SCR_FONT,
|
||||
COMPLEX_FONT, EUROPEAN_FONT, BOLD_FONT };
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Structures
|
||||
// ---------------------------------------------------------------------------
|
||||
// This structure records information about the last call to arc. It is used
|
||||
// by getarccoords to get the location of the endpoints of the arc.
|
||||
struct arccoordstype
|
||||
{
|
||||
int x, y; // Center point of the arc
|
||||
int xstart, ystart; // The starting position of the arc
|
||||
int xend, yend; // The ending position of the arc.
|
||||
};
|
||||
|
||||
|
||||
// This structure defines the fill style for the current window. Pattern is
|
||||
// one of the system patterns such as SOLID_FILL. Color is the color to
|
||||
// fill with
|
||||
struct fillsettingstype
|
||||
{
|
||||
int pattern; // Current fill pattern
|
||||
int color; // Current fill color
|
||||
};
|
||||
|
||||
|
||||
// This structure records information about the current line style.
|
||||
// linestyle is one of the line styles such as SOLID_LINE, upattern is a
|
||||
// 16-bit pattern for user defined lines, and thickness is the width of the
|
||||
// line in pixels.
|
||||
struct linesettingstype
|
||||
{
|
||||
int linestyle; // Current line style
|
||||
unsigned upattern; // 16-bit user line pattern
|
||||
int thickness; // Width of the line in pixels
|
||||
};
|
||||
|
||||
|
||||
// This structure records information about the text settings.
|
||||
struct textsettingstype
|
||||
{
|
||||
int font; // The font in use
|
||||
int direction; // Text direction
|
||||
int charsize; // Character size
|
||||
int horiz; // Horizontal text justification
|
||||
int vert; // Vertical text justification
|
||||
};
|
||||
|
||||
|
||||
// This structure records information about the viewport
|
||||
struct viewporttype
|
||||
{
|
||||
int left, top, // Viewport bounding box
|
||||
right, bottom;
|
||||
int clip; // Whether to clip image to viewport
|
||||
};
|
||||
|
||||
|
||||
// This structure records information about the palette.
|
||||
struct palettetype
|
||||
{
|
||||
unsigned char size;
|
||||
signed char colors[MAXCOLORS + 1];
|
||||
};
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// API Entries
|
||||
// ---------------------------------------------------------------------------
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Drawing Functions
|
||||
void arc( int x, int y, int stangle, int endangle, int radius );
|
||||
void bar( int left, int top, int right, int bottom );
|
||||
void bar3d( int left, int top, int right, int bottom, int depth, int topflag );
|
||||
void circle( int x, int y, int radius );
|
||||
void cleardevice( );
|
||||
void clearviewport( );
|
||||
void drawpoly(int n_points, int* points);
|
||||
void ellipse( int x, int y, int stangle, int endangle, int xradius, int yradius );
|
||||
void fillellipse( int x, int y, int xradius, int yradius );
|
||||
void fillpoly(int n_points, int* points);
|
||||
void floodfill( int x, int y, int border );
|
||||
void line( int x1, int y1, int x2, int y2 );
|
||||
void linerel( int dx, int dy );
|
||||
void lineto( int x, int y );
|
||||
void pieslice( int x, int y, int stangle, int endangle, int radius );
|
||||
void putpixel( int x, int y, int color );
|
||||
void rectangle( int left, int top, int right, int bottom );
|
||||
void sector( int x, int y, int stangle, int endangle, int xradius, int yradius );
|
||||
|
||||
// Miscellaneous Functions
|
||||
int getdisplaycolor( int color );
|
||||
int converttorgb( int color );
|
||||
void delay( int msec );
|
||||
void getarccoords( arccoordstype *arccoords );
|
||||
int getbkcolor( );
|
||||
int getcolor( );
|
||||
void getfillpattern( char *pattern );
|
||||
void getfillsettings( fillsettingstype *fillinfo );
|
||||
void getlinesettings( linesettingstype *lineinfo );
|
||||
int getmaxcolor( );
|
||||
int getmaxheight( );
|
||||
int getmaxwidth( );
|
||||
int getmaxx( );
|
||||
int getmaxy( );
|
||||
bool getrefreshingbgi( );
|
||||
int getwindowheight( );
|
||||
int getwindowwidth( );
|
||||
int getpixel( int x, int y );
|
||||
void getviewsettings( viewporttype *viewport );
|
||||
int getx( );
|
||||
int gety( );
|
||||
void moverel( int dx, int dy );
|
||||
void moveto( int x, int y );
|
||||
void refreshbgi(int left, int top, int right, int bottom);
|
||||
void refreshallbgi( );
|
||||
void setbkcolor( int color );
|
||||
void setcolor( int color );
|
||||
void setfillpattern( char *upattern, int color );
|
||||
void setfillstyle( int pattern, int color );
|
||||
void setlinestyle( int linestyle, unsigned upattern, int thickness );
|
||||
void setrefreshingbgi(bool value);
|
||||
void setviewport( int left, int top, int right, int bottom, int clip );
|
||||
void setwritemode( int mode );
|
||||
|
||||
// Window Creation / Graphics Manipulation
|
||||
void closegraph( int wid=ALL_WINDOWS );
|
||||
void detectgraph( int *graphdriver, int *graphmode );
|
||||
void getaspectratio( int *xasp, int *yasp );
|
||||
char *getdrivername( );
|
||||
int getgraphmode( );
|
||||
int getmaxmode( );
|
||||
char *getmodename( int mode_number );
|
||||
void getmoderange( int graphdriver, int *lomode, int *himode );
|
||||
void graphdefaults( );
|
||||
char *grapherrormsg( int errorcode );
|
||||
int graphresult( );
|
||||
void initgraph( int *graphdriver, int *graphmode, char *pathtodriver );
|
||||
int initwindow
|
||||
( int width, int height, const char* title="Windows BGI", int left=0, int top=0, bool dbflag=false, bool closeflag=true );
|
||||
int installuserdriver( char *name, int *fp ); // Not available in WinBGI
|
||||
int installuserfont( char *name ); // Not available in WinBGI
|
||||
int registerbgidriver( void *driver ); // Not available in WinBGI
|
||||
int registerbgifont( void *font ); // Not available in WinBGI
|
||||
void restorecrtmode( );
|
||||
void setaspectratio( int xasp, int yasp );
|
||||
unsigned setgraphbufsize( unsigned bufsize ); // Not available in WinBGI
|
||||
void setgraphmode( int mode );
|
||||
void showerrorbox( const char *msg = NULL );
|
||||
|
||||
// User Interaction
|
||||
int getch( );
|
||||
int kbhit( );
|
||||
|
||||
// User-Controlled Window Functions (winbgi.cpp)
|
||||
int getcurrentwindow( );
|
||||
void setcurrentwindow( int window );
|
||||
|
||||
// Double buffering support (winbgi.cpp)
|
||||
int getactivepage( );
|
||||
int getvisualpage( );
|
||||
void setactivepage( int page );
|
||||
void setvisualpage( int page );
|
||||
void swapbuffers( );
|
||||
|
||||
// Image Functions (drawing.cpp)
|
||||
unsigned imagesize( int left, int top, int right, int bottom );
|
||||
void getimage( int left, int top, int right, int bottom, void *bitmap );
|
||||
void putimage( int left, int top, void *bitmap, int op );
|
||||
void printimage(
|
||||
const char* title=NULL,
|
||||
double width_inches=7, double border_left_inches=0.75, double border_top_inches=0.75,
|
||||
int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX,
|
||||
bool active=true, HWND hwnd=NULL
|
||||
);
|
||||
void readimagefile(
|
||||
const char* filename=NULL,
|
||||
int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX
|
||||
);
|
||||
void writeimagefile(
|
||||
const char* filename=NULL,
|
||||
int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX,
|
||||
bool active=true, HWND hwnd=NULL
|
||||
);
|
||||
|
||||
// Text Functions (text.cpp)
|
||||
void gettextsettings(struct textsettingstype *texttypeinfo);
|
||||
void outtext(char *textstring);
|
||||
void outtextxy(int x, int y, char *textstring);
|
||||
void settextjustify(int horiz, int vert);
|
||||
void settextstyle(int font, int direction, int charsize);
|
||||
void setusercharsize(int multx, int divx, int multy, int divy);
|
||||
int textheight(char *textstring);
|
||||
int textwidth(char *textstring);
|
||||
extern std::ostringstream bgiout;
|
||||
void outstream(std::ostringstream& out=bgiout);
|
||||
void outstreamxy(int x, int y, std::ostringstream& out=bgiout);
|
||||
|
||||
// Mouse Functions (mouse.cpp)
|
||||
void clearmouseclick( int kind );
|
||||
void clearresizeevent( );
|
||||
void getmouseclick( int kind, int& x, int& y );
|
||||
bool ismouseclick( int kind );
|
||||
bool isresizeevent( );
|
||||
int mousex( );
|
||||
int mousey( );
|
||||
void registermousehandler( int kind, void h( int, int ) );
|
||||
void setmousequeuestatus( int kind, bool status=true );
|
||||
|
||||
// Palette Functions
|
||||
palettetype *getdefaultpalette( );
|
||||
void getpalette( palettetype *palette );
|
||||
int getpalettesize( );
|
||||
void setallpalette( palettetype *palette );
|
||||
void setpalette( int colornum, int color );
|
||||
void setrgbpalette( int colornum, int red, int green, int blue );
|
||||
|
||||
// Color Macros
|
||||
#define IS_BGI_COLOR(v) ( ((v) >= 0) && ((v) < 16) )
|
||||
#define IS_RGB_COLOR(v) ( (v) & 0x03000000 )
|
||||
#define RED_VALUE(v) int(GetRValue( converttorgb(v) ))
|
||||
#define GREEN_VALUE(v) int(GetGValue( converttorgb(v) ))
|
||||
#define BLUE_VALUE(v) int(GetBValue( converttorgb(v) ))
|
||||
#undef COLOR
|
||||
int COLOR(int r, int g, int b); // No longer a macro
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // WINBGI_H
|
||||
|
||||
Executable
+126
@@ -0,0 +1,126 @@
|
||||
0.000000 0.000000
|
||||
320.000000 240.000000
|
||||
0.100000 0.099833
|
||||
325.000000 236.006663
|
||||
0.200000 0.198669
|
||||
330.000000 232.053227
|
||||
0.300000 0.295520
|
||||
335.000000 228.179192
|
||||
0.400000 0.389418
|
||||
340.000000 224.423266
|
||||
0.500000 0.479426
|
||||
345.000000 220.822978
|
||||
0.600000 0.564642
|
||||
350.000000 217.414301
|
||||
0.700000 0.644218
|
||||
355.000000 214.231293
|
||||
0.800000 0.717356
|
||||
360.000000 211.305756
|
||||
0.900000 0.783327
|
||||
365.000000 208.666924
|
||||
1.000000 0.841471
|
||||
370.000000 206.341161
|
||||
1.100000 0.891207
|
||||
375.000000 204.351706
|
||||
1.200000 0.932039
|
||||
380.000000 202.718437
|
||||
1.300000 0.963558
|
||||
385.000000 201.457673
|
||||
1.400000 0.985450
|
||||
390.000000 200.582011
|
||||
1.500000 0.997495
|
||||
395.000000 200.100201
|
||||
1.600000 0.999574
|
||||
400.000000 200.017056
|
||||
1.700000 0.991665
|
||||
405.000000 200.333408
|
||||
1.800000 0.973848
|
||||
410.000000 201.046095
|
||||
1.900000 0.946300
|
||||
415.000000 202.147996
|
||||
2.000000 0.909297
|
||||
420.000000 203.628103
|
||||
2.100000 0.863209
|
||||
425.000000 205.471625
|
||||
2.200000 0.808496
|
||||
430.000000 207.660144
|
||||
2.300000 0.745705
|
||||
435.000000 210.171792
|
||||
2.400000 0.675463
|
||||
440.000000 212.981473
|
||||
2.500000 0.598472
|
||||
445.000000 216.061114
|
||||
2.600000 0.515501
|
||||
450.000000 219.379945
|
||||
2.700000 0.427380
|
||||
455.000000 222.904805
|
||||
2.800000 0.334988
|
||||
460.000000 226.600474
|
||||
2.900000 0.239249
|
||||
465.000000 230.430027
|
||||
3.000000 0.141120
|
||||
470.000000 234.355200
|
||||
3.100000 0.041581
|
||||
475.000000 238.336774
|
||||
3.200000 -0.058374
|
||||
480.000000 242.334966
|
||||
3.300000 -0.157746
|
||||
485.000000 246.309828
|
||||
3.400000 -0.255541
|
||||
490.000000 250.221644
|
||||
3.500000 -0.350783
|
||||
495.000000 254.031329
|
||||
3.600000 -0.442520
|
||||
500.000000 257.700818
|
||||
3.700000 -0.529836
|
||||
505.000000 261.193446
|
||||
3.800000 -0.611858
|
||||
510.000000 264.474316
|
||||
3.900000 -0.687766
|
||||
515.000000 267.510646
|
||||
4.000000 -0.756802
|
||||
520.000000 270.272100
|
||||
4.100000 -0.818277
|
||||
525.000000 272.731084
|
||||
4.200000 -0.871576
|
||||
530.000000 274.863031
|
||||
4.300000 -0.916166
|
||||
535.000000 276.646637
|
||||
4.400000 -0.951602
|
||||
540.000000 278.064083
|
||||
4.500000 -0.977530
|
||||
545.000000 279.101205
|
||||
4.600000 -0.993691
|
||||
550.000000 279.747640
|
||||
4.700000 -0.999923
|
||||
555.000000 279.996930
|
||||
4.800000 -0.996165
|
||||
560.000000 279.846584
|
||||
4.900000 -0.982453
|
||||
565.000000 279.298105
|
||||
5.000000 -0.958924
|
||||
570.000000 278.356971
|
||||
5.100000 -0.925815
|
||||
575.000000 277.032587
|
||||
5.200000 -0.883455
|
||||
580.000000 275.338186
|
||||
5.300000 -0.832267
|
||||
585.000000 273.290698
|
||||
5.400000 -0.772764
|
||||
590.000000 270.910580
|
||||
5.500000 -0.705540
|
||||
595.000000 268.221613
|
||||
5.600000 -0.631267
|
||||
600.000000 265.250666
|
||||
5.700000 -0.550686
|
||||
605.000000 262.027422
|
||||
5.800000 -0.464602
|
||||
610.000000 258.584087
|
||||
5.900000 -0.373877
|
||||
615.000000 254.955067
|
||||
6.000000 -0.279415
|
||||
620.000000 251.176620
|
||||
6.100000 -0.182163
|
||||
625.000000 247.286500
|
||||
6.200000 -0.083089
|
||||
630.000000 243.323576
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
0.000000 0.000000
|
||||
0.100000 0.099833
|
||||
0.200000 0.198669
|
||||
0.300000 0.295520
|
||||
0.400000 0.389418
|
||||
0.500000 0.479426
|
||||
0.600000 0.564642
|
||||
0.700000 0.644218
|
||||
0.800000 0.717356
|
||||
0.900000 0.783327
|
||||
1.000000 0.841471
|
||||
1.100000 0.891207
|
||||
1.200000 0.932039
|
||||
1.300000 0.963558
|
||||
1.400000 0.985450
|
||||
1.500000 0.997495
|
||||
1.600000 0.999574
|
||||
1.700000 0.991665
|
||||
1.800000 0.973848
|
||||
1.900000 0.946300
|
||||
2.000000 0.909297
|
||||
2.100000 0.863209
|
||||
2.200000 0.808496
|
||||
2.300000 0.745705
|
||||
2.400000 0.675463
|
||||
2.500000 0.598472
|
||||
2.600000 0.515501
|
||||
2.700000 0.427380
|
||||
2.800000 0.334988
|
||||
2.900000 0.239249
|
||||
3.000000 0.141120
|
||||
3.100000 0.041581
|
||||
3.200000 -0.058374
|
||||
3.300000 -0.157746
|
||||
3.400000 -0.255541
|
||||
3.500000 -0.350783
|
||||
3.600000 -0.442520
|
||||
3.700000 -0.529836
|
||||
3.800000 -0.611858
|
||||
3.900000 -0.687766
|
||||
4.000000 -0.756802
|
||||
4.100000 -0.818277
|
||||
4.200000 -0.871576
|
||||
4.300000 -0.916166
|
||||
4.400000 -0.951602
|
||||
4.500000 -0.977530
|
||||
4.600000 -0.993691
|
||||
4.700000 -0.999923
|
||||
4.800000 -0.996165
|
||||
4.900000 -0.982453
|
||||
5.000000 -0.958924
|
||||
5.100000 -0.925815
|
||||
5.200000 -0.883455
|
||||
5.300000 -0.832267
|
||||
5.400000 -0.772764
|
||||
5.500000 -0.705540
|
||||
5.600000 -0.631267
|
||||
5.700000 -0.550686
|
||||
5.800000 -0.464602
|
||||
5.900000 -0.373877
|
||||
6.000000 -0.279415
|
||||
6.100000 -0.182163
|
||||
6.200000 -0.083089
|
||||
Reference in New Issue
Block a user