C/C++ - [решено] Построение геом. фигуры

Ответить
Аватара пользователя
kadett46

C/C++ - [решено] Построение геом. фигуры

Сообщение kadett46 »

Нужно построить данную фигуру (картинка).

Желательно несколькими способами. Заранее благодарен.
Аватара пользователя
kadett46

Re: C/C++ - [решено] Построение геом. фигуры

Сообщение kadett46 »

1 способом сделал.

Подскажите еще.





HTML код:

Код: Выделить всё

#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include "iomanip"
using namespace std;
void main()
{
	int w=40,h=21;
	cout << endl;
	for (int i=0; i<h; i++)
	{
		cout << setw(21);
		for (int j=0; j<w; j++)
			if ( i == 0 || i == h-1 || j==0 || j==w-1)
			{
				cout << "*";
			}
			else if (j==(w-i*2))
			{
				cout << "*";
			} 
			else
				cout << " ";
			cout << endl;
	}
_getch();
}
Аватара пользователя
mrcnn

Re: C/C++ - [решено] Построение геом. фигуры

Сообщение mrcnn »

Код:

Код: Выделить всё

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <locale.h>
#include <string.h>
#include <windows.h>
#pragma comment(lib,"user32.lib")
#pragma comment(lib, "kernel32.lib")
#pragma comment(lib,"gdi32.lib")
HRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
struct c_program
{
WNDCLASSEX wc;
MSG msg;
HWND hwnd;
HDC hdc;
void draw_gdi(){  hdc = GetDC(hwnd); 
MoveToEx(hdc, 40, 40, RGB(255, 0, 0)); LineTo(hdc, 140, 40);
MoveToEx(hdc, 140, 40, RGB(255, 0, 0)); LineTo(hdc, 140, 80);
MoveToEx(hdc, 40, 40, RGB(255, 0, 0)); LineTo(hdc, 40, 80);
MoveToEx(hdc, 40, 80,RGB(255, 0, 0)); LineTo(hdc, 140, 80);
MoveToEx(hdc, 40, 80, RGB(255, 0,0)); LineTo(hdc, 140, 40);
c_program(){ set_locale(LC_ALL,"Russian"); };
~c_program(){}
int main(){ HINSTANCE hInstance=GetModuleHandle(0); LPSTR CommandLine = GetCommandLine(); return WinMain(hInstance, NULL, CommandLine, SW_SHOWDEFAULT);};
void create_wndclass(HINSTANCE hInst){ wc.cbSize=sizeof(WNDCLASSEX); wc.style=CS_HREDRAW|CS_VREDRAW; wc.lpfnWndProc=(WNDPROC)WndProc; wc.cbClsExtra=NULL; wc.cbWndExtra=NULL;wc.hInstance=hInst;wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName="MainMenu"; wc.lpszClassName="SimpleWinClass"; wc.hIcon=LoadIcon(NULL, IDI_APPLICATION); wc.hIconSm=LoadIcon(NULL, IDI_APPLICATION); wc.hCursor=LoadCursor(NULL, IDC_ARROW);RegisterClassEx(&wc);}
void create_windows(HINSTANCE hInst){ hwnd=CreateWindowEx(NULL, "SimpleWinClass","host",WS_OVERLAPPEDWINDOW, 100,100,1000,1000,NULL,(HMENU) NULL,hInst, NULL); ShowWindow(hwnd, SW_SHOWNORMAL)! UpdateWindow(hwnd);}
int message_cycle(){while(GetMessage(&msg,NULL,0,0)){TranslateMessage(&msg); DispatchMessage(&msg);} return msg.wParam;}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR CmdLine, int CmdShow){create_wndclass(hInst); create_windows(hInst);  return message_cycle();}
};
c_program z;
int main(int argc, char* argv[]){ return z.main();}
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_DESTROY: PostQuitMessage(NULL); return 0;
case WM_PAINT: z.draw_gdi(); return 0;
default: return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return DefWindowProc(hwnd,uMsg, wParam,lParam);
}

на GDI
Аватара пользователя
pva

Re: C/C++ - [решено] Построение геом. фигуры

Сообщение pva »

Код:

Код: Выделить всё

#include 
int main() {
	int x1=0, x2=200, y1=0, y2=100;
	printf("\n"
		"\n"
		"\n", x2, y2, x2,y1, x1,y2, x2,y2, x2,y1, x1,y1, x1,y2);
}

использовать так:



Код:

Код: Выделить всё

gcc -o test.exe test.c
test.exe > test.html
firefox test.html
Аватара пользователя
pva

Re: C/C++ - [решено] Построение геом. фигуры

Сообщение pva »

Код:

Код: Выделить всё

#include 
#include 
#include 
int main() {
	int const x2=78, y2=30, pitch=x2+1, area_size=pitch*y2;
	int x=1, normal=(x2-y2)/2;
	char *img = malloc(area_size), *last=img+area_size-pitch, *row=last;
	memset(img, ' ', area_size);
	for(;;) {
		if (0



Код:

Код: Выделить всё

#include 
#include 
#include 
int main() {
	int const x2=78, y2=30, pitch=x2+1, area_size=pitch*y2;
	char *img = malloc(area_size);
	unsigned const dx=x2-2, dy=y2-2;
	int const width = (x2+y2)/2;
	unsigned x, y;
	for(y=0; y
Ответить

Вернуться в «Программирование и базы данных»